Skip to content

Commit 7c7a746

Browse files
natiginfogithub-actions[bot]
authored andcommitted
[maps-android] utilize duration when OverviewViewportStateOptions.animationDurationMs is set (#9505)
GitOrigin-RevId: b8c3e1e69c3ecf03fd9b9e8790a67e2e24082d0c
1 parent 3ab9f27 commit 7c7a746

4 files changed

Lines changed: 34 additions & 2 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ Mapbox welcomes participation and contributions from everyone.
1313

1414
## Bug fixes 🐞
1515
* Fix rare scenario where map render surface size was wrong.
16+
* Respect `animationDurationMs` when custom `OverviewViewportStateOptions.animationDurationMs` is set.
1617

1718

1819
# 11.18.0 January 15, 2026

compose-app/src/main/java/com/mapbox/maps/compose/testapp/examples/animation/MapViewportAnimationsActivity.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ public class MapViewportAnimationsActivity : ComponentActivity() {
104104
)
105105
)
106106
)
107+
.animationDurationMs(600L)
107108
.padding(EdgeInsets(100.0, 100.0, 100.0, 100.0))
108109
.build(),
109110
defaultTransitionOptions = DefaultViewportTransitionOptions.Builder()

plugin-viewport/src/main/kotlin/com/mapbox/maps/plugin/viewport/transition/DefaultViewportTransitionImpl.kt

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ import com.mapbox.maps.plugin.animation.animator.CameraAnimator
1515
import com.mapbox.maps.plugin.animation.camera
1616
import com.mapbox.maps.plugin.delegates.MapDelegateProvider
1717
import com.mapbox.maps.plugin.viewport.CompletionListener
18+
import com.mapbox.maps.plugin.viewport.DEFAULT_STATE_ANIMATION_DURATION_MS
1819
import com.mapbox.maps.plugin.viewport.data.DefaultViewportTransitionOptions
20+
import com.mapbox.maps.plugin.viewport.state.OverviewViewportState
1921
import com.mapbox.maps.plugin.viewport.state.ViewportState
2022
import com.mapbox.maps.threading.AnimationThreadController
2123
import com.mapbox.maps.util.MathUtils
@@ -68,7 +70,7 @@ internal class DefaultViewportTransitionImpl(
6870
startCamera,
6971
cameraOptions
7072
) ?: kotlin.run {
71-
val initialAnimatorSet = createAnimatorSet(cameraOptions, options.maxDurationMs)
73+
val initialAnimatorSet = createAnimatorSet(to, cameraOptions, options.maxDurationMs)
7274
.apply {
7375
addListener(
7476
object : Animator.AnimatorListener {
@@ -133,7 +135,25 @@ internal class DefaultViewportTransitionImpl(
133135
}
134136
}
135137

136-
private fun createAnimatorSet(cameraOptions: CameraOptions, maxDurationMs: Long): AnimatorSet {
138+
private fun createAnimatorSet(
139+
targetState: ViewportState,
140+
cameraOptions: CameraOptions,
141+
maxDurationMs: Long
142+
): AnimatorSet {
143+
// If transitioning to OverviewViewportState and user has explicitly customized animationDurationMs,
144+
// animate using that value. Otherwise, use default animation logic.
145+
if (targetState is OverviewViewportState) {
146+
val overviewDuration = targetState.options.animationDurationMs
147+
148+
// Only use linear animation if user explicitly set a different duration from default.
149+
// If user did not customize duration, then we will fallback to default animation logic
150+
if (overviewDuration != DEFAULT_STATE_ANIMATION_DURATION_MS) {
151+
// Use the state's animation duration, but still respect maxDurationMs as an upper bound
152+
val effectiveDuration = minOf(overviewDuration, maxDurationMs)
153+
return transitionFactory.transitionLinear(cameraOptions, effectiveDuration)
154+
}
155+
}
156+
137157
val currentZoom = cameraDelegate.cameraState.zoom
138158
return with(transitionFactory) {
139159
if (currentZoom < (cameraOptions.zoom ?: currentZoom)) {

sdk-base/src/main/java/com/mapbox/maps/plugin/viewport/data/OverviewViewportStateOptions.kt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@ class OverviewViewportStateOptions private constructor(
5858
* The length of the animation performed in milliseconds by [OverviewViewportState] when it starts
5959
* updating the camera and anytime [OverviewViewportState.options] is set.
6060
*
61+
* When set to a custom value, transitions will use fixed-duration linear animations that take
62+
* exactly the specified duration regardless of distance. This provides predictable timing but
63+
* may result in very fast camera movement for large distances. Consider using longer durations
64+
* or keeping the default value if animating over large geographic areas.
65+
*
6166
* @see [OverviewViewportState.options] for details.
6267
*
6368
* Defaults to [DEFAULT_STATE_ANIMATION_DURATION_MS] milliseconds
@@ -177,6 +182,11 @@ class OverviewViewportStateOptions private constructor(
177182
* The length of the animation performed by [OverviewViewportState] when it starts updating the
178183
* camera and anytime [OverviewViewportState.options] is set.
179184
*
185+
* When set to a custom value, transitions will use fixed-duration linear animations that take
186+
* exactly the specified duration regardless of distance. This provides predictable timing but
187+
* may result in very fast camera movement for large distances. Consider using longer durations
188+
* or keeping the default value if animating over large geographic areas.
189+
*
180190
* @see [OverviewViewportState.options] for details.
181191
*
182192
* Defaults to [DEFAULT_STATE_ANIMATION_DURATION_MS] milliseconds

0 commit comments

Comments
 (0)