Fixed
Status Update
Comments
jb...@google.com <jb...@google.com>
ap...@google.com <ap...@google.com> #2
Project: platform/frameworks/support
Branch: androidx-main
commit bf4f304e9e45d30cf34239ba705dce2a878d97a0
Author: Alex Vanyo <vanyo@google.com>
Date: Tue Mar 29 23:19:03 2022
Add SavedStateHandle.saveable property delegates
Relnote: "Add SavedStateHandle.saveable property delegates to use
property names as keys for persisting state into the SavedStateHandle"
Fixes: 225014345
Test: New tests for ./gradlew :lifecycle:lifecycle-viewmodel-compose:connectedCheck
Change-Id: I8bb86c6c636e62f89b61d8406ea1ecb8435783f6
M lifecycle/lifecycle-viewmodel-compose/api/public_plus_experimental_current.txt
M lifecycle/lifecycle-viewmodel-compose/samples/src/main/java/androidx/lifecycle/viewmodel/compose/samples/LifecycleViewModelSamples.kt
M lifecycle/lifecycle-viewmodel-compose/src/androidTest/java/androidx/lifecycle/viewmodel/compose/SavedStateHandleSaverTest.kt
M lifecycle/lifecycle-viewmodel-compose/src/main/java/androidx/lifecycle/viewmodel/compose/SavedStateHandleSaver.kt
https://android-review.googlesource.com/2048356
Branch: androidx-main
commit bf4f304e9e45d30cf34239ba705dce2a878d97a0
Author: Alex Vanyo <vanyo@google.com>
Date: Tue Mar 29 23:19:03 2022
Add SavedStateHandle.saveable property delegates
Relnote: "Add SavedStateHandle.saveable property delegates to use
property names as keys for persisting state into the SavedStateHandle"
Fixes: 225014345
Test: New tests for ./gradlew :lifecycle:lifecycle-viewmodel-compose:connectedCheck
Change-Id: I8bb86c6c636e62f89b61d8406ea1ecb8435783f6
M lifecycle/lifecycle-viewmodel-compose/api/public_plus_experimental_current.txt
M lifecycle/lifecycle-viewmodel-compose/samples/src/main/java/androidx/lifecycle/viewmodel/compose/samples/LifecycleViewModelSamples.kt
M lifecycle/lifecycle-viewmodel-compose/src/androidTest/java/androidx/lifecycle/viewmodel/compose/SavedStateHandleSaverTest.kt
M lifecycle/lifecycle-viewmodel-compose/src/main/java/androidx/lifecycle/viewmodel/compose/SavedStateHandleSaver.kt
il...@google.com <il...@google.com> #3
While this missed the deadline for the Lifecycle 2.5.0-alpha06, this change will be the next Lifecycle release after that.
Description
SavedStateHandle.saveable requires passing a key.
In the case where the value returned by
Saveable
is the only place where this value is written to and read, the exact value ofkey
doesn't really matter, so long as it is unique.Therefore, there's the possibility of using property delegates to automatically pull the name of the property to use as a key. An implementation would look something like the following:
And then usage would look like:
If b/224565154 is created, then an additional property delegate for
MutableState
could also be created, using something like the following:Usage here would then match
rememberSaveable
almost identically for simplemutableStateOf
usages: