Fixed
Status Update
Comments
so...@google.com <so...@google.com>
an...@google.com <an...@google.com> #2
Hey! Could you please let us know a bit more on how you want to use it from inside composables?
ma...@n26.com <ma...@n26.com> #3
Sure!
I currently use ViewModel + SavedState. To create a ViewModel with a custom constructor, I need to implement SavedStateHandle
. However, AbstractSavedStateViewModelFactory
has a default constructor with the following parameters: (SavedStateRegistryOwner owner, Bundle defaultArgs)
.
Note that
Right now, I'm using an AmbientLifecycleOwner
and hard casting it to SavedStateRegistryOwner
but this is a fragile solution as I have no assurance that the LifecycleOwner
implements SavedStateRegistryOwner
and this will, most likely, result in a Runtime Exception.
an...@google.com <an...@google.com> #4
Thanks for the feature request. It will be available in the next alpha release
ap...@google.com <ap...@google.com> #5
Project: platform/frameworks/support
Branch: androidx-main
commit bf453a62da17ba70ea71245a88b50b9dff5ca429
Author: Andrey Kulikov <andreykulikov@google.com>
Date: Thu Jan 14 01:02:23 2021
Introduce AmbientSavedStateRegistryOwner
Fixes: 176756365
Relnote: AmbientSavedStateRegistryOwner was added similarly to already existing AmbientLifecycleOwner and AmbientViewModelStoreOwner
Test: new tests
Change-Id: I9a3e829262e30c950ac07dfc4f89eeda632a729f
M compose/ui/ui/api/current.txt
M compose/ui/ui/api/public_plus_experimental_current.txt
M compose/ui/ui/api/restricted_current.txt
M compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/owners/LifecycleOwnerInAppCompatActivityTest.kt
M compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/owners/LifecycleOwnerInComponentActivityTest.kt
M compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/owners/LifecycleOwnerInFragmentTest.kt
M compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/owners/SavedStateRegistryOwnerInAppCompatActivityTest.kt
M compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/owners/SavedStateRegistryOwnerInComponentActivityTest.kt
M compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/owners/SavedStateRegistryOwnerInFragmentTest.kt
M compose/ui/ui/src/androidMain/kotlin/androidx/compose/ui/platform/AndroidAmbients.kt
https://android-review.googlesource.com/1550025
Branch: androidx-main
commit bf453a62da17ba70ea71245a88b50b9dff5ca429
Author: Andrey Kulikov <andreykulikov@google.com>
Date: Thu Jan 14 01:02:23 2021
Introduce AmbientSavedStateRegistryOwner
Fixes: 176756365
Relnote: AmbientSavedStateRegistryOwner was added similarly to already existing AmbientLifecycleOwner and AmbientViewModelStoreOwner
Test: new tests
Change-Id: I9a3e829262e30c950ac07dfc4f89eeda632a729f
M compose/ui/ui/api/current.txt
M compose/ui/ui/api/public_plus_experimental_current.txt
M compose/ui/ui/api/restricted_current.txt
M compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/owners/LifecycleOwnerInAppCompatActivityTest.kt
M compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/owners/LifecycleOwnerInComponentActivityTest.kt
M compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/owners/LifecycleOwnerInFragmentTest.kt
M compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/owners/SavedStateRegistryOwnerInAppCompatActivityTest.kt
M compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/owners/SavedStateRegistryOwnerInComponentActivityTest.kt
M compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/owners/SavedStateRegistryOwnerInFragmentTest.kt
M compose/ui/ui/src/androidMain/kotlin/androidx/compose/ui/platform/AndroidAmbients.kt
Description
Android Studio Build: `#AI-202.7319.50.2031.7019041, built on December 8, 2020`
Steps to Reproduce:
1. Create a `@Composable` function;
2. Try to access the current `Ambient*` objects;
3. Verify there's currently no `Ambient` for `SavedStateRegistryOwner`.
Given that there's already one `Ambient` for `LifecycleOwner` and `ViewModelStoreOwner`, it would be useful to have one for `SavedStateRegistryOwner` as well as we can't use `AmbientUiSavedStateOwner` as a replacement for current Android APIs neither.