maplibre-react-native
maplibre-react-native copied to clipboard
Disable setting render mode if map is not fully ready
The org.maplibre.reactnative.components.location throws error if the map style is not fully ready and we try to set render mode. Crash can happen if the Map is being unmounted, but render mode is being set.
This fix is only for NativeUserLocation instance, and same fix might be appliable for other cases (LocationComponentManager.java).
Same issue was reported here https://github.com/maplibre/maplibre-native/issues/2876
Fix is to check if map style is fully ready before doing the action.
Thank you for your contribution. Could you share a minimal reproduction, so we can see how the bug occurs?
Shortest example is choosing Native render mode in the package react-native example:
On our project minimal reproduction was:
- You have screen with a component containing Map and UserLocation
- As a part of optimisation, we want to hide user location when the component is not visible on the screen
- When navigating back from that screen, we register screen changed event before component will unmount.
- Now here the magic happens: UserLocation render mode is changing, and at the same time component unmounting (map ready becoming false). When render mode is about to change, style update in mapbox is happening on non-existant map -
Attempt to invoke virtual method 'org.maplibre.android.maps.Style org.maplibre.android.maps.MapLibreMap.getStyle()' on a null object referenceis fired.
The change above ignores this change if map is not ready. I hope I explained well. If you need more info, let me know. And thank you for maintaining this package.
First of all, are you using the old or new architecture?
I'm struggling to reproduce the bug. Could you please further explain, how to trigger it with the "Follow User Location Render Mode" example? Maybe provide a video?
I also don't fully understand your use case. Why would you unmount the map and change the render mode at the same time?
Closing for missing response to my feedback. Happy to discuss further if my questions/concerns are adressed.