Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,6 @@ After `stopNavigation`, the route and the puck are removed and the camera eases
## Limitations

- `@rnmapbox/maps` `LocationPuck` and `UserLocation` don't work on navigation maps: the navigation puck replaces the map's location provider.
- iOS: `@rnmapbox/maps` takes over the map's `gestures.delegate`, so `NavigationMapViewDelegate` interaction callbacks don't fire. Gesture handling for the camera state doesn't depend on them.
- One navigation session for all navigation maps. Per-map routes or cameras aren't supported.
- Route progress events already on their way to JS still arrive after `stopNavigation`. Ignore them if you need to.
- Not tested yet: live (non-simulated) guidance on a device, release builds, several navigation maps at once, and unmounting a map during guidance.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import com.mapbox.navigation.ui.maps.route.line.api.MapboxRouteLineApi
import com.mapbox.navigation.ui.maps.route.line.api.MapboxRouteLineView
import com.mapbox.navigation.ui.maps.route.line.model.MapboxRouteLineApiOptions
import com.mapbox.navigation.ui.maps.route.line.model.MapboxRouteLineViewOptions
import com.rnmapbox.rnmbx.components.mapview.Cancelable
import com.rnmapbox.rnmbx.components.mapview.OnCameraWillMoveMapListener
import com.rnmapbox.rnmbx.components.mapview.RNMBXMapView
import com.rnmapbox.rnmbx.components.mapview.RNMBXMapViewFactory
Expand All @@ -44,15 +45,14 @@ object RNMBXNavigationMapFactory {
RNMBXMapViewFactory.register(MAP_VIEW_IMPL) { _, parent -> createMapView(parent) }
}

private fun createMapView(parent: ViewGroup): MapView {
private fun createMapView(parent: RNMBXMapView): MapView {
val mapView = MapView(parent.context)
mapView.layoutParams = FrameLayout.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT
)
parent.addView(mapView)
val binding = RNMBXNavigationMapBinding(mapView)
(parent as? RNMBXMapView)?.addOnCameraWillMoveMapListener(binding)
val binding = RNMBXNavigationMapBinding(mapView, parent)
bindings[mapView] = binding
return mapView
}
Expand All @@ -64,7 +64,10 @@ object RNMBXNavigationMapFactory {
}

/** Mirrors [RNMBXNavigationSession] onto one MapView while it's attached to a window. */
class RNMBXNavigationMapBinding(private val mapView: MapView) :
class RNMBXNavigationMapBinding(
private val mapView: MapView,
private val parent: RNMBXMapView? = null
) :
RNMBXNavigationSession.Listener, View.OnAttachStateChangeListener, OnCameraWillMoveMapListener {

private val locationProvider = NavigationLocationProvider()
Expand All @@ -75,6 +78,8 @@ class RNMBXNavigationMapBinding(private val mapView: MapView) :
)
private val routeLineView = MapboxRouteLineView(MapboxRouteLineViewOptions.Builder(mapView.context).build())

private var cameraWillMoveMapRegistration: Cancelable? = null

private var navigationCameraState = NavigationCameraState.IDLE
private val onNavigationCameraState = NavigationCameraStateChangedObserver { state ->
val wasActive = navigationCameraState != NavigationCameraState.IDLE
Expand Down Expand Up @@ -135,11 +140,14 @@ class RNMBXNavigationMapBinding(private val mapView: MapView) :
override fun onViewAttachedToWindow(view: View) {
mapView.location.addOnIndicatorPositionChangedListener(onPuckPosition)
navigationCamera.registerNavigationCameraStateChangeObserver(onNavigationCameraState)
cameraWillMoveMapRegistration = parent?.addOnCameraWillMoveMapListener(this)
RNMBXNavigationSession.addListener(this)
}

override fun onViewDetachedFromWindow(view: View) {
RNMBXNavigationSession.removeListener(this)
cameraWillMoveMapRegistration?.cancel()
cameraWillMoveMapRegistration = null
navigationCamera.unregisterNavigationCameraStateChangeObserver(onNavigationCameraState)
mapView.location.removeOnIndicatorPositionChangedListener(onPuckPosition)
routeLineApi.cancel()
Expand Down
8 changes: 4 additions & 4 deletions example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1785,11 +1785,11 @@ PODS:
- React-utils (= 0.84.1)
- ReactNativeDependencies
- ReactNativeDependencies (0.84.1)
- rnmapbox-maps (10.3.10):
- rnmapbox-maps (10.3.11):
- React
- React-Core
- rnmapbox-maps/DynamicLibrary (= 10.3.10)
- rnmapbox-maps/DynamicLibrary (10.3.10):
- rnmapbox-maps/DynamicLibrary (= 10.3.11)
- rnmapbox-maps/DynamicLibrary (10.3.11):
- hermes-engine
- RCTRequired
- RCTTypeSafety
Expand Down Expand Up @@ -2137,7 +2137,7 @@ SPEC CHECKSUMS:
ReactCodegen: 797de5178718324c6eba3327b07f9a423fbd5787
ReactCommon: 07572bf9e687c8a52fbe4a3641e9e3a1a477c78e
ReactNativeDependencies: f87e546ce8bce7e377018d6516f8105e90c0b491
rnmapbox-maps: f8e61127245890ebf5b3cad9653830dc45499c11
rnmapbox-maps: 5f06d0ba48bafae784ea06d5b9f5b79217330c73
rnmapbox-navigation: a2931d7566bf4fe912586bbeec86ecb73da7ee6a
Yoga: c0b3f2c7e8d3e327e450223a2414ca3fa296b9a2

Expand Down
2 changes: 1 addition & 1 deletion example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"typecheck": "tsc --noEmit"
},
"dependencies": {
"@rnmapbox/maps": "10.3.10",
"@rnmapbox/maps": "10.3.11",
"react": "19.2.3",
"react-native": "0.84.1"
},
Expand Down
30 changes: 8 additions & 22 deletions ios/RNMBXNavigationMapFactory.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public final class RNMBXNavigationMapFactory: NSObject {
})
}

