Google Maps Wont restoreState properly when navigating through bottom nav
See original GitHub issueEnvironment details
- library: com.google.maps.android:maps-compose:2.1.0
Steps to reproduce
- clone this repo
- add your google api key to the manifest file
- Quickly navigate between the bottom tabs and check if the maps is loaded properly
- When navigating quickly with the bottom tabs the maps wont restore its state eg. camera position, markers
Observation
The maps will load properly even if we navigate quickly on the bottom tabs when the starting route of nav host is the map to reproduce.
- Change the AnimatedNavHost start destination from
AnimatedNavHost(
navController = navController,
startDestination = Screen.Other.route
)
to
AnimatedNavHost(
navController = navController,
startDestination = Screen.Map.route
)
and it will work just fine.
Here is a sample video of the bug
Issue Analytics
- State:
- Created a year ago
- Comments:10 (5 by maintainers)
Top Results From Across the Web
Jetpack compose Google Maps does not load properly when ...
The problem is when navigating through the bottom navigation quickly. Meaning when I switch fast pages it will not load the map properly....
Read more >How to fix Maps when it crashes - Android - Google Maps Help
Find "Map - Navigate & Explore", then tap Update. Clear the app's cache & data. Start here, then finish the process on your...
Read more >Support multiple back stacks for Bottom tab navigation
The current bottom tab navigation doesn't follow the latest material ... the navigation component does not set the menu items properly for each...
Read more >Navigation | Android Developers
To add a dependency on Navigation, you must add the Google Maven ... between bottom destinations when using the Navigation Compose NavHost ....
Read more >Navigation, Saving fragment state · Issue #530 - GitHub
Hi, I'm was trying to save fragment state, Is there a suggested way to use while using Navigation component? It's like open new...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Looks like this issue happens you’re in the tab displaying the map, and quickly tap out and back in (before the crossfade animation completes). In this specific scenario, the
MapView
is in the state such that theGoogleMap
composable never left the composition (and so nodes aren’t readded) but theMapView
has been recreated (i.e. went through an ON_STOP, followed by an ON_CREATE > ON_START > ON_RESUME). I believe the fix here would be to propagate the saved instance stateBundle
across the variousMapView
lifecycle events. However, there are no hooks in theandroidx.lifecycle
library to obtain that bundle. Will try to figure out a workaround for this.Edit: saving instance state will only restore some properties of the map (like the camera’s position). Drawn objects like markers will have to be readded. The closest thing to a workaround for now is to shorten the crossfade duration to reduce the occurrence of this bug.
🎉 This issue has been resolved in version 2.2.1 🎉
The release is available on:
v2.2.1
Your semantic-release bot 📦🚀