mapbox-maps-android
mapbox-maps-android copied to clipboard
Mapbox lifecycle with Jetpack Compose
I am using Jetpack Compose for my app and it seems like recomposing causes many issues. For example, changing a layer's property works fine and then after recomposing, it does not work anymore.
Also I would like to know what is the best practices working with Mapbox and ViewModels. Should we hold the MapboxMap and MapView instances?
Related Jetpack Compose ticket
- https://github.com/mapbox/mapbox-maps-android/issues/129
I'm coming from issue: Map status not preserved in Jetpack Compose as I have the exact same issue.
Have you considered fixing this bug? Issue hasn't been updated for months and it's blocking us from migrating to the new SDK. Without doing an official Compose support, it would be nice to at least make the new SDK properly works with Compose as it was with the legacy SDK. BTW, I'm able to update layers properties and make it works even after recomposition. The only blocking issue I found is the lifecycle being broken when switching between composables.
I tried to do some digging while migrating from the legacy SDK to the new one. When I manually handle the mapbox SDK, MapView.onDestroy() is automatically fired from Mapbox SDK when I navigate to another Composable, but I'm not manually calling mapView.onDestroy().
In the legacy SDK it was working as intended, it seems to be a bug from the new SDK and how the lifecycle is handled. I don't want the Mapview to be destroyed in some conditions (for instance the home of the app is a bottom bar, and one screen is a mapView. So switching from Tabs shouldn't destroy everything)
Something to note: in a Compose only UI app appcompat isn't needed, only activity-compose is necessary.
To be honest this is kind of a deal breaker. I'm working a project that just started and jetpack compose is kind of mandatory for a new greenfield project on android. Being an app that uses a lot of map the mapbox SDK was suggested and we are still testing it out but if there is no support for compose we will have to move to another map SDK. So far I didn't see any official communication from the mapbox team. Or did I miss something?
Working on a project with Jetpack Compose and I was surprised to find out there is no support. I can only feel sad right now. Wow!
Hi all, as you may have noticed from #129, we just released our first official Jetpack Compose Extension, now available for public preview. We would greatly appreciate your feedback, preferably as separate issues in this repo with label compose. Thank you!
Closing as the lifecycle is handled correctly by the compose-extension, please refer to https://github.com/mapbox/mapbox-maps-android/tree/main/extension-compose to get started.