Skip to content

Commit 1492b14

Browse files
dzinadgithub-actions[bot]
authored andcommitted
NAVAND-5897: interpolate platform-calculated center to StatusAnimator center
GitOrigin-RevId: dfac1f1fd588069cf35a5d72841283a99577ff32
1 parent aa4d01f commit 1492b14

3 files changed

Lines changed: 72 additions & 6 deletions

File tree

ui-maps/src/main/java/com/mapbox/navigation/ui/maps/camera/data/MapboxNavigationViewportDataSource.kt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ class MapboxNavigationViewportDataSource private constructor(
223223

224224
constructor(mapboxMap: MapboxMap) : this(
225225
mapboxMap,
226-
FollowingFramingModeHolder(),
226+
null,
227227
OverviewViewportDataSource(
228228
mapboxMap,
229229
InternalViewportDataSourceOptions(
@@ -237,7 +237,7 @@ class MapboxNavigationViewportDataSource private constructor(
237237
// options and internalOptions must be the same instance in OverviewViewportDataSource and MapboxNavigationViewportDataSource
238238
internal constructor(
239239
mapboxMap: MapboxMap,
240-
followingFramingModeHolder: FollowingFramingModeHolder,
240+
followingFramingModeHolder: FollowingFramingModeHolder?,
241241
overviewViewportDataSource: OverviewViewportDataSource,
242242
) : this(
243243
mapboxMap,
@@ -762,7 +762,6 @@ class MapboxNavigationViewportDataSource private constructor(
762762
followingCenterProperty.fallback = cameraState.center
763763
followingZoomProperty.fallback = max(min(cameraState.zoom, maxZoom), minZoom)
764764
}
765-
followingFramingModeHolder?.mode = FollowingFramingMode.NONE
766765
// nothing to frame
767766
return
768767
}
@@ -833,7 +832,6 @@ class MapboxNavigationViewportDataSource private constructor(
833832

834833
if (cameraFrame.isEmpty) {
835834
logW { "CameraOptions is empty" }
836-
followingFramingModeHolder?.mode = FollowingFramingMode.NONE
837835
return
838836
}
839837

ui-maps/src/main/java/com/mapbox/navigation/ui/maps/internal/camera/FollowingFramingModeHolder.kt

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,20 @@ package com.mapbox.navigation.ui.maps.internal.camera
33
import androidx.annotation.RestrictTo
44

55
@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP_PREFIX)
6-
enum class FollowingFramingMode { NONE, LOCATION_INDICATOR, MULTIPLE_POINTS }
6+
enum class FollowingFramingMode {
7+
LOCATION_INDICATOR,
8+
MULTIPLE_POINTS,
9+
}
710

811
@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP_PREFIX)
912
class FollowingFramingModeHolder {
1013

11-
var mode: FollowingFramingMode = FollowingFramingMode.NONE
14+
var prevMode: FollowingFramingMode = FollowingFramingMode.LOCATION_INDICATOR
15+
private set
16+
17+
var mode: FollowingFramingMode = FollowingFramingMode.LOCATION_INDICATOR
18+
set(value) {
19+
prevMode = field
20+
field = value
21+
}
1222
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package com.mapbox.navigation.ui.maps.internal.camera
2+
3+
import org.junit.Assert.assertEquals
4+
import org.junit.Before
5+
import org.junit.Test
6+
7+
class FollowingFramingModeHolderTest {
8+
9+
private lateinit var holder: FollowingFramingModeHolder
10+
11+
@Before
12+
fun setup() {
13+
holder = FollowingFramingModeHolder()
14+
}
15+
16+
@Test
17+
fun `initial state has LOCATION_INDICATOR mode and prevMode`() {
18+
assertEquals(FollowingFramingMode.LOCATION_INDICATOR, holder.mode)
19+
assertEquals(FollowingFramingMode.LOCATION_INDICATOR, holder.prevMode)
20+
}
21+
22+
@Test
23+
fun `setting mode to different value updates prevMode`() {
24+
holder.mode = FollowingFramingMode.LOCATION_INDICATOR
25+
holder.mode = FollowingFramingMode.MULTIPLE_POINTS
26+
27+
assertEquals(FollowingFramingMode.MULTIPLE_POINTS, holder.mode)
28+
assertEquals(FollowingFramingMode.LOCATION_INDICATOR, holder.prevMode)
29+
}
30+
31+
@Test
32+
fun `setting mode to same value updates prevMode`() {
33+
holder.mode = FollowingFramingMode.LOCATION_INDICATOR
34+
holder.mode = FollowingFramingMode.LOCATION_INDICATOR
35+
36+
assertEquals(FollowingFramingMode.LOCATION_INDICATOR, holder.mode)
37+
assertEquals(FollowingFramingMode.LOCATION_INDICATOR, holder.prevMode)
38+
}
39+
40+
@Test
41+
fun `alternating between two modes works correctly`() {
42+
holder.mode = FollowingFramingMode.MULTIPLE_POINTS
43+
assertEquals(FollowingFramingMode.MULTIPLE_POINTS, holder.mode)
44+
assertEquals(FollowingFramingMode.LOCATION_INDICATOR, holder.prevMode)
45+
46+
holder.mode = FollowingFramingMode.LOCATION_INDICATOR
47+
assertEquals(FollowingFramingMode.LOCATION_INDICATOR, holder.mode)
48+
assertEquals(FollowingFramingMode.MULTIPLE_POINTS, holder.prevMode)
49+
50+
holder.mode = FollowingFramingMode.MULTIPLE_POINTS
51+
assertEquals(FollowingFramingMode.MULTIPLE_POINTS, holder.mode)
52+
assertEquals(FollowingFramingMode.LOCATION_INDICATOR, holder.prevMode)
53+
54+
holder.mode = FollowingFramingMode.LOCATION_INDICATOR
55+
assertEquals(FollowingFramingMode.LOCATION_INDICATOR, holder.mode)
56+
assertEquals(FollowingFramingMode.MULTIPLE_POINTS, holder.prevMode)
57+
}
58+
}

0 commit comments

Comments
 (0)