question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Google Maps Wont restoreState properly when navigating through bottom nav

See original GitHub issue

Environment details

  1. library: com.google.maps.android:maps-compose:2.1.0

Steps to reproduce

  1. clone this repo
  2. add your google api key to the manifest file
  3. Quickly navigate between the bottom tabs and check if the maps is loaded properly
  4. 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.

  1. 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:closed
  • Created a year ago
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

3reactions
arriolaccommented, Jun 7, 2022

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 the GoogleMap composable never left the composition (and so nodes aren’t readded) but the MapView 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 state Bundle across the various MapView lifecycle events. However, there are no hooks in the androidx.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.

1reaction
googlemaps-botcommented, Jun 7, 2022

🎉 This issue has been resolved in version 2.2.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found