-
Notifications
You must be signed in to change notification settings - Fork 131
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix camera animators ordering on Android 6 and lower #597
Conversation
b8aa498
to
5fc6d28
Compare
...in-animation/src/test/java/com/mapbox/maps/plugin/animation/CameraAnimationsListenersTest.kt
Outdated
Show resolved
Hide resolved
assertEquals(10.0, updateList[1].pitch!!, EPS) | ||
// Both, tick and bearing are updated to the start values at first tick. | ||
assertEquals(20.0, updateList.first().bearing!!, EPS) | ||
assertEquals(10.0, updateList.first().pitch!!, EPS) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The resulting behavior seems like more correct that the previous one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Originally, the test was added here - #352.
The problem i am trying to fix is similar, this solution covers them both.
4508752
to
2e5e990
Compare
plugin-animation/src/main/java/com/mapbox/maps/plugin/animation/CameraAnimationsPluginImpl.kt
Outdated
Show resolved
Hide resolved
plugin-animation/src/main/java/com/mapbox/maps/plugin/animation/CameraAnimationsPluginImpl.kt
Show resolved
Hide resolved
plugin-animation/src/main/java/com/mapbox/maps/plugin/animation/CameraAnimationsPluginImpl.kt
Outdated
Show resolved
Hide resolved
plugin-animation/src/main/java/com/mapbox/maps/plugin/animation/animator/CameraAnimator.kt
Outdated
Show resolved
Hide resolved
if (animator.haveUserListeners) { | ||
// If the animator have third-party listeners camera changes must be applied immediately | ||
// to be seen from the listeners. | ||
if (commitScheduled) handler.removeCallbacks(commitChangesRunnable) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: let's use {} even for single line and separate with new lines
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generally I'm seeing
if (commitScheduled) handler.removeCallbacks(commitChangesRunnable)
commitChangesRunnable.run()
for 3 times, let's move it to private function
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@zeac so do I get it correctly that accumulating camera optimization is not working if we do have userUpdateListeners
? Could there be a better way?
thanks to @LukasPaczos for stating it out.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Accumulated camera changes is flushed after value updates from Animators with third-party listeners only, so this optimization still works for NavigationCamera or GesturePlugin animations.
The only other way i see is to call all userUpdateListeners
manually after camera is updated. I'm not sure that it is a better way.
plugin-animation/src/main/java/com/mapbox/maps/plugin/animation/CameraAnimationsPluginImpl.kt
Show resolved
Hide resolved
2e5e990
to
120568e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@zeac thanks for your fantastic work in preparing this contribution!
LGTM
Pull request checklist:
mapbox-maps-android
changelog:<changelog>Fix issue with camera animators ordering on Android 6 and lower by revisiting overall approach of applying accumulated camera changes.</changelog>
.Fixes: #596
Summary of changes
The root of the problem is in the order of callbacks from ValueAnimators, that is different on Android 6. This PR changes core logic of applying animators making it easier to support and delegating updating accumulated
CameraOptions
toHandler
instead of relying on update of "oldest" animator (which as said before is not working as expected on Android 6 and below). This should not affect camera animation in any way, the only possible drawback is applying camera changes on each animator update if user has addedValueAnimator.AnimatorUpdateListener
instead of accumulating which should be a pretty rare use-case.