@MainActor private static func makeMapView(in parent: UIView) -> MapView {
@MainActor private static func makeMapView(in parent: RNMBXMapView) -> MapView {
let session = RNMBXNavigationSession.shared
let navigationMapView = RNMBXNavigationMapView(
location: session.$location.compactMap { $0 }.eraseToAnyPublisher(),
Expand All @@ -31,7 +31,7 @@ public final class RNMBXNavigationMapFactory: NSObject {
parent.addSubview(navigationMapView)

let binding = RNMBXNavigationMapBinding(navigationMapView, session: session)
(parent as? RNMBXMapView)?.addCameraDelegate(binding)
parent.addCameraDelegate(binding)
objc_setAssociatedObject(navigationMapView, &bindingKey, binding, .OBJC_ASSOCIATION_RETAIN_NONATOMIC)
return navigationMapView.mapView
}
Expand Down Expand Up @@ -111,31 +111,17 @@ private final class RNMBXNavigationMapBinding: NSObject {
}
.store(in: &subscriptions)

// The SDK's own gesture handling goes through `mapView.gestures.delegate`, which rnmapbox replaces, and the
// core `NavigationCamera` keeps following through gestures anyway, so hand the camera to the user here.
let gestures: GestureManager = navigationMapView.mapView.gestures
for recognizer in [
gestures.panGestureRecognizer,
gestures.pinchGestureRecognizer,
gestures.rotateGestureRecognizer,
gestures.pitchGestureRecognizer,
gestures.doubleTapToZoomInGestureRecognizer,
gestures.doubleTouchToZoomOutGestureRecognizer,
gestures.quickZoomGestureRecognizer,
] {
recognizer.addTarget(self, action: #selector(userGesture(_:)))
}
navigationMapView.delegate = self
}
}

@objc private func userGesture(_ recognizer: UIGestureRecognizer) {
let started = recognizer is UITapGestureRecognizer ? recognizer.state == .ended : recognizer.state == .began
if started {
session.cameraState = .idle
}
extension RNMBXNavigationMapBinding: NavigationMapViewDelegate {
func navigationMapViewUserDidStartInteraction(_ navigationMapView: NavigationMapView) {
session.cameraState = .idle
}
}

extension RNMBXNavigationMapBinding: @preconcurrency RNMBXCameraDelegate {
extension RNMBXNavigationMapBinding: RNMBXCameraDelegate {
func cameraWillMoveMap(_ map: RNMBXMapView) {
session.cameraState = .idle
}
Expand Down
10 changes: 5 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2500,9 +2500,9 @@ __metadata:
languageName: node
linkType: hard

"@rnmapbox/maps@npm:10.3.10":
version: 10.3.10
resolution: "@rnmapbox/maps@npm:10.3.10"
"@rnmapbox/maps@npm:10.3.11":
version: 10.3.11
resolution: "@rnmapbox/maps@npm:10.3.11"
dependencies:
"@turf/along": "npm:6.5.0"
"@turf/distance": "npm:6.5.0"
Expand All @@ -2524,7 +2524,7 @@ __metadata:
optional: true
react-dom:
optional: true
checksum: 10c0/4fc9be6df29162ab611168c0822bbc162e2fc133c815245b5488226b81c20d8cb3c1c6351d1797edc00cd98f9925f4c71d085141d102e26dcba78778859cddd7
checksum: 10c0/19200c19545dd94b574067c74fe11d2f72047dcc10872a80aa647ff45de34fd9fddff44ea033aacf1fc7cca29edb1c56fbccddaf9c268b42cd575872adbba762
languageName: node
linkType: hard

Expand All @@ -2541,7 +2541,7 @@ __metadata:
"@react-native/babel-preset": "npm:0.84.1"
"@react-native/metro-config": "npm:0.84.1"
"@react-native/typescript-config": "npm:0.84.1"
"@rnmapbox/maps": "npm:10.3.10"
"@rnmapbox/maps": "npm:10.3.11"
"@types/react": "npm:^19.2.0"
react: "npm:19.2.3"
react-native: "npm:0.84.1"
Expand Down
Loading