-
-
Notifications
You must be signed in to change notification settings - Fork 915
feat: remove deprecated RNMBXMapView's mapView & mapboxMap APIs #3963
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -40,20 +40,22 @@ struct CameraUpdateItem { | |
| var duration: TimeInterval? | ||
|
|
||
| func execute(map: RNMBXMapView, cameraAnimator: inout BasicCameraAnimator?) { | ||
| logged("CameraUpdateItem.execute") { | ||
| if let center = camera.center { | ||
| try center.validate() | ||
| } | ||
| map.withMapView { _mapView in | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
| logged("CameraUpdateItem.execute") { | ||
| if let center = camera.center { | ||
| try center.validate() | ||
| } | ||
|
|
||
| switch mode { | ||
| case .flight: | ||
| map.mapView.camera.fly(to: camera, duration: duration) | ||
| case .ease: | ||
| map.mapView.camera.ease(to: camera, duration: duration ?? 0, curve: .easeInOut, completion: nil) | ||
| case .linear: | ||
| map.mapView.camera.ease(to: camera, duration: duration ?? 0, curve: .linear, completion: nil) | ||
| default: | ||
| map.mapboxMap.setCamera(to: camera) | ||
| switch mode { | ||
| case .flight: | ||
| _mapView.camera.fly(to: camera, duration: duration) | ||
| case .ease: | ||
| _mapView.camera.ease(to: camera, duration: duration ?? 0, curve: .easeInOut, completion: nil) | ||
| case .linear: | ||
| _mapView.camera.ease(to: camera, duration: duration ?? 0, curve: .linear, completion: nil) | ||
| default: | ||
| _mapView.mapboxMap.setCamera(to: camera) | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
@@ -92,7 +94,9 @@ open class RNMBXMapComponentBase : UIView, RNMBXMapComponent { | |
|
|
||
| func withMapView(_ callback: @escaping (_ mapView: MapView) -> Void) { | ||
| withRNMBXMapView { mapView in | ||
| callback(mapView.mapView) | ||
| mapView.withMapView { _mapView in | ||
| callback(_mapView) | ||
| } | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -529,7 +533,9 @@ open class RNMBXCamera : RNMBXMapComponentBase { | |
| return false | ||
| } | ||
|
|
||
| map.mapView.viewport.removeStatusObserver(self) | ||
| map.withMapView { _mapView in | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as the other remove, we don't want to try to remove from other mapViewpot we've added ourselves to |
||
| _mapView.viewport.removeStatusObserver(self) | ||
| } | ||
| return super.removeFromMap(map, reason:reason) | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -47,8 +47,8 @@ public class RNMBXCustomLocationProvider: UIView, RNMBXMapComponent { | |
|
|
||
| public func addToMap(_ map: RNMBXMapView, style: Style) { | ||
| self.map = map | ||
| if let mapView = map.mapView { | ||
| installCustomeLocationProviderIfNeeded(mapView: mapView) | ||
| map.withMapView{ _mapView in | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So we have a valid style, we should have a map too. Maybe add a map parameter as well?! |
||
| self.installCustomeLocationProviderIfNeeded(mapView: _mapView) | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -61,10 +61,10 @@ public class RNMBXCustomLocationProvider: UIView, RNMBXMapComponent { | |
| } | ||
|
|
||
| public func removeFromMap(_ map: RNMBXMapView, reason: RemovalReason) -> Bool { | ||
| if let mapView = map.mapView { | ||
| removeCustomLocationProvider(mapView: mapView) | ||
| map.withMapView { _mapView in | ||
| self.removeCustomLocationProvider(mapView: _mapView) | ||
| self.map = nil | ||
| } | ||
| self.map = nil | ||
| return true | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,8 +7,11 @@ public class RNMBXImageSource : RNMBXSource { | |
| didSet { | ||
| if var source = source as? ImageSource { | ||
| source.url = url | ||
| self.doUpdate { (style) in | ||
| try! style.setSourceProperty(for: id, property: "url", value: url) | ||
| self.map?.withMapboxMap { [weak self] _mapboxMap in | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same concern here as well. We've added ourself to style. So we don't want to wait for it again. Maybe we should save the style here as well |
||
| guard let self = self else { return } | ||
| self.doUpdate(_mapboxMap: _mapboxMap) { (style) in | ||
| try! style.setSourceProperty(for: self.id, property: "url", value: source.url) | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
@@ -22,8 +25,11 @@ public class RNMBXImageSource : RNMBXSource { | |
| } else { | ||
| source.coordinates = nil | ||
| } | ||
| self.doUpdate { (style) in | ||
| try! style.setSourceProperty(for: id, property: "coordinates", value: source.coordinates) | ||
| self.map?.withMapboxMap { [weak self] _mapboxMap in | ||
| guard let self = self else { return } | ||
| self.doUpdate(_mapboxMap: _mapboxMap) { (style) in | ||
| try! style.setSourceProperty(for: self.id, property: "coordinates", value: source.coordinates) | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
@@ -51,14 +57,14 @@ public class RNMBXImageSource : RNMBXSource { | |
| return result | ||
| } | ||
|
|
||
| func doUpdate(_ update:(Style) -> Void) { | ||
| func doUpdate(_mapboxMap: MapboxMap, _ update:(Style) -> Void) { | ||
| guard let map = self.map, | ||
| let _ = self.source, | ||
| map.mapboxMap.style.sourceExists(withId: id) else { | ||
| _mapboxMap.style.sourceExists(withId: id) else { | ||
| return | ||
| } | ||
|
|
||
| let style = map.mapboxMap.style | ||
| let style = _mapboxMap.style | ||
| update(style) | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure about this. Maybe we should store the style we've added ourself to? Doesn't make much sense to wait for a style here. It could be other style, then we've added to, so...
Also not sure if a race like this is possible:
this can't happen as 6.) will be called before 4.) but it's something I need to think about on every change like this.