Fixed
Status Update
Comments
il...@google.com <il...@google.com>
cl...@google.com <cl...@google.com> #2
Bug happens because when we navigate from one screen to another with configuration change, the NavHost
is destroyed and the record of transitioning entries are lost. This means the transitioning outgoing entry that would be marked as complete when navigation completes does not get marked complete. And clear viewmodel is part of the mark complete work.
ap...@google.com <ap...@google.com> #3
Project: platform/frameworks/support
Branch: androidx-main
commit 690f94c30462a839c39ef5298ec263b67a33557e
Author: Clara Fok <clarafok@google.com>
Date: Tue Oct 10 13:38:34 2023
Fix ViewModel not cleared after pop
When an entry is popped followed by a configuration change, the list of transitioning entries is lost and the outgoing entry is not marked complete. As a result, the ViewModel is also not cleared.
Now we ensure to mark outgoing entries as complete when a NavHost goes through config change (when it is disposed).
Test: ./gradlew navigation:navigation-compose:cC
Bug: 298164648
Relnote: "When an entry is popped followed by a configuration change, the entry's ViewModel will now be cleared properly if saveState is false."
Change-Id: Idf242239ceeb731c3375ef507a2cc854d85743c7
M navigation/navigation-compose/src/androidTest/java/androidx/navigation/compose/NavHostTest.kt
M navigation/navigation-compose/src/main/java/androidx/navigation/compose/NavHost.kt
https://android-review.googlesource.com/2780876
Branch: androidx-main
commit 690f94c30462a839c39ef5298ec263b67a33557e
Author: Clara Fok <clarafok@google.com>
Date: Tue Oct 10 13:38:34 2023
Fix ViewModel not cleared after pop
When an entry is popped followed by a configuration change, the list of transitioning entries is lost and the outgoing entry is not marked complete. As a result, the ViewModel is also not cleared.
Now we ensure to mark outgoing entries as complete when a NavHost goes through config change (when it is disposed).
Test: ./gradlew navigation:navigation-compose:cC
Bug: 298164648
Relnote: "When an entry is popped followed by a configuration change, the entry's ViewModel will now be cleared properly if saveState is false."
Change-Id: Idf242239ceeb731c3375ef507a2cc854d85743c7
M navigation/navigation-compose/src/androidTest/java/androidx/navigation/compose/NavHostTest.kt
M navigation/navigation-compose/src/main/java/androidx/navigation/compose/NavHost.kt
cl...@google.com <cl...@google.com> #4
Fixed internally, available in navigation 2.7.5
na...@google.com <na...@google.com> #5
The following release(s) address this bug.It is possible this bug has only been partially addressed:
androidx.navigation:navigation-compose:2.7.5
na...@google.com <na...@google.com> #6
The following release(s) address this bug.It is possible this bug has only been partially addressed:
androidx.navigation:navigation-compose:2.8.0-alpha01
Description
Component used: Navigation
Version used:
If this is a bug in the library, we would appreciate if you could attach:
Issue:
Hi, I just encountered a weird behaviour which can be reproduced every time. My setup looks like this, Single Activity with Compose Navigation, some screens are locked to portrait orientation, some can be used in every orientation, e.g. to display images or videos.
Orientation is set like this while navigating:
ScreenA
is locked to portrait,ScreenB
can be used in every orientation. IfScreenB
is used in landscape mode, while navigating back an orientation change is requested which leads to activity recreation. I think because of the activity recreationScreenBViewModel.onCleared
is not called...How to reproduce?
ScreenBViewModel.onCleared
is not calledYou can just search the logs for "ScreenBViewModel", an info gets logged for init and onCleared of
ScreenBViewModel
. IfScreenB
doesn't change its orientationonCleared
is called as expected.Expected behaviour:
For step 5
ScreenBViewModel.onCleared
is calledDo you have any recommendations for a temporary workaround or any suggestions how orientation changes can be forced without losing the
onCleared
call?Let me know if you need more info.
Best regards ✌️