Fixed
Status Update
Comments
jb...@google.com <jb...@google.com>
cl...@google.com <cl...@google.com> #2
Fixed internally and will be available in navigation 2.8.0-alpha02
.
ap...@google.com <ap...@google.com> #3
Project: platform/frameworks/support
Branch: androidx-main
commit db700c8e99e354fbc35cf4bbd5f6f811deb587a0
Author: Clara Fok <clarafok@google.com>
Date: Wed Jan 31 16:19:02 2024
Fix NavGraph ViewModel destroyed too soon
The NavGraph entry when popped gets stored into savedState bundle but the entry's ViewModel is cleared from the ViewModelStore because we did not track the entry's saveState. We used to only track the saveState on FragmentNavigator and ComposeNavigator. Now whenever we pop, the base NavControllerNavigatorState would add the entry to map of saveState so we don't destroy the VM prematurely.
Test: ./gradlew navigation:navigation-runtime:cC
Bug: 317581849
Change-Id: Ib6bb7d1d2f1af928a23a2647b1800eb4bb37d39d
M navigation/navigation-runtime/src/androidTest/java/androidx/navigation/NavControllerTest.kt
M navigation/navigation-runtime/src/main/java/androidx/navigation/NavController.kt
https://android-review.googlesource.com/2942087
Branch: androidx-main
commit db700c8e99e354fbc35cf4bbd5f6f811deb587a0
Author: Clara Fok <clarafok@google.com>
Date: Wed Jan 31 16:19:02 2024
Fix NavGraph ViewModel destroyed too soon
The NavGraph entry when popped gets stored into savedState bundle but the entry's ViewModel is cleared from the ViewModelStore because we did not track the entry's saveState. We used to only track the saveState on FragmentNavigator and ComposeNavigator. Now whenever we pop, the base NavControllerNavigatorState would add the entry to map of saveState so we don't destroy the VM prematurely.
Test: ./gradlew navigation:navigation-runtime:cC
Bug: 317581849
Change-Id: Ib6bb7d1d2f1af928a23a2647b1800eb4bb37d39d
M navigation/navigation-runtime/src/androidTest/java/androidx/navigation/NavControllerTest.kt
M navigation/navigation-runtime/src/main/java/androidx/navigation/NavController.kt
jb...@google.com <jb...@google.com> #4
This is actually part of Navigation 2.8.0-alpha03
.
pr...@google.com <pr...@google.com> #5
The following release(s) address this bug.It is possible this bug has only been partially addressed:
androidx.navigation:navigation-runtime:2.8.0-alpha03
Description
Component used: Navigation Version used: 2.7.6 Devices/Android versions reproduced on: any devices
When using
saveState
andrestoreState
in Nested Navigation, the ViewModel whose parent BackStackEntry is Owner is not restored.I have attached the project to reproduce, so please check it.