Skip to content

Commit

Permalink
expose NavigationViewApi.recenterCamera
Browse files Browse the repository at this point in the history
  • Loading branch information
LukasPaczos committed Jan 18, 2024
1 parent 537fc9b commit 1a5f235
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 +117,10 @@ abstract class NavigationViewApi {
* Access the current instance of [MapboxVoiceInstructionsPlayer] created by [NavigationView].
*/
abstract fun getCurrentVoiceInstructionsPlayer(): MapboxVoiceInstructionsPlayer?

/**
* If the camera is idle or in overview mode, calling this function will dispatch an action
* that will reposition the camera back to the user locaiton indicator (as if the recenter button was clicked).
*/
abstract fun recenterCamera()
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ internal class RecenterButtonComponentContractImpl(
}

override fun onClick(view: View) {
store.dispatch(CameraAction.SetCameraMode(TargetCameraMode.Following))
store.recenterCamera()
}
}

internal fun Store.recenterCamera() = dispatch(
CameraAction.SetCameraMode(TargetCameraMode.Following)
)
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import com.mapbox.navigation.core.lifecycle.MapboxNavigationApp
import com.mapbox.navigation.dropin.NavigationViewApi
import com.mapbox.navigation.dropin.NavigationViewApiError
import com.mapbox.navigation.dropin.NavigationViewApiErrorTypes
import com.mapbox.navigation.dropin.camera.recenterCamera
import com.mapbox.navigation.ui.app.internal.Store
import com.mapbox.navigation.ui.app.internal.endNavigation
import com.mapbox.navigation.ui.app.internal.extension.dispatch
Expand Down Expand Up @@ -108,6 +109,10 @@ internal class MapboxNavigationViewApi(
return MapboxAudioGuidance.getRegisteredInstance().getCurrentVoiceInstructionsPlayer()
}

override fun recenterCamera() {
store.recenterCamera()
}

@Throws(NavigationViewApiError::class)
private fun checkDestination() {
if (store.state.value.destination == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import com.mapbox.navigation.core.lifecycle.MapboxNavigationApp
import com.mapbox.navigation.dropin.NavigationViewApiErrorTypes
import com.mapbox.navigation.dropin.util.TestStore
import com.mapbox.navigation.ui.app.internal.Reducer
import com.mapbox.navigation.ui.app.internal.camera.CameraAction
import com.mapbox.navigation.ui.app.internal.camera.TargetCameraMode
import com.mapbox.navigation.ui.app.internal.destination.Destination
import com.mapbox.navigation.ui.app.internal.destination.DestinationAction
import com.mapbox.navigation.ui.app.internal.navigation.NavigationState
Expand Down Expand Up @@ -368,6 +370,12 @@ class MapboxNavigationViewApiTest {
assertNull(sut.getCurrentVoiceInstructionsPlayer())
}

@Test
fun `recenterCamera should dispatch store action`() {
sut.recenterCamera()
verify { testStore.dispatch(CameraAction.SetCameraMode(TargetCameraMode.Following)) }
}

private fun navigationRoute(vararg waypoints: Point): NavigationRoute {
return mockk {
every { routeOptions } returns mockk(relaxed = true) {
Expand Down

0 comments on commit 1a5f235

Please sign in to comment.