Skip to content

Commit 160bd69

Browse files
authored
use non-immediate dispatcher in camera component (#6449)
1 parent 56e02b6 commit 160bd69

6 files changed

Lines changed: 17 additions & 8 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ Mapbox welcomes participation and contributions from everyone.
1616
- Introduced `ViewStyleCutomization.compassButtonParams` property to configure compass. [#6395](https://github.com/mapbox/mapbox-navigation-android/pull/6395)
1717
- Introduced `MapboxExtendableButtonParams.enabled` property to enable/disable a button. [#6395](https://github.com/mapbox/mapbox-navigation-android/pull/6395)
1818
- Renamed `MapboxAudioGuidance.getInstance()` to `getRegisteredInstance`. Rename `unMute` to `unmute` for audio guidance classes. [#6445](https://github.com/mapbox/mapbox-navigation-android/pull/6445)
19+
- Fixed an issue with `NavigationView` that prevented camera from going into following state after starting a trip. [#6449](https://github.com/mapbox/mapbox-navigation-android/pull/6449)
1920

2021
## Mapbox Navigation SDK 2.9.0-alpha.4 - 30 September, 2022
2122
### Changelog

libnavui-base/api/current.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ package com.mapbox.navigation.ui.base.lifecycle {
4545
@com.mapbox.navigation.base.ExperimentalPreviewMapboxNavigationAPI public class UIComponent implements com.mapbox.navigation.core.lifecycle.MapboxNavigationObserver {
4646
ctor public UIComponent();
4747
method public final kotlinx.coroutines.CoroutineScope getCoroutineScope();
48-
method protected final inline <T> void observe(kotlinx.coroutines.flow.Flow<? extends T>, kotlin.jvm.functions.Function2<? super T,? super kotlin.coroutines.Continuation<? super kotlin.Unit>,?> action);
48+
method protected final inline <T> void observe(kotlinx.coroutines.flow.Flow<? extends T>, kotlin.coroutines.CoroutineContext context = EmptyCoroutineContext, kotlin.jvm.functions.Function2<? super T,? super kotlin.coroutines.Continuation<? super kotlin.Unit>,?> action);
4949
method @CallSuper public void onAttached(com.mapbox.navigation.core.MapboxNavigation mapboxNavigation);
5050
method @CallSuper public void onDetached(com.mapbox.navigation.core.MapboxNavigation mapboxNavigation);
5151
method public final void setCoroutineScope(kotlinx.coroutines.CoroutineScope);

libnavui-base/src/main/java/com/mapbox/navigation/ui/base/lifecycle/UIComponent.kt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import kotlinx.coroutines.cancel
1111
import kotlinx.coroutines.flow.Flow
1212
import kotlinx.coroutines.flow.collect
1313
import kotlinx.coroutines.launch
14+
import kotlin.coroutines.CoroutineContext
15+
import kotlin.coroutines.EmptyCoroutineContext
1416

1517
/**
1618
* Using the [UIComponent] gives you access to a [coroutineScope] which uses
@@ -42,7 +44,10 @@ open class UIComponent : MapboxNavigationObserver {
4244
coroutineScope.cancel()
4345
}
4446

45-
protected inline fun <T> Flow<T>.observe(crossinline action: suspend (value: T) -> Unit) {
46-
coroutineScope.launch { collect(action) }
47+
protected inline fun <T> Flow<T>.observe(
48+
context: CoroutineContext = EmptyCoroutineContext,
49+
crossinline action: suspend (value: T) -> Unit,
50+
) {
51+
coroutineScope.launch(context) { collect(action) }
4752
}
4853
}

libnavui-dropin/src/main/java/com/mapbox/navigation/dropin/camera/CameraComponent.kt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import com.mapbox.navigation.ui.maps.camera.lifecycle.NavigationBasicGesturesHan
2222
import com.mapbox.navigation.ui.maps.camera.transition.NavigationCameraTransitionOptions
2323
import com.mapbox.navigation.ui.maps.internal.extensions.flowNavigationCameraState
2424
import com.mapbox.navigation.utils.internal.logD
25+
import kotlinx.coroutines.Dispatchers
2526
import kotlinx.coroutines.flow.SharingStarted
2627
import kotlinx.coroutines.flow.collect
2728
import kotlinx.coroutines.flow.collectLatest
@@ -127,11 +128,12 @@ internal class CameraComponent constructor(
127128
}
128129

129130
private fun syncNavigationCameraState() {
130-
navigationCamera.flowNavigationCameraState().observe {
131+
// using immediate dispatcher causes nested store updates
132+
navigationCamera.flowNavigationCameraState().observe(Dispatchers.Main) {
131133
store.dispatch(SetCameraMode(it.toTargetCameraMode()))
132134
}
133135

134-
store.select { it.camera.cameraMode }.observe {
136+
store.select { it.camera.cameraMode }.observe(Dispatchers.Main) {
135137
val currentMode = navigationCamera.state.toTargetCameraMode()
136138
if (isCameraInitialized && it != currentMode) {
137139
when (it) {
@@ -219,7 +221,8 @@ internal class CameraComponent constructor(
219221
viewportDataSource.evaluate()
220222
}
221223
}
222-
coroutineScope.launch {
224+
// using immediate dispatcher causes nested store updates
225+
coroutineScope.launch(Dispatchers.Main) {
223226
store.select { it.navigation }.collectLatest { navigationState ->
224227
when (navigationState) {
225228
NavigationState.FreeDrive -> {

libnavui-maps/src/main/java/com/mapbox/navigation/ui/maps/internal/ui/CameraModeButtonComponent.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class CameraModeButtonComponent(
3434
super.onAttached(mapboxNavigation)
3535
val contract = contractProvider.get()
3636
contract.isVisible.observe { cameraModeButton.isVisible = it }
37-
contract.buttonState.observe(cameraModeButton::setState)
37+
contract.buttonState.observe { cameraModeButton.setState(it) }
3838
cameraModeButton.setOnClickListener(contract::onClick)
3939
}
4040

libnavui-maps/src/main/java/com/mapbox/navigation/ui/maps/internal/ui/RecenterButtonComponent.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,6 @@ internal class MapboxRecenterButtonComponentContract(
7474

7575
mapboxNavigation.flowLocationMatcherResult()
7676
.map { it.enhancedLocation }
77-
.observe(location::set)
77+
.observe { location.set(it) }
7878
}
7979
}

0 commit comments

Comments
 (0)