Merge "Rename UiSavedStateRegistry to SaveableStateRegistry" into androidx-main
diff --git a/compose/runtime/runtime-saveable/api/current.txt b/compose/runtime/runtime-saveable/api/current.txt
index 89f9634..bb252f1 100644
--- a/compose/runtime/runtime-saveable/api/current.txt
+++ b/compose/runtime/runtime-saveable/api/current.txt
@@ -22,6 +22,19 @@
method @androidx.compose.runtime.Composable public static androidx.compose.runtime.saveable.SaveableStateHolder rememberSaveableStateHolder();
}
+ public interface SaveableStateRegistry {
+ method public boolean canBeSaved(Object value);
+ method public Object? consumeRestored(String key);
+ method public java.util.Map<java.lang.String,java.util.List<java.lang.Object>> performSave();
+ method public void registerProvider(String key, kotlin.jvm.functions.Function0<?> valueProvider);
+ method public void unregisterProvider(String key, kotlin.jvm.functions.Function0<?> valueProvider);
+ }
+
+ public final class SaveableStateRegistryKt {
+ method public static androidx.compose.runtime.saveable.SaveableStateRegistry SaveableStateRegistry(java.util.Map<java.lang.String,? extends java.util.List<?>>? restoredValues, kotlin.jvm.functions.Function1<java.lang.Object,java.lang.Boolean> canBeSaved);
+ method public static androidx.compose.runtime.ProvidableAmbient<androidx.compose.runtime.saveable.SaveableStateRegistry> getAmbientSaveableStateRegistry();
+ }
+
public interface Saver<Original, Saveable> {
method public Original? restore(Saveable value);
method public Saveable? save(androidx.compose.runtime.saveable.SaverScope, Original? value);
@@ -42,7 +55,9 @@
public final class DeprecatedKt {
method @Deprecated public static <Original, Saveable> androidx.compose.runtime.savedinstancestate.Saver<Original,Saveable> Saver(kotlin.jvm.functions.Function2<? super androidx.compose.runtime.savedinstancestate.SaverScope,? super Original,? extends Saveable> save, kotlin.jvm.functions.Function1<? super Saveable,? extends Original> restore);
+ method @Deprecated public static androidx.compose.runtime.savedinstancestate.UiSavedStateRegistry UiSavedStateRegistry(java.util.Map<java.lang.String,? extends java.util.List<?>>? restoredValues, kotlin.jvm.functions.Function1<java.lang.Object,java.lang.Boolean> canBeSaved);
method @Deprecated public static <T> androidx.compose.runtime.savedinstancestate.Saver<T,java.lang.Object> autoSaver();
+ method @Deprecated public static androidx.compose.runtime.ProvidableAmbient<androidx.compose.runtime.savedinstancestate.UiSavedStateRegistry> getAmbientUiSavedStateRegistry();
method @Deprecated public static <Original, Saveable> androidx.compose.runtime.savedinstancestate.Saver<Original,?> listSaver(kotlin.jvm.functions.Function2<? super androidx.compose.runtime.savedinstancestate.SaverScope,? super Original,? extends java.util.List<? extends Saveable>> save, kotlin.jvm.functions.Function1<? super java.util.List<? extends Saveable>,? extends Original> restore);
method @Deprecated public static <T> androidx.compose.runtime.savedinstancestate.Saver<T,?> mapSaver(kotlin.jvm.functions.Function2<? super androidx.compose.runtime.savedinstancestate.SaverScope,? super T,? extends java.util.Map<java.lang.String,?>> save, kotlin.jvm.functions.Function1<? super java.util.Map<java.lang.String,?>,? extends T> restore);
method @Deprecated @androidx.compose.runtime.Composable public static <T> androidx.compose.runtime.savedinstancestate.RestorableStateHolder<T> rememberRestorableStateHolder();
@@ -65,18 +80,7 @@
@Deprecated public interface SaverScope extends androidx.compose.runtime.saveable.SaverScope {
}
- public interface UiSavedStateRegistry {
- method public boolean canBeSaved(Object value);
- method public Object? consumeRestored(String key);
- method public java.util.Map<java.lang.String,java.util.List<java.lang.Object>> performSave();
- method public void registerProvider(String key, kotlin.jvm.functions.Function0<?> valueProvider);
- method public void unregisterProvider(String key, kotlin.jvm.functions.Function0<?> valueProvider);
- }
-
- public final class UiSavedStateRegistryKt {
- method public static androidx.compose.runtime.savedinstancestate.UiSavedStateRegistry UiSavedStateRegistry(java.util.Map<java.lang.String,? extends java.util.List<?>>? restoredValues, kotlin.jvm.functions.Function1<java.lang.Object,java.lang.Boolean> canBeSaved);
- method public static androidx.compose.runtime.ProvidableAmbient<androidx.compose.runtime.savedinstancestate.UiSavedStateRegistry> getAmbientUiSavedStateRegistry();
- method @Deprecated public static androidx.compose.runtime.ProvidableAmbient<androidx.compose.runtime.savedinstancestate.UiSavedStateRegistry>! getUiSavedStateRegistryAmbient();
+ @Deprecated public interface UiSavedStateRegistry extends androidx.compose.runtime.saveable.SaveableStateRegistry {
}
}
diff --git a/compose/runtime/runtime-saveable/api/public_plus_experimental_current.txt b/compose/runtime/runtime-saveable/api/public_plus_experimental_current.txt
index 89f9634..bb252f1 100644
--- a/compose/runtime/runtime-saveable/api/public_plus_experimental_current.txt
+++ b/compose/runtime/runtime-saveable/api/public_plus_experimental_current.txt
@@ -22,6 +22,19 @@
method @androidx.compose.runtime.Composable public static androidx.compose.runtime.saveable.SaveableStateHolder rememberSaveableStateHolder();
}
+ public interface SaveableStateRegistry {
+ method public boolean canBeSaved(Object value);
+ method public Object? consumeRestored(String key);
+ method public java.util.Map<java.lang.String,java.util.List<java.lang.Object>> performSave();
+ method public void registerProvider(String key, kotlin.jvm.functions.Function0<?> valueProvider);
+ method public void unregisterProvider(String key, kotlin.jvm.functions.Function0<?> valueProvider);
+ }
+
+ public final class SaveableStateRegistryKt {
+ method public static androidx.compose.runtime.saveable.SaveableStateRegistry SaveableStateRegistry(java.util.Map<java.lang.String,? extends java.util.List<?>>? restoredValues, kotlin.jvm.functions.Function1<java.lang.Object,java.lang.Boolean> canBeSaved);
+ method public static androidx.compose.runtime.ProvidableAmbient<androidx.compose.runtime.saveable.SaveableStateRegistry> getAmbientSaveableStateRegistry();
+ }
+
public interface Saver<Original, Saveable> {
method public Original? restore(Saveable value);
method public Saveable? save(androidx.compose.runtime.saveable.SaverScope, Original? value);
@@ -42,7 +55,9 @@
public final class DeprecatedKt {
method @Deprecated public static <Original, Saveable> androidx.compose.runtime.savedinstancestate.Saver<Original,Saveable> Saver(kotlin.jvm.functions.Function2<? super androidx.compose.runtime.savedinstancestate.SaverScope,? super Original,? extends Saveable> save, kotlin.jvm.functions.Function1<? super Saveable,? extends Original> restore);
+ method @Deprecated public static androidx.compose.runtime.savedinstancestate.UiSavedStateRegistry UiSavedStateRegistry(java.util.Map<java.lang.String,? extends java.util.List<?>>? restoredValues, kotlin.jvm.functions.Function1<java.lang.Object,java.lang.Boolean> canBeSaved);
method @Deprecated public static <T> androidx.compose.runtime.savedinstancestate.Saver<T,java.lang.Object> autoSaver();
+ method @Deprecated public static androidx.compose.runtime.ProvidableAmbient<androidx.compose.runtime.savedinstancestate.UiSavedStateRegistry> getAmbientUiSavedStateRegistry();
method @Deprecated public static <Original, Saveable> androidx.compose.runtime.savedinstancestate.Saver<Original,?> listSaver(kotlin.jvm.functions.Function2<? super androidx.compose.runtime.savedinstancestate.SaverScope,? super Original,? extends java.util.List<? extends Saveable>> save, kotlin.jvm.functions.Function1<? super java.util.List<? extends Saveable>,? extends Original> restore);
method @Deprecated public static <T> androidx.compose.runtime.savedinstancestate.Saver<T,?> mapSaver(kotlin.jvm.functions.Function2<? super androidx.compose.runtime.savedinstancestate.SaverScope,? super T,? extends java.util.Map<java.lang.String,?>> save, kotlin.jvm.functions.Function1<? super java.util.Map<java.lang.String,?>,? extends T> restore);
method @Deprecated @androidx.compose.runtime.Composable public static <T> androidx.compose.runtime.savedinstancestate.RestorableStateHolder<T> rememberRestorableStateHolder();
@@ -65,18 +80,7 @@
@Deprecated public interface SaverScope extends androidx.compose.runtime.saveable.SaverScope {
}
- public interface UiSavedStateRegistry {
- method public boolean canBeSaved(Object value);
- method public Object? consumeRestored(String key);
- method public java.util.Map<java.lang.String,java.util.List<java.lang.Object>> performSave();
- method public void registerProvider(String key, kotlin.jvm.functions.Function0<?> valueProvider);
- method public void unregisterProvider(String key, kotlin.jvm.functions.Function0<?> valueProvider);
- }
-
- public final class UiSavedStateRegistryKt {
- method public static androidx.compose.runtime.savedinstancestate.UiSavedStateRegistry UiSavedStateRegistry(java.util.Map<java.lang.String,? extends java.util.List<?>>? restoredValues, kotlin.jvm.functions.Function1<java.lang.Object,java.lang.Boolean> canBeSaved);
- method public static androidx.compose.runtime.ProvidableAmbient<androidx.compose.runtime.savedinstancestate.UiSavedStateRegistry> getAmbientUiSavedStateRegistry();
- method @Deprecated public static androidx.compose.runtime.ProvidableAmbient<androidx.compose.runtime.savedinstancestate.UiSavedStateRegistry>! getUiSavedStateRegistryAmbient();
+ @Deprecated public interface UiSavedStateRegistry extends androidx.compose.runtime.saveable.SaveableStateRegistry {
}
}
diff --git a/compose/runtime/runtime-saveable/api/restricted_current.txt b/compose/runtime/runtime-saveable/api/restricted_current.txt
index 89f9634..bb252f1 100644
--- a/compose/runtime/runtime-saveable/api/restricted_current.txt
+++ b/compose/runtime/runtime-saveable/api/restricted_current.txt
@@ -22,6 +22,19 @@
method @androidx.compose.runtime.Composable public static androidx.compose.runtime.saveable.SaveableStateHolder rememberSaveableStateHolder();
}
+ public interface SaveableStateRegistry {
+ method public boolean canBeSaved(Object value);
+ method public Object? consumeRestored(String key);
+ method public java.util.Map<java.lang.String,java.util.List<java.lang.Object>> performSave();
+ method public void registerProvider(String key, kotlin.jvm.functions.Function0<?> valueProvider);
+ method public void unregisterProvider(String key, kotlin.jvm.functions.Function0<?> valueProvider);
+ }
+
+ public final class SaveableStateRegistryKt {
+ method public static androidx.compose.runtime.saveable.SaveableStateRegistry SaveableStateRegistry(java.util.Map<java.lang.String,? extends java.util.List<?>>? restoredValues, kotlin.jvm.functions.Function1<java.lang.Object,java.lang.Boolean> canBeSaved);
+ method public static androidx.compose.runtime.ProvidableAmbient<androidx.compose.runtime.saveable.SaveableStateRegistry> getAmbientSaveableStateRegistry();
+ }
+
public interface Saver<Original, Saveable> {
method public Original? restore(Saveable value);
method public Saveable? save(androidx.compose.runtime.saveable.SaverScope, Original? value);
@@ -42,7 +55,9 @@
public final class DeprecatedKt {
method @Deprecated public static <Original, Saveable> androidx.compose.runtime.savedinstancestate.Saver<Original,Saveable> Saver(kotlin.jvm.functions.Function2<? super androidx.compose.runtime.savedinstancestate.SaverScope,? super Original,? extends Saveable> save, kotlin.jvm.functions.Function1<? super Saveable,? extends Original> restore);
+ method @Deprecated public static androidx.compose.runtime.savedinstancestate.UiSavedStateRegistry UiSavedStateRegistry(java.util.Map<java.lang.String,? extends java.util.List<?>>? restoredValues, kotlin.jvm.functions.Function1<java.lang.Object,java.lang.Boolean> canBeSaved);
method @Deprecated public static <T> androidx.compose.runtime.savedinstancestate.Saver<T,java.lang.Object> autoSaver();
+ method @Deprecated public static androidx.compose.runtime.ProvidableAmbient<androidx.compose.runtime.savedinstancestate.UiSavedStateRegistry> getAmbientUiSavedStateRegistry();
method @Deprecated public static <Original, Saveable> androidx.compose.runtime.savedinstancestate.Saver<Original,?> listSaver(kotlin.jvm.functions.Function2<? super androidx.compose.runtime.savedinstancestate.SaverScope,? super Original,? extends java.util.List<? extends Saveable>> save, kotlin.jvm.functions.Function1<? super java.util.List<? extends Saveable>,? extends Original> restore);
method @Deprecated public static <T> androidx.compose.runtime.savedinstancestate.Saver<T,?> mapSaver(kotlin.jvm.functions.Function2<? super androidx.compose.runtime.savedinstancestate.SaverScope,? super T,? extends java.util.Map<java.lang.String,?>> save, kotlin.jvm.functions.Function1<? super java.util.Map<java.lang.String,?>,? extends T> restore);
method @Deprecated @androidx.compose.runtime.Composable public static <T> androidx.compose.runtime.savedinstancestate.RestorableStateHolder<T> rememberRestorableStateHolder();
@@ -65,18 +80,7 @@
@Deprecated public interface SaverScope extends androidx.compose.runtime.saveable.SaverScope {
}
- public interface UiSavedStateRegistry {
- method public boolean canBeSaved(Object value);
- method public Object? consumeRestored(String key);
- method public java.util.Map<java.lang.String,java.util.List<java.lang.Object>> performSave();
- method public void registerProvider(String key, kotlin.jvm.functions.Function0<?> valueProvider);
- method public void unregisterProvider(String key, kotlin.jvm.functions.Function0<?> valueProvider);
- }
-
- public final class UiSavedStateRegistryKt {
- method public static androidx.compose.runtime.savedinstancestate.UiSavedStateRegistry UiSavedStateRegistry(java.util.Map<java.lang.String,? extends java.util.List<?>>? restoredValues, kotlin.jvm.functions.Function1<java.lang.Object,java.lang.Boolean> canBeSaved);
- method public static androidx.compose.runtime.ProvidableAmbient<androidx.compose.runtime.savedinstancestate.UiSavedStateRegistry> getAmbientUiSavedStateRegistry();
- method @Deprecated public static androidx.compose.runtime.ProvidableAmbient<androidx.compose.runtime.savedinstancestate.UiSavedStateRegistry>! getUiSavedStateRegistryAmbient();
+ @Deprecated public interface UiSavedStateRegistry extends androidx.compose.runtime.saveable.SaveableStateRegistry {
}
}
diff --git a/compose/runtime/runtime-saveable/src/androidAndroidTest/kotlin/androidx/compose/runtime/saveable/RememberSaveableTest.kt b/compose/runtime/runtime-saveable/src/androidAndroidTest/kotlin/androidx/compose/runtime/saveable/RememberSaveableTest.kt
index 9eef95a..706b0e3 100644
--- a/compose/runtime/runtime-saveable/src/androidAndroidTest/kotlin/androidx/compose/runtime/saveable/RememberSaveableTest.kt
+++ b/compose/runtime/runtime-saveable/src/androidAndroidTest/kotlin/androidx/compose/runtime/saveable/RememberSaveableTest.kt
@@ -20,8 +20,6 @@
import androidx.compose.runtime.Providers
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
-import androidx.compose.runtime.savedinstancestate.AmbientUiSavedStateRegistry
-import androidx.compose.runtime.savedinstancestate.UiSavedStateRegistry
import androidx.compose.runtime.setValue
import androidx.compose.ui.test.junit4.StateRestorationTester
import androidx.compose.ui.test.junit4.createComposeRule
@@ -166,7 +164,7 @@
@Test
fun unregistersFromPrevProviderAndRegistersToTheNewOne() {
var unregisterCalledForKey: String? = null
- var registryFactory by mutableStateOf<(UiSavedStateRegistry) -> UiSavedStateRegistry>(
+ var registryFactory by mutableStateOf<(SaveableStateRegistry) -> SaveableStateRegistry>(
value = {
object : DelegateRegistry(it) {
override fun unregisterProvider(key: String, valueProvider: () -> Any?) {
@@ -352,14 +350,14 @@
@Composable
private fun WrapRegistry(
- wrap: @Composable (UiSavedStateRegistry) -> UiSavedStateRegistry,
+ wrap: @Composable (SaveableStateRegistry) -> SaveableStateRegistry,
content: @Composable () -> Unit
) {
Providers(
- AmbientUiSavedStateRegistry provides wrap(AmbientUiSavedStateRegistry.current!!),
+ AmbientSaveableStateRegistry provides wrap(AmbientSaveableStateRegistry.current!!),
content = content
)
}
-private open class DelegateRegistry(original: UiSavedStateRegistry) :
- UiSavedStateRegistry by original
\ No newline at end of file
+private open class DelegateRegistry(original: SaveableStateRegistry) :
+ SaveableStateRegistry by original
\ No newline at end of file
diff --git a/compose/runtime/runtime-saveable/src/commonMain/kotlin/androidx/compose/runtime/saveable/ListSaver.kt b/compose/runtime/runtime-saveable/src/commonMain/kotlin/androidx/compose/runtime/saveable/ListSaver.kt
index d3b7388..149d147 100644
--- a/compose/runtime/runtime-saveable/src/commonMain/kotlin/androidx/compose/runtime/saveable/ListSaver.kt
+++ b/compose/runtime/runtime-saveable/src/commonMain/kotlin/androidx/compose/runtime/saveable/ListSaver.kt
@@ -20,7 +20,7 @@
* The [Saver] implementation which allows to represent your [Original] class as a list of
* [Saveable] values.
*
- * What types can be saved is defined by [UiSavedStateRegistry], by default everything which can
+ * What types can be saved is defined by [SaveableStateRegistry], by default everything which can
* be stored in the Bundle class can be saved.
*
* You can use it as a parameter for [savedInstanceState] or [rememberSaveable].
diff --git a/compose/runtime/runtime-saveable/src/commonMain/kotlin/androidx/compose/runtime/saveable/MapSaver.kt b/compose/runtime/runtime-saveable/src/commonMain/kotlin/androidx/compose/runtime/saveable/MapSaver.kt
index acc3763..9c7c2f1 100644
--- a/compose/runtime/runtime-saveable/src/commonMain/kotlin/androidx/compose/runtime/saveable/MapSaver.kt
+++ b/compose/runtime/runtime-saveable/src/commonMain/kotlin/androidx/compose/runtime/saveable/MapSaver.kt
@@ -20,7 +20,7 @@
* The [Saver] implementation which allows to represent your class as a map of values which can
* be saved individually.
*
- * What types can be saved is defined by [UiSavedStateRegistry], by default everything which can
+ * What types can be saved is defined by [SaveableStateRegistry], by default everything which can
* be stored in the Bundle class can be saved.
*
* You can use it as a parameter for [savedInstanceState] or [rememberSaveable].
diff --git a/compose/runtime/runtime-saveable/src/commonMain/kotlin/androidx/compose/runtime/saveable/RememberSaveable.kt b/compose/runtime/runtime-saveable/src/commonMain/kotlin/androidx/compose/runtime/saveable/RememberSaveable.kt
index de83acc..22f3585 100644
--- a/compose/runtime/runtime-saveable/src/commonMain/kotlin/androidx/compose/runtime/saveable/RememberSaveable.kt
+++ b/compose/runtime/runtime-saveable/src/commonMain/kotlin/androidx/compose/runtime/saveable/RememberSaveable.kt
@@ -22,8 +22,6 @@
import androidx.compose.runtime.currentCompositeKeyHash
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
-import androidx.compose.runtime.savedinstancestate.AmbientUiSavedStateRegistry
-import androidx.compose.runtime.savedinstancestate.UiSavedStateRegistry
/**
* Remember the value produced by [init].
@@ -68,7 +66,7 @@
@Suppress("UNCHECKED_CAST")
(saver as Saver<T, Any>)
- val registry = AmbientUiSavedStateRegistry.current
+ val registry = AmbientSaveableStateRegistry.current
// value is restored using the registry or created via [init] lambda
val value = remember(*inputs) {
// TODO not restore when the input values changed (use hashKeys?) b/152014032
@@ -100,7 +98,7 @@
return value
}
-private fun UiSavedStateRegistry.requireCanBeSaved(value: Any?) {
+private fun SaveableStateRegistry.requireCanBeSaved(value: Any?) {
if (value != null && !canBeSaved(value)) {
throw IllegalArgumentException(
if (value is MutableState<*>) {
diff --git a/compose/runtime/runtime-saveable/src/commonMain/kotlin/androidx/compose/runtime/saveable/SaveableStateHolder.kt b/compose/runtime/runtime-saveable/src/commonMain/kotlin/androidx/compose/runtime/saveable/SaveableStateHolder.kt
index ef4a926..7f8cdcd 100644
--- a/compose/runtime/runtime-saveable/src/commonMain/kotlin/androidx/compose/runtime/saveable/SaveableStateHolder.kt
+++ b/compose/runtime/runtime-saveable/src/commonMain/kotlin/androidx/compose/runtime/saveable/SaveableStateHolder.kt
@@ -22,8 +22,6 @@
import androidx.compose.runtime.Providers
import androidx.compose.runtime.key
import androidx.compose.runtime.remember
-import androidx.compose.runtime.savedinstancestate.AmbientUiSavedStateRegistry
-import androidx.compose.runtime.savedinstancestate.UiSavedStateRegistry
/**
* Allows to save the state defined with [savedInstanceState] and [rememberSaveable]
@@ -66,28 +64,28 @@
) {
SaveableStateHolderImpl()
}.apply {
- parentSavedStateRegistry = AmbientUiSavedStateRegistry.current
+ parentSaveableStateRegistry = AmbientSaveableStateRegistry.current
}
private class SaveableStateHolderImpl(
private val savedStates: MutableMap<Any, Map<String, List<Any?>>> = mutableMapOf()
) : SaveableStateHolder {
private val registryHolders = mutableMapOf<Any, RegistryHolder>()
- var parentSavedStateRegistry: UiSavedStateRegistry? = null
+ var parentSaveableStateRegistry: SaveableStateRegistry? = null
@OptIn(ExperimentalComposeApi::class)
@Composable
override fun SaveableStateProvider(key: Any, content: @Composable () -> Unit) {
key(key) {
val registryHolder = remember {
- require(parentSavedStateRegistry?.canBeSaved(key) ?: true) {
+ require(parentSaveableStateRegistry?.canBeSaved(key) ?: true) {
"Type of the key used for withRestorableState is not supported. On Android " +
"you can only use types which can be stored inside the Bundle."
}
RegistryHolder(key)
}
Providers(
- AmbientUiSavedStateRegistry provides registryHolder.registry,
+ AmbientSaveableStateRegistry provides registryHolder.registry,
content = content
)
DisposableEffect(key) {
@@ -121,8 +119,8 @@
val key: Any
) {
var shouldSave = true
- val registry: UiSavedStateRegistry = UiSavedStateRegistry(savedStates[key]) {
- parentSavedStateRegistry?.canBeSaved(it) ?: true
+ val registry: SaveableStateRegistry = SaveableStateRegistry(savedStates[key]) {
+ parentSaveableStateRegistry?.canBeSaved(it) ?: true
}
fun saveTo(map: MutableMap<Any, Map<String, List<Any?>>>) {
diff --git a/compose/runtime/runtime-saveable/src/commonMain/kotlin/androidx/compose/runtime/savedinstancestate/UiSavedStateRegistry.kt b/compose/runtime/runtime-saveable/src/commonMain/kotlin/androidx/compose/runtime/saveable/SaveableStateRegistry.kt
similarity index 86%
rename from compose/runtime/runtime-saveable/src/commonMain/kotlin/androidx/compose/runtime/savedinstancestate/UiSavedStateRegistry.kt
rename to compose/runtime/runtime-saveable/src/commonMain/kotlin/androidx/compose/runtime/saveable/SaveableStateRegistry.kt
index b27176a..4a971f5 100644
--- a/compose/runtime/runtime-saveable/src/commonMain/kotlin/androidx/compose/runtime/savedinstancestate/UiSavedStateRegistry.kt
+++ b/compose/runtime/runtime-saveable/src/commonMain/kotlin/androidx/compose/runtime/saveable/SaveableStateRegistry.kt
@@ -1,5 +1,5 @@
/*
- * Copyright 2020 The Android Open Source Project
+ * Copyright 2021 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -14,14 +14,14 @@
* limitations under the License.
*/
-package androidx.compose.runtime.savedinstancestate
+package androidx.compose.runtime.saveable
import androidx.compose.runtime.staticAmbientOf
/**
* Allows components to save and restore their state using the saved instance state mechanism.
*/
-interface UiSavedStateRegistry {
+interface SaveableStateRegistry {
/**
* Returns the restored value for the given key.
* Once being restored the value is cleared, so you can't restore the same key twice.
@@ -71,38 +71,25 @@
}
/**
- * Creates [UiSavedStateRegistry].
+ * Creates [SaveableStateRegistry].
*
* @param restoredValues The map of the restored values
* @param canBeSaved Function which returns true if the given value can be saved by the registry
*/
-fun UiSavedStateRegistry(
+fun SaveableStateRegistry(
restoredValues: Map<String, List<Any?>>?,
canBeSaved: (Any) -> Boolean
-): UiSavedStateRegistry = UiSavedStateRegistryImpl(restoredValues, canBeSaved)
+): SaveableStateRegistry = SaveableStateRegistryImpl(restoredValues, canBeSaved)
/**
- * Ambient with a current [UiSavedStateRegistry] instance.
+ * Ambient with a current [SaveableStateRegistry] instance.
*/
-@Suppress("AmbientNaming")
-@Deprecated(
- "Renamed to AmbientUiSavedStateRegistry",
- replaceWith = ReplaceWith(
- "AmbientUiSavedStateRegistry",
- "androidx.compose.runtime.savedinstancestate.AmbientUiSavedStateRegistry"
- )
-)
-val UiSavedStateRegistryAmbient get() = AmbientUiSavedStateRegistry
+val AmbientSaveableStateRegistry = staticAmbientOf<SaveableStateRegistry?> { null }
-/**
- * Ambient with a current [UiSavedStateRegistry] instance.
- */
-val AmbientUiSavedStateRegistry = staticAmbientOf<UiSavedStateRegistry?> { null }
-
-private class UiSavedStateRegistryImpl(
+private class SaveableStateRegistryImpl(
restored: Map<String, List<Any?>>?,
private val canBeSaved: (Any) -> Boolean
-) : UiSavedStateRegistry {
+) : SaveableStateRegistry {
private val restored: MutableMap<String, List<Any?>> =
restored?.toMutableMap() ?: mutableMapOf()
diff --git a/compose/runtime/runtime-saveable/src/commonMain/kotlin/androidx/compose/runtime/saveable/Saver.kt b/compose/runtime/runtime-saveable/src/commonMain/kotlin/androidx/compose/runtime/saveable/Saver.kt
index 3f43303..26d48ee 100644
--- a/compose/runtime/runtime-saveable/src/commonMain/kotlin/androidx/compose/runtime/saveable/Saver.kt
+++ b/compose/runtime/runtime-saveable/src/commonMain/kotlin/androidx/compose/runtime/saveable/Saver.kt
@@ -20,7 +20,7 @@
* The [Saver] describes how the object of [Original] class can be simplified and converted into
* something which is [Saveable].
*
- * What types can be saved is defined by [UiSavedStateRegistry], by default everything which can
+ * What types can be saved is defined by [SaveableStateRegistry], by default everything which can
* be stored in the Bundle class can be saved.
* The implementations can check that the provided value can be saved via [SaverScope.canBeSaved]
*
@@ -46,7 +46,7 @@
* The [Saver] describes how the object of [Original] class can be simplified and converted into
* something which is [Saveable].
*
- * What types can be saved is defined by [UiSavedStateRegistry], by default everything which can
+ * What types can be saved is defined by [SaveableStateRegistry], by default everything which can
* be stored in the Bundle class can be saved.
* The implementations can check that the provided value can be saved via [SaverScope.canBeSaved]
*
@@ -78,7 +78,7 @@
*/
fun interface SaverScope {
/**
- * What types can be saved is defined by [UiSavedStateRegistry], by default everything which can
+ * What types can be saved is defined by [SaveableStateRegistry], by default everything which can
* be stored in the Bundle class can be saved.
*/
fun canBeSaved(value: Any): Boolean
diff --git a/compose/runtime/runtime-saveable/src/commonMain/kotlin/androidx/compose/runtime/savedinstancestate/Deprecated.kt b/compose/runtime/runtime-saveable/src/commonMain/kotlin/androidx/compose/runtime/savedinstancestate/Deprecated.kt
index 55f58b9..74609a3 100644
--- a/compose/runtime/runtime-saveable/src/commonMain/kotlin/androidx/compose/runtime/savedinstancestate/Deprecated.kt
+++ b/compose/runtime/runtime-saveable/src/commonMain/kotlin/androidx/compose/runtime/savedinstancestate/Deprecated.kt
@@ -21,6 +21,8 @@
package androidx.compose.runtime.savedinstancestate
import androidx.compose.runtime.Composable
+import androidx.compose.runtime.saveable.SaveableStateRegistry
+import androidx.compose.runtime.staticAmbientOf
@Deprecated(
"It was moved to androidx.compose.runtime.saveable package",
@@ -127,3 +129,48 @@
): T = throw IllegalStateException(
"This method is deprecated and moved to androidx.compose.runtime.saveable package"
)
+
+@Deprecated(
+ "It was renamed to SaveableStateRegistry and moved to androidx.compose.runtime.saveable" +
+ " package",
+ ReplaceWith(
+ "SaveableStateRegistry",
+ "androidx.compose.runtime.saveable.SaveableStateRegistry"
+ ),
+ level = DeprecationLevel.ERROR
+)
+interface UiSavedStateRegistry : SaveableStateRegistry
+
+@Deprecated(
+ "It was renamed to SaveableStateRegistry and moved to androidx.compose.runtime.saveable" +
+ " package",
+ ReplaceWith(
+ "SaveableStateRegistry(restoredValues, canBeSaved)",
+ "androidx.compose.runtime.saveable.SaveableStateRegistry"
+ ),
+ level = DeprecationLevel.ERROR
+)
+@Suppress("DocumentExceptions")
+fun UiSavedStateRegistry(
+ restoredValues: Map<String, List<Any?>>?,
+ canBeSaved: (Any) -> Boolean
+): UiSavedStateRegistry = throw IllegalStateException(
+ "It was renamed to SaveableStateRegistry and moved to androidx.compose.runtime.saveable" +
+ " package"
+)
+
+@Deprecated(
+ "It was renamed to AmbientSaveableStateRegistry and moved to" +
+ " androidx.compose.runtime.saveable package",
+ ReplaceWith(
+ "AmbientSaveableStateRegistry",
+ "androidx.compose.runtime.saveable.AmbientSaveableStateRegistry"
+ ),
+ level = DeprecationLevel.ERROR
+)
+val AmbientUiSavedStateRegistry = staticAmbientOf<UiSavedStateRegistry?> {
+ throw IllegalStateException(
+ "It was renamed to SaveableStateRegistry and moved to androidx.compose.runtime.saveable" +
+ " package"
+ )
+}
diff --git a/compose/runtime/runtime-saveable/src/test/java/androidx/compose/runtime/savedinstancestate/UiSavedStateRegistryTest.kt b/compose/runtime/runtime-saveable/src/test/java/androidx/compose/runtime/saveable/SaveableStateRegistryTest.kt
similarity index 97%
rename from compose/runtime/runtime-saveable/src/test/java/androidx/compose/runtime/savedinstancestate/UiSavedStateRegistryTest.kt
rename to compose/runtime/runtime-saveable/src/test/java/androidx/compose/runtime/saveable/SaveableStateRegistryTest.kt
index 4c34371..bf3ec29 100644
--- a/compose/runtime/runtime-saveable/src/test/java/androidx/compose/runtime/savedinstancestate/UiSavedStateRegistryTest.kt
+++ b/compose/runtime/runtime-saveable/src/test/java/androidx/compose/runtime/saveable/SaveableStateRegistryTest.kt
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package androidx.compose.runtime.savedinstancestate
+package androidx.compose.runtime.saveable
import com.google.common.truth.Truth.assertThat
import org.junit.Test
@@ -22,7 +22,7 @@
import org.junit.runners.JUnit4
@RunWith(JUnit4::class)
-class UiSavedStateRegistryTest {
+class SaveableStateRegistryTest {
@Test
fun saveSimpleValue() {
@@ -193,5 +193,5 @@
private fun createRegistry(
restored: Map<String, List<Any?>>? = null,
canBeSaved: (Any) -> Boolean = { true }
- ) = UiSavedStateRegistry(restored, canBeSaved)
-}
\ No newline at end of file
+ ) = SaveableStateRegistry(restored, canBeSaved)
+}
diff --git a/compose/ui/ui-test-junit4/src/androidMain/kotlin/androidx/compose/ui/test/junit4/StateRestorationTester.kt b/compose/ui/ui-test-junit4/src/androidMain/kotlin/androidx/compose/ui/test/junit4/StateRestorationTester.kt
index 56f5670..cbbb360 100644
--- a/compose/ui/ui-test-junit4/src/androidMain/kotlin/androidx/compose/ui/test/junit4/StateRestorationTester.kt
+++ b/compose/ui/ui-test-junit4/src/androidMain/kotlin/androidx/compose/ui/test/junit4/StateRestorationTester.kt
@@ -21,9 +21,9 @@
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
-import androidx.compose.runtime.savedinstancestate.AmbientUiSavedStateRegistry
+import androidx.compose.runtime.saveable.AmbientSaveableStateRegistry
+import androidx.compose.runtime.saveable.SaveableStateRegistry
import androidx.compose.runtime.setValue
-import androidx.compose.runtime.savedinstancestate.UiSavedStateRegistry
/**
* Helps to test the state restoration for your Composable component.
@@ -78,24 +78,24 @@
@Composable
private fun InjectRestorationRegistry(content: @Composable (RestorationRegistry) -> Unit) {
- val original = requireNotNull(AmbientUiSavedStateRegistry.current) {
+ val original = requireNotNull(AmbientSaveableStateRegistry.current) {
"StateRestorationTester requires composeTestRule.setContent() to provide " +
- "an UiSavedStateRegistry implementation via UiSavedStateRegistryAmbient"
+ "an SaveableStateRegistry implementation via AmbientSaveableStateRegistry"
}
val restorationRegistry = remember { RestorationRegistry(original) }
- Providers(AmbientUiSavedStateRegistry provides restorationRegistry) {
+ Providers(AmbientSaveableStateRegistry provides restorationRegistry) {
if (restorationRegistry.shouldEmitChildren) {
content(restorationRegistry)
}
}
}
- private class RestorationRegistry(private val original: UiSavedStateRegistry) :
- UiSavedStateRegistry {
+ private class RestorationRegistry(private val original: SaveableStateRegistry) :
+ SaveableStateRegistry {
var shouldEmitChildren by mutableStateOf(true)
private set
- private var currentRegistry: UiSavedStateRegistry = original
+ private var currentRegistry: SaveableStateRegistry = original
private var savedMap: Map<String, List<Any?>> = emptyMap()
fun saveStateAndDisposeChildren() {
@@ -104,7 +104,7 @@
}
fun emitChildrenWithRestoredState() {
- currentRegistry = UiSavedStateRegistry(
+ currentRegistry = SaveableStateRegistry(
restoredValues = savedMap,
canBeSaved = { original.canBeSaved(it) }
)
@@ -123,4 +123,4 @@
override fun performSave() = currentRegistry.performSave()
}
-}
\ No newline at end of file
+}
diff --git a/compose/ui/ui-tooling/src/androidTest/java/androidx/compose/ui/tooling/SimpleComposablePreview.kt b/compose/ui/ui-tooling/src/androidTest/java/androidx/compose/ui/tooling/SimpleComposablePreview.kt
index 227f0b5..3c95990 100644
--- a/compose/ui/ui-tooling/src/androidTest/java/androidx/compose/ui/tooling/SimpleComposablePreview.kt
+++ b/compose/ui/ui-tooling/src/androidTest/java/androidx/compose/ui/tooling/SimpleComposablePreview.kt
@@ -19,7 +19,7 @@
import androidx.compose.material.Surface
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
-import androidx.compose.runtime.savedinstancestate.AmbientUiSavedStateRegistry
+import androidx.compose.runtime.saveable.AmbientSaveableStateRegistry
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.AmbientLifecycleOwner
import androidx.compose.ui.tooling.preview.Preview
@@ -79,11 +79,11 @@
@Preview
@Composable
-private fun UiSavedStateRegistryPreview() {
- if (AmbientUiSavedStateRegistry.current == null) throw IllegalArgumentException(
- "UiSavedStateRegistry is not provided"
+private fun SaveableStateRegistryPreview() {
+ if (AmbientSaveableStateRegistry.current == null) throw IllegalArgumentException(
+ "SaveableStateRegistry is not provided"
)
- Text("UiSavedStateRegistry preview")
+ Text("SaveableStateRegistry preview")
}
class TestGroup {
diff --git a/compose/ui/ui-tooling/src/androidTest/java/androidx/compose/ui/tooling/preview/ComposeViewAdapterTest.kt b/compose/ui/ui-tooling/src/androidTest/java/androidx/compose/ui/tooling/preview/ComposeViewAdapterTest.kt
index 30b9537..05bbd6a 100644
--- a/compose/ui/ui-tooling/src/androidTest/java/androidx/compose/ui/tooling/preview/ComposeViewAdapterTest.kt
+++ b/compose/ui/ui-tooling/src/androidTest/java/androidx/compose/ui/tooling/preview/ComposeViewAdapterTest.kt
@@ -238,10 +238,10 @@
}
@Test
- fun uiSavedStateRegistryUsedInsidePreview() {
+ fun saveableStateRegistryUsedInsidePreview() {
assertRendersCorrectly(
"androidx.compose.ui.tooling.SimpleComposablePreviewKt",
- "UiSavedStateRegistryPreview"
+ "SaveableStateRegistryPreview"
)
}
diff --git a/compose/ui/ui/api/current.txt b/compose/ui/ui/api/current.txt
index 05ed0ae..ff52cbb 100644
--- a/compose/ui/ui/api/current.txt
+++ b/compose/ui/ui/api/current.txt
@@ -2183,7 +2183,7 @@
public final class DebugUtilsKt {
}
- public final class DisposableUiSavedStateRegistryKt {
+ public final class DisposableSaveableStateRegistryKt {
}
public interface InspectableValue {
diff --git a/compose/ui/ui/api/public_plus_experimental_current.txt b/compose/ui/ui/api/public_plus_experimental_current.txt
index 05ed0ae..ff52cbb 100644
--- a/compose/ui/ui/api/public_plus_experimental_current.txt
+++ b/compose/ui/ui/api/public_plus_experimental_current.txt
@@ -2183,7 +2183,7 @@
public final class DebugUtilsKt {
}
- public final class DisposableUiSavedStateRegistryKt {
+ public final class DisposableSaveableStateRegistryKt {
}
public interface InspectableValue {
diff --git a/compose/ui/ui/api/restricted_current.txt b/compose/ui/ui/api/restricted_current.txt
index cf8cdc8..71d7ef0d 100644
--- a/compose/ui/ui/api/restricted_current.txt
+++ b/compose/ui/ui/api/restricted_current.txt
@@ -2245,7 +2245,7 @@
public final class DebugUtilsKt {
}
- public final class DisposableUiSavedStateRegistryKt {
+ public final class DisposableSaveableStateRegistryKt {
}
public interface InspectableValue {
diff --git a/compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/platform/UiSavedStateRegistryTest.kt b/compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/platform/DisposableSaveableStateRegistryTest.kt
similarity index 88%
rename from compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/platform/UiSavedStateRegistryTest.kt
rename to compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/platform/DisposableSaveableStateRegistryTest.kt
index b93ac1d..0124586 100644
--- a/compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/platform/UiSavedStateRegistryTest.kt
+++ b/compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/platform/DisposableSaveableStateRegistryTest.kt
@@ -41,7 +41,7 @@
@SmallTest
@RunWith(AndroidJUnit4::class)
-class DisposableUiSavedStateRegistryTest {
+class DisposableSaveableStateRegistryTest {
private val ContainerKey = 100
private val SaveKey = "key"
@@ -51,12 +51,12 @@
@Test
fun simpleSaveAndRestore() {
val owner1 = TestOwner()
- var registry = DisposableUiSavedStateRegistry(ContainerKey, owner1)
+ var registry = DisposableSaveableStateRegistry(ContainerKey, owner1)
registry.registerProvider(SaveKey) { SaveValue }
val bundle = owner1.save()
val owner2 = TestOwner(bundle)
- registry = DisposableUiSavedStateRegistry(ContainerKey, owner2)
+ registry = DisposableSaveableStateRegistry(ContainerKey, owner2)
val restoredValue = registry.consumeRestored(SaveKey)
assertEquals(SaveValue, restoredValue)
}
@@ -72,22 +72,22 @@
val value2 = 2
// save first view
- val registryToSave1 = DisposableUiSavedStateRegistry(parentKey1, owner1)
+ val registryToSave1 = DisposableSaveableStateRegistry(parentKey1, owner1)
registryToSave1.registerProvider(SaveKey) { value1 }
// save second view
- val registryToSave2 = DisposableUiSavedStateRegistry(parentKey2, owner1)
+ val registryToSave2 = DisposableSaveableStateRegistry(parentKey2, owner1)
registryToSave2.registerProvider(SaveKey) { value2 }
val owner2 = TestOwner(owner1.save())
// restore first view
- val registryToRestore1 = DisposableUiSavedStateRegistry(parentKey1, owner2)
+ val registryToRestore1 = DisposableSaveableStateRegistry(parentKey1, owner2)
val restoredValue1 = registryToRestore1.consumeRestored(SaveKey)
assertEquals(value1, restoredValue1)
// restore second view
- val registryToRestore2 = DisposableUiSavedStateRegistry(parentKey2, owner2)
+ val registryToRestore2 = DisposableSaveableStateRegistry(parentKey2, owner2)
val restoredValue2 = registryToRestore2.consumeRestored(SaveKey)
assertEquals(value2, restoredValue2)
}
@@ -95,7 +95,7 @@
@UiThreadTest
@Test
fun typesSupportedByBaseBundleCanBeSaved() {
- val registry = DisposableUiSavedStateRegistry(ContainerKey, TestOwner())
+ val registry = DisposableSaveableStateRegistry(ContainerKey, TestOwner())
assertTrue(registry.canBeSaved(true))
assertTrue(registry.canBeSaved(true.asBoxed()))
@@ -114,7 +114,7 @@
@UiThreadTest
@Test
fun typesSupportedByBundleCanBeSaved() {
- val registry = DisposableUiSavedStateRegistry(ContainerKey, TestOwner())
+ val registry = DisposableSaveableStateRegistry(ContainerKey, TestOwner())
assertTrue(registry.canBeSaved(Binder()))
assertTrue(registry.canBeSaved(Bundle()))
@@ -148,7 +148,7 @@
@UiThreadTest
@Test
fun customTypeCantBeSaved() {
- val registry = DisposableUiSavedStateRegistry(ContainerKey, TestOwner())
+ val registry = DisposableSaveableStateRegistry(ContainerKey, TestOwner())
assertFalse(registry.canBeSaved(CustomClass()))
}
@@ -156,7 +156,7 @@
@UiThreadTest
@Test
fun charSequenceCantBeSaved() {
- val registry = DisposableUiSavedStateRegistry(ContainerKey, TestOwner())
+ val registry = DisposableSaveableStateRegistry(ContainerKey, TestOwner())
assertFalse(registry.canBeSaved(CustomCharSequence()))
}
diff --git a/compose/ui/ui/src/androidMain/kotlin/androidx/compose/ui/platform/AndroidAmbients.kt b/compose/ui/ui/src/androidMain/kotlin/androidx/compose/ui/platform/AndroidAmbients.kt
index 7209338..88b2a04 100644
--- a/compose/ui/ui/src/androidMain/kotlin/androidx/compose/ui/platform/AndroidAmbients.kt
+++ b/compose/ui/ui/src/androidMain/kotlin/androidx/compose/ui/platform/AndroidAmbients.kt
@@ -31,7 +31,7 @@
import androidx.compose.runtime.neverEqualPolicy
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
-import androidx.compose.runtime.savedinstancestate.AmbientUiSavedStateRegistry
+import androidx.compose.runtime.saveable.AmbientSaveableStateRegistry
import androidx.compose.runtime.setValue
import androidx.compose.runtime.staticAmbientOf
import androidx.compose.ui.ExperimentalComposeUiApi
@@ -98,12 +98,12 @@
"Called when the ViewTreeOwnersAvailability is not yet in Available state"
)
- val uiSavedStateRegistry = remember {
- DisposableUiSavedStateRegistry(view, viewTreeOwners.savedStateRegistryOwner)
+ val saveableStateRegistry = remember {
+ DisposableSaveableStateRegistry(view, viewTreeOwners.savedStateRegistryOwner)
}
DisposableEffect(Unit) {
onDispose {
- uiSavedStateRegistry.dispose()
+ saveableStateRegistry.dispose()
}
}
@@ -112,7 +112,7 @@
AmbientContext provides context,
AmbientLifecycleOwner provides viewTreeOwners.lifecycleOwner,
AmbientSavedStateRegistryOwner provides viewTreeOwners.savedStateRegistryOwner,
- AmbientUiSavedStateRegistry provides uiSavedStateRegistry,
+ AmbientSaveableStateRegistry provides saveableStateRegistry,
AmbientView provides owner.view,
AmbientViewModelStoreOwner provides viewTreeOwners.viewModelStoreOwner
) {
diff --git a/compose/ui/ui/src/androidMain/kotlin/androidx/compose/ui/platform/DisposableUiSavedStateRegistry.kt b/compose/ui/ui/src/androidMain/kotlin/androidx/compose/ui/platform/DisposableSaveableStateRegistry.kt
similarity index 84%
rename from compose/ui/ui/src/androidMain/kotlin/androidx/compose/ui/platform/DisposableUiSavedStateRegistry.kt
rename to compose/ui/ui/src/androidMain/kotlin/androidx/compose/ui/platform/DisposableSaveableStateRegistry.kt
index e38953bf..c46566b 100644
--- a/compose/ui/ui/src/androidMain/kotlin/androidx/compose/ui/platform/DisposableUiSavedStateRegistry.kt
+++ b/compose/ui/ui/src/androidMain/kotlin/androidx/compose/ui/platform/DisposableSaveableStateRegistry.kt
@@ -23,29 +23,29 @@
import android.util.SizeF
import android.util.SparseArray
import android.view.View
-import androidx.compose.runtime.savedinstancestate.UiSavedStateRegistry
+import androidx.compose.runtime.saveable.SaveableStateRegistry
import androidx.savedstate.SavedStateRegistry
import androidx.savedstate.SavedStateRegistryOwner
import java.io.Serializable
/**
- * Creates [DisposableUiSavedStateRegistry] associated with these [view] and [owner].
+ * Creates [DisposableSaveableStateRegistry] associated with these [view] and [owner].
*/
-internal fun DisposableUiSavedStateRegistry(
+internal fun DisposableSaveableStateRegistry(
view: View,
owner: SavedStateRegistryOwner
-): DisposableUiSavedStateRegistry {
+): DisposableSaveableStateRegistry {
// When AndroidComposeView is composed into some ViewGroup we just added as a child for this
// ViewGroup. And we don't have any id on AndroidComposeView as we can't make it unique, but
// we require this parent ViewGroup to have an unique id for the saved instance state mechanism
// to work (similarly to how it works without Compose). When we composed into Activity our
// parent is the ViewGroup with android.R.id.content.
val parentId: Int = (view.parent as? View)?.id ?: View.NO_ID
- return DisposableUiSavedStateRegistry(parentId, owner)
+ return DisposableSaveableStateRegistry(parentId, owner)
}
/**
- * Creates [DisposableUiSavedStateRegistry] with the restored values using [SavedStateRegistry] and
+ * Creates [DisposableSaveableStateRegistry] with the restored values using [SavedStateRegistry] and
* saves the values when [SavedStateRegistry] performs save.
*
* To provide a namespace we require unique [id]. We can't use the default way of doing it when we
@@ -59,22 +59,22 @@
* id for this ViewGroup. If @GenerateView will be used then we will ask users to set an id on
* this generated View.
*/
-internal fun DisposableUiSavedStateRegistry(
+internal fun DisposableSaveableStateRegistry(
id: Int,
savedStateRegistryOwner: SavedStateRegistryOwner
-): DisposableUiSavedStateRegistry {
- val key = "${UiSavedStateRegistry::class.java.simpleName}:$id"
+): DisposableSaveableStateRegistry {
+ val key = "${SaveableStateRegistry::class.java.simpleName}:$id"
val androidxRegistry = savedStateRegistryOwner.savedStateRegistry
val bundle = androidxRegistry.consumeRestoredStateForKey(key)
val restored: Map<String, List<Any?>>? = bundle?.toMap()
- val uiSavedStateRegistry = UiSavedStateRegistry(restored) {
+ val saveableStateRegistry = SaveableStateRegistry(restored) {
canBeSavedToBundle(it)
}
val registered = try {
androidxRegistry.registerSavedStateProvider(key) {
- uiSavedStateRegistry.performSave().toBundle()
+ saveableStateRegistry.performSave().toBundle()
}
true
} catch (ignore: IllegalArgumentException) {
@@ -84,7 +84,7 @@
// TODO: we should verify our strategy for such cases and improve it. b/162397322
false
}
- return DisposableUiSavedStateRegistry(uiSavedStateRegistry) {
+ return DisposableSaveableStateRegistry(saveableStateRegistry) {
if (registered) {
androidxRegistry.unregisterSavedStateProvider(key)
}
@@ -92,12 +92,12 @@
}
/**
- * [UiSavedStateRegistry] which can be disposed using [dispose].
+ * [SaveableStateRegistry] which can be disposed using [dispose].
*/
-internal class DisposableUiSavedStateRegistry(
- uiSavedStateRegistry: UiSavedStateRegistry,
+internal class DisposableSaveableStateRegistry(
+ saveableStateRegistry: SaveableStateRegistry,
private val onDispose: () -> Unit
-) : UiSavedStateRegistry by uiSavedStateRegistry {
+) : SaveableStateRegistry by saveableStateRegistry {
fun dispose() {
onDispose()