Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
[android] Call callback.onFinish() when camera is already at the corr…
Browse files Browse the repository at this point in the history
…ect position

[android] Call callback.onFinish() when camera is already at the correct position
  • Loading branch information
tobrun authored Sep 4, 2019
1 parent ed964fc commit a691db5
Show file tree
Hide file tree
Showing 2 changed files with 103 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ public void run() {
}
}
});
} else if (callback != null) {
callback.onFinish();
}
}

Expand All @@ -137,6 +139,8 @@ final void easeCamera(@NonNull MapboxMap mapboxMap, CameraUpdate update, int dur
mapView.addOnCameraDidChangeListener(this);
nativeMap.easeTo(cameraPosition.target, cameraPosition.zoom, cameraPosition.bearing, cameraPosition.tilt,
cameraPosition.padding, durationMs, easingInterpolator);
} else if (callback != null) {
callback.onFinish();
}
}

Expand All @@ -157,6 +161,8 @@ public final void animateCamera(@NonNull MapboxMap mapboxMap, CameraUpdate updat
mapView.addOnCameraDidChangeListener(this);
nativeMap.flyTo(cameraPosition.target, cameraPosition.zoom, cameraPosition.bearing,
cameraPosition.tilt, cameraPosition.padding, durationMs);
} else if (callback != null) {
callback.onFinish();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}
Expand All @@ -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
Expand Down

0 comments on commit a691db5

Please sign in to comment.