[android] Call callback.onFinish() when camera is already at the correct position
[android] Call callback.onFinish() when camera is already at the correct position
This commit is contained in:
@@ -120,6 +120,8 @@ public final class Transform implements MapView.OnCameraDidChangeListener {
|
||||
}
|
||||
}
|
||||
});
|
||||
} else if (callback != null) {
|
||||
callback.onFinish();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -137,6 +139,8 @@ public final class Transform implements MapView.OnCameraDidChangeListener {
|
||||
mapView.addOnCameraDidChangeListener(this);
|
||||
nativeMap.easeTo(cameraPosition.target, cameraPosition.zoom, cameraPosition.bearing, cameraPosition.tilt,
|
||||
cameraPosition.padding, durationMs, easingInterpolator);
|
||||
} else if (callback != null) {
|
||||
callback.onFinish();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -157,6 +161,8 @@ public final class Transform implements MapView.OnCameraDidChangeListener {
|
||||
mapView.addOnCameraDidChangeListener(this);
|
||||
nativeMap.flyTo(cameraPosition.target, cameraPosition.zoom, cameraPosition.bearing,
|
||||
cameraPosition.tilt, cameraPosition.padding, durationMs);
|
||||
} else if (callback != null) {
|
||||
callback.onFinish();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -26,6 +26,7 @@ class TransformTest {
|
||||
every { nativeMapView.cameraPosition } returns CameraPosition.DEFAULT
|
||||
every { nativeMapView.cancelTransitions() } answers {}
|
||||
every { nativeMapView.jumpTo(any(), any(), any(), any(), any()) } answers {}
|
||||
every { nativeMapView.easeTo(any(), any(), any(), any(), any(), any(), any()) } answers {}
|
||||
every { nativeMapView.flyTo(any(), any(), any(), any(), any(), any()) } answers {}
|
||||
every { nativeMapView.minZoom = any() } answers {}
|
||||
every { nativeMapView.maxZoom = any() } answers {}
|
||||
@@ -48,6 +49,102 @@ class TransformTest {
|
||||
verify { callback.onFinish() }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testMoveCameraToSamePosition() {
|
||||
val mapboxMap = mockk<MapboxMap>()
|
||||
every { mapboxMap.cameraPosition } answers { CameraPosition.DEFAULT }
|
||||
|
||||
val callback = mockk<MapboxMap.CancelableCallback>()
|
||||
every { callback.onFinish() } answers {}
|
||||
|
||||
val expected = CameraPosition.DEFAULT
|
||||
val update = CameraUpdateFactory.newCameraPosition(expected)
|
||||
|
||||
transform.moveCamera(mapboxMap, update, null) // Initialize camera position
|
||||
transform.moveCamera(mapboxMap, update, callback)
|
||||
|
||||
verify(exactly = 1, verifyBlock = { nativeMapView.jumpTo(any(), any(), any(), any(), any()) })
|
||||
verify { callback.onFinish() }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testEaseCamera() {
|
||||
val mapboxMap = mockk<MapboxMap>()
|
||||
every { mapboxMap.cameraPosition } answers { CameraPosition.DEFAULT }
|
||||
|
||||
every { mapView.addOnCameraDidChangeListener(any()) } answers { transform.onCameraDidChange(true) }
|
||||
every { mapView.removeOnCameraDidChangeListener(any()) } answers {}
|
||||
|
||||
val callback = mockk<MapboxMap.CancelableCallback>()
|
||||
every { callback.onFinish() } answers {}
|
||||
|
||||
val target = LatLng(1.0, 2.0)
|
||||
val expected = CameraPosition.Builder().target(target).build()
|
||||
val update = CameraUpdateFactory.newCameraPosition(expected)
|
||||
|
||||
transform.easeCamera(mapboxMap, update, 100, false, callback)
|
||||
|
||||
verify { nativeMapView.easeTo(target, -1.0, -1.0, -1.0, null, 100, false) }
|
||||
verify { callback.onFinish() }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testEaseCameraToSamePosition() {
|
||||
val mapboxMap = mockk<MapboxMap>()
|
||||
every { mapboxMap.cameraPosition } answers { CameraPosition.DEFAULT }
|
||||
|
||||
val callback = mockk<MapboxMap.CancelableCallback>()
|
||||
every { callback.onFinish() } answers {}
|
||||
|
||||
val expected = CameraPosition.DEFAULT
|
||||
val update = CameraUpdateFactory.newCameraPosition(expected)
|
||||
transform.moveCamera(mapboxMap, update, null)
|
||||
|
||||
transform.easeCamera(mapboxMap, update, 100, false, callback)
|
||||
|
||||
verify(exactly = 0, verifyBlock = { nativeMapView.easeTo(any(), any(), any(), any(), any(), any(), any()) })
|
||||
verify { callback.onFinish() }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testAnimateCamera() {
|
||||
val mapboxMap = mockk<MapboxMap>()
|
||||
every { mapboxMap.cameraPosition } answers { CameraPosition.DEFAULT }
|
||||
|
||||
every { mapView.addOnCameraDidChangeListener(any()) } answers { transform.onCameraDidChange(true) }
|
||||
every { mapView.removeOnCameraDidChangeListener(any()) } answers {}
|
||||
|
||||
val callback = mockk<MapboxMap.CancelableCallback>()
|
||||
every { callback.onFinish() } answers {}
|
||||
|
||||
val target = LatLng(1.0, 2.0)
|
||||
val expected = CameraPosition.Builder().target(target).build()
|
||||
val update = CameraUpdateFactory.newCameraPosition(expected)
|
||||
|
||||
transform.animateCamera(mapboxMap, update, 100, callback)
|
||||
|
||||
verify { nativeMapView.flyTo(target, -1.0, -1.0, -1.0, null, 100) }
|
||||
verify { callback.onFinish() }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testAnimateCameraToSamePosition() {
|
||||
val mapboxMap = mockk<MapboxMap>()
|
||||
every { mapboxMap.cameraPosition } answers { CameraPosition.DEFAULT }
|
||||
|
||||
val callback = mockk<MapboxMap.CancelableCallback>()
|
||||
every { callback.onFinish() } answers {}
|
||||
|
||||
val expected = CameraPosition.DEFAULT
|
||||
val update = CameraUpdateFactory.newCameraPosition(expected)
|
||||
transform.moveCamera(mapboxMap, update, null)
|
||||
|
||||
transform.animateCamera(mapboxMap, update, 100, callback)
|
||||
|
||||
verify(exactly = 0, verifyBlock = { nativeMapView.flyTo(any(), any(), any(), any(), any(), any()) })
|
||||
verify { callback.onFinish() }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testMinZoom() {
|
||||
transform.minZoom = 10.0
|
||||
|
||||
Reference in New Issue
Block a user