-
-
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?
Conversation
In our App, the deprecated APIs (`RNMBXMapView.mapView` & `RNMBXMapView.mapboxMap`) cause the app to crash because rnmapbox is trying to unwrap them while they are still `nil`. This PR removes those two deprecated APIs and changes all their usage to the safe `withMapView` & `withMapboxMap` API calls.
|
@PRESIDENT810 thanks much for the PR Unfortunately it's a bit complicated. Like in case of remove? withMapView could keep stuff alive and create a leak. So one thing we have to be carefully withMapView is leaks the other is concurrency, as the code will be called from other thread. And can cause deadlock and other issues. Do you perhaps has stack traces? So we can address those cases, where you hit by the nil mapboxMap? |
|
@mfazekas Here's the stacktrace I can see the crash is caused by 5th closure in RNMBXMapView.setupEvents with "Swift runtime failure: Unexpectedly found nil while implicitly unwrapping an optional value" but I can't see what triggers it. For leaks, I think I used |
|
ping @mfazekas |
|
|
||
| guard let mapboxMap = map.mapboxMap else { | ||
| return false | ||
| map.withMapboxMap { [weak self] _mapboxMap in |
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:
- item added to map with style A
- style removed from map
- item tries to removeFromMap so it's waits for style
- style B is added to map
- item is added to style B
- withMapboxMap is executed item removed from style B
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.
| 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 comment
The reason will be displayed to describe this comment to others. Learn more.
👍
| } | ||
|
|
||
| map.mapView.viewport.removeStatusObserver(self) | ||
| map.withMapView { _mapView in |
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.
Same as the other remove, we don't want to try to remove from other mapViewpot we've added ourselves to
| 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 comment
The 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?!
| 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 comment
The 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
| resolver(["data": NSNumber(value: result)]) | ||
| } else { | ||
| resolver(nil) | ||
| view.withMapboxMap { [weak view] _mapboxMap in |
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.
👍
| ]) | ||
| case .failure(let error): | ||
| rejecter("queryRenderedFeaturesInRect", "failed to query features", error) | ||
| map.withMapboxMap { [weak map] _mapboxMap in |
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.
👍
| rejecter( | ||
| "querySourceFeatures", | ||
| "failed to query source features: \(error.localizedDescription)", error) | ||
| map.withMapboxMap { _mapboxMap in |
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.
👍
|
@PRESIDENT810 thanks again, and sorry for taking this long. So generally there is 2 cases in the changes. |
Description
In our App, the deprecated APIs (
RNMBXMapView.mapView&RNMBXMapView.mapboxMap) cause the app to crash because rnmapbox is trying to unwrap them while they are stillnil.This PR removes those two deprecated APIs and changes all their usage to the safe
withMapView&withMapboxMapAPI calls. After this fix our app no longer crashes.Checklist
CONTRIBUTING.mdyarn generatein the root folder/exampleapp./example)Screenshot OR Video
Component to reproduce the issue you're fixing
Kinda hard since the crash is triggered by an edge case in our app and we don't know how to create a minimal reproducing example yet but after I patched this package our app no longer crashes.