-
Notifications
You must be signed in to change notification settings - Fork 145
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
Google Maps Wont restoreState properly when using restoreState = true while navigating. #663
Comments
@Del-S I am not a project maintainer, but I guided the implementation of #436. What I see in the video is the user clicking the Map icon to switch to the Map screen, and then clicking the Map icon again while on the Map screen, resulting in the Map no longer working. Can you explain why you think that there is a problem with GoogleMap()? What the user is doing in the video should result in a no-op. It needs to be guarded by androidx.navigation and/or user code: "user tries to go to screen, but is on screen already". Instead I see some lifecycle changes happening when I debug. I don't see how this is GoogleMap()'s problem. I see that there is a need to harden navigation-related code against lifecycle problems in user code, these issues point at some recipes: |
@bubenheimer Hi, I would agree with that if that did not happen with Deeplinking (and fast clicking in some cases) as well. I just created the easiest case to implement. Basically when you are on a screen and you navigate to it with new intent (and/or new data) it should just restore the state, if it can right, and then deliver the new data into it. But the map (or the listener) end's up in "destroyed" state even when it is on screen and should be interactible. Not sure that should ever happen. But if you say that it is "us" issue then I guess I can do nothing with that. I just can't imagine it's a good thing that the map is not usable even when on screen. 🤷 |
@Del-S What I see in the case of the workflow from the video is the GoogleMap View lifecycle ending up in CREATED state after the user clicks the map navigation button while on the Map screen; the View sees Lifecycle.Event.ON_PAUSE, then Lifecycle.Event.ON_STOP, which puts it into CREATED state. I do not see the lifecycle ending up in DESTROYED state; there is no Lifecycle.Event.ON_DESTROY. When I fast click to switch from Map screen to Main screen then Map screen while the transition animation to Main screen is ongoing I can get the GoogleMap View lifecycle temporarily stuck in CREATED state, upon re-entering the Map screen. Once I switch back to Main screen a second time after that, the GoogleMap View lifecycle goes to DESTROYED, and everything is back to normal when re-entering the GoogleMap screen the next time, the GoogleMap View is re-created in this case. The behavior in the latter case suggests to me that guarding the screen switches with lifecycle barriers would help; similar guardrails may help in the former case, too. The former case does not seem to behave for me in the manner that you describe: the lifecycle does not go to DESTROYED. Also, what I observe is the GoogleMap View behaving as desired once it actually goes to DESTROYED lifecycle state. If you have a repro for the case that actually interests you, it may help, to see what's going on in that case. It may also help you to dig more into potential problems with Navigation behaviors, as opposed to GoogleMap behaviors. I can only look at it from the perspective of what GoogleMap() sees in terms of lifecycle signals and view hierarchy changes, and its response to them. I don't see anything actionable at this point. Someone else may have other insights. |
I've looked at it once more and I see that there is more complexity involved. Will look into it some more. |
What I see now (in the case from the video) is that the LifecycleOwner changes. The View does see the ON_DESTROY lifecycle event from the old lifecycle owner, and around the same time a new LifecycleOwner is installed on the composition. The View is not detached from the hierarchy, and the composition is not disposed. Someone with better knowledge of androidx.navigation needs to look at this:
If necessary, I think it could be worked around in different ways. For example, one could observe changes to LifecycleOwner from the composition, and cleanly recreate AndroidView in this case. Essentially |
Ah right it makes sense that the LifecycleOwner changes that seems to be the main "problem". The repo is not a proper way of using bottom navigation -> I agree that the secondary click should result with a no-op but still there are cases when you are navigating to the screen for which you already have a We wanted to allow:
Hmmm I'm thinking about Side-note: during the holidays I am planning to refactor navigation in the app so I might try/find some ways to make this work. :) Anyway thanks for the help. 👍 |
@Del-S for the time being you could try applying the |
@Del-S the other workaround that you are suggesting may be feasible. I did not mention it, because the exact desired implementation and behavior at the time of View seeing ON_DESTROY and lifecycleOwner being replaced seem a little unclear, and it will take a bit of extra hacking to make it work, you could try it in a private fork. As my other workaround idea wouldn't pan out, this may be worth pursuing for you for now, if you do not find a different Navigation approach. You could possibly override setTag() on the MapView, too, and wait for a LifecyleOwner tag to be set. Because this looks somewhat murky, I think an actual solution should be deferred to AndroidView() and/or Navigation; like I said, all Views in AndroidView would share this problem, not just MapView. If it is a valid problem. |
Ok, great. Thanks for the help. 👍 |
Environment details
Steps to reproduce
Observation
Lifecycle observer goes to
ON_DESTROY
and never makes it's way toON_RESUME
, which keeps the map in "destroyed" state and it is not usable (cannot scroll, zoom or anything else).While not using
restoreState
orsaveState
set totrue
the map works fine. Also when downgrading compose map library to6.0.0
it works properly.It might be related to already resolved issue: #112. But due to refactor in #436 it probably happens again. Not really connected to animations this time. It is probably connected to the restoreState.
Sample video of the issue.
The text was updated successfully, but these errors were encountered: