Skip to content

Commit 4ff37be

Browse files
jushgithub-actions[bot]
authored andcommitted
Avoid setting camera for Anchor animator (#6628)
Currently we call set camera per each Animator independently. For Anchor animator it doesn't make sense to call set camera since it will do nothing. This PR makes that more explicit and avoids some minor calls for the Anchor animator. Moreover, this PR also resets the camera builder instead of creating a new one on every animator update. cc @mapbox/maps-android GitOrigin-RevId: 2edc883a9b63a7cbfe8875f84fc1cdbb0364ff78
1 parent 9cbd785 commit 4ff37be

File tree

2 files changed

+17
-18
lines changed

2 files changed

+17
-18
lines changed

plugin-animation/src/main/java/com/mapbox/maps/plugin/animation/CameraAnimationsExt.kt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -340,11 +340,11 @@ internal fun updateCameraValue(
340340
* Convenience method to clear camera options so it can be reused instead of creating
341341
* new [CameraOptions.Builder].
342342
*/
343-
private fun CameraOptions.Builder.clear() {
343+
internal fun CameraOptions.Builder.clear() {
344344
center(null)
345-
.padding(null)
346-
.anchor(null)
347-
.zoom(null)
348-
.bearing(null)
349-
.pitch(null)
345+
padding(null)
346+
anchor(null)
347+
zoom(null)
348+
bearing(null)
349+
pitch(null)
350350
}

plugin-animation/src/main/java/com/mapbox/maps/plugin/animation/CameraAnimationsPluginImpl.kt

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -377,9 +377,6 @@ internal class CameraAnimationsPluginImpl : CameraAnimationsPlugin, MapCameraPlu
377377
AnimationFinishStatus.ENDED -> it.onAnimatorEnding(type, this, owner)
378378
}
379379
}
380-
if (runningAnimatorsQueue.isEmpty()) {
381-
commitChanges()
382-
}
383380
} ?: throw MapboxCameraAnimationException(
384381
"Could not finish animation as it must be an instance of CameraAnimator and not null!"
385382
)
@@ -399,22 +396,24 @@ internal class CameraAnimationsPluginImpl : CameraAnimationsPlugin, MapCameraPlu
399396
// add current animator to queue-set if was not present
400397
runningAnimatorsQueue.add(animator)
401398

402-
// set current animator value in any case
403-
updateCameraValue(animator, animator.animatedValue, cameraOptionsBuilder)
404-
399+
// Anchor animator is a special case. It won't affect the camera by itself so we cache the value
400+
// and apply it to the other animators.
405401
if (animator.type == CameraAnimatorType.ANCHOR) {
406402
anchor = animator.animatedValue as ScreenCoordinate
407-
}
403+
} else {
404+
// set current animator value to the camera options builder
405+
updateCameraValue(animator, animator.animatedValue, cameraOptionsBuilder)
408406

409-
// commit applies changes immediately
410-
// this helps to avoid camera animations jitter noticeable on high zoom levels using location puck following mode.
411-
commitChanges()
407+
// commit applies changes immediately
408+
// this helps to avoid camera animations jitter noticeable on high zoom levels using location puck following mode.
409+
commitChanges()
410+
}
412411
}
413412

414413
private fun commitChanges() {
415414
performMapJump(cameraOptionsBuilder.anchor(anchor).build())
416-
// reset values
417-
cameraOptionsBuilder = CameraOptions.Builder()
415+
// reset values so it can be reused
416+
cameraOptionsBuilder.clear()
418417
}
419418

420419
private fun cancelAnimatorSet() {

0 commit comments

Comments
 (0)