mapbox / mapbox-gl-native

Interactive, thoroughly customizable maps in native Android, iOS, macOS, Node.js, and Qt applications, powered by vector tiles and OpenGL
https://mapbox.com/mobile
Other
4.37k stars 1.33k forks source link

Setting padding interrupts camera animation #15252

Open cmahopper opened 5 years ago

cmahopper commented 5 years ago

Calling MapboxMap#setPadding( ... ) after calling MapboxMap#animateCamera( ... ) (or easeCamera( ... )) causes the camera animation to stop, and, if the CancelableCallback is set, onFinish() is called instead of onCancel().

Ideally I would expect that the camera animation would not be interrupted by calling setPadding(). Otherwise, I would expect that onCancel() would be called on the camera animation's CancelableCallback when the animation is interrupted.

Configuration

Android versions: Android 9.0 Mapbox SDK versions: 8.2.0

astojilj commented 5 years ago

Setting padding is another animation triggered. To combine this to the same animation (with benefit of seeing also padding animating during the animation), please try use one of getCameraForGeometry methods with padding parameter, to get CameraPosition. We don't have the padding field exposed in the API, though so I need to verify this would work.

cmahopper commented 5 years ago

@astojilj Thanks, I'll take a look at them!

cmahopper commented 5 years ago

@astojilj Unfortunately, this is not quite what I'm looking for. The function getCameraForGeometry is just another way to get a CameraPosition.

I realize I didn't describe my problem clearly enough so that's my fault.

I'm starting a camera animation that zooms out to fit a route on the screen. While the camera is moving, something happens on the screen, like a BottomSheet slides up/down or changes size, and I want to change the padding on the MapboxMap, not just the camera animation. When changing the padding, the camera animation just stops.

I'm also not told by the CancelableCallback that the animation was cancelled, but that's another problem.

LukasPaczos commented 5 years ago

Thanks for the report @cmahopper! Like @astojilj mentioned, setting the padding will start a new camera animation that adapts the camera position to the requested padding. We should still deliver onCancel() in this scenario, but otherwise, an interruption is expected here.

cmahopper commented 5 years ago

Thanks for the response @LukasPaczos.

I figured this was probably the case. Do you happen to have a suggestion for how to handle my case?

The workaround I am trying now is if padding needs to be updated while an animation is in progress, I wait until the animation is finished before setting the padding. Unfortunately, this causes the map to jump a little bit when the animation is done since I can't call MapboxMap#setPadding() with an animation.

LukasPaczos commented 5 years ago

You could try using an Animator to smoothly set padding values (which will result in a smooth animation) instead of setting it right away.

cmahopper commented 5 years ago

@LukasPaczos Right, I guess that'll have to do :)