Package-level declarations

Types

Link copied to clipboard
fun interface CanRetainChecker

Checks whether or not we can retain, usually derived from the current composable context.

Link copied to clipboard
object Continuity
Link copied to clipboard
@Target(allowedTargets = [AnnotationTarget.FUNCTION])
annotation class DelicateCircuitRetainedApi

Indicates that the annotated retained API is delicate and should be used carefully.

Link copied to clipboard

A no-op RetainedStateRegistry. Should generally only be used for testing and previews.

Link copied to clipboard

Allows components to save and restore their state using the onRetainNonConfigurationInstance mechanism.

Link copied to clipboard

Interface that allows RetainedStateRegistry to unwrap any values held underneath.

Link copied to clipboard
actual fun interface RetainedValueProvider : Function0<Any?>

Provides a retained value to a RetainedStateRegistry.

expect fun interface RetainedValueProvider

Provides a retained value to a RetainedStateRegistry.

actual fun interface RetainedValueProvider

Provides a retained value to a RetainedStateRegistry.

actual fun interface RetainedValueProvider : Function0<Any?>

Provides a retained value to a RetainedStateRegistry.

actual fun interface RetainedValueProvider : Function0<Any?>

Provides a retained value to a RetainedStateRegistry.

actual fun interface RetainedValueProvider

Provides a retained value to a RetainedStateRegistry.

Functions

Link copied to clipboard
fun <T> StateFlow<T>.collectAsRetainedState(context: CoroutineContext = EmptyCoroutineContext): State<T>

Collects values from this StateFlow and represents its latest value via a retained State. The StateFlow.value is used as an initial value. Every time there would be new value posted into the StateFlow the returned State will be updated causing recomposition of every State.value usage.

fun <T : R, R> Flow<T>.collectAsRetainedState(initial: R, context: CoroutineContext = EmptyCoroutineContext): State<R>

Collects values from this Flow and represents its latest value via retained State. Every time there would be new value posted into the Flow the returned State will be updated causing recomposition of every State.value usage.

Link copied to clipboard
fun continuityRetainedStateRegistry(key: String = Continuity.KEY, factory: ViewModelProvider.Factory = ContinuityViewModel.Factory, canRetainChecker: CanRetainChecker = LocalCanRetainChecker.current ?: rememberCanRetainChecker()): RetainedStateRegistry
expect fun continuityRetainedStateRegistry(key: String = Continuity.KEY, canRetainChecker: CanRetainChecker = LocalCanRetainChecker.current ?: rememberCanRetainChecker()): RetainedStateRegistry
Link copied to clipboard
fun <T> produceRetainedState(initialValue: T, producer: suspend ProduceStateScope<T>.() -> Unit): State<T>

Return an observable snapshot State that produces values over time without a defined data source.

fun <T> produceRetainedState(initialValue: T, key1: Any?, producer: suspend ProduceStateScope<T>.() -> Unit): State<T>

Return an observable snapshot State that produces values over time from key1.

fun <T> produceRetainedState(initialValue: T, vararg keys: Any?, producer: suspend ProduceStateScope<T>.() -> Unit): State<T>

Return an observable snapshot State that produces values over time from keys.

fun <T> produceRetainedState(initialValue: T, key1: Any?, key2: Any?, producer: suspend ProduceStateScope<T>.() -> Unit): State<T>

Return an observable snapshot State that produces values over time from key1 and key2.

fun <T> produceRetainedState(initialValue: T, key1: Any?, key2: Any?, key3: Any?, producer: suspend ProduceStateScope<T>.() -> Unit): State<T>

Return an observable snapshot State that produces values over time from key1, key2 and key3.

Link copied to clipboard

On Android, we retain only if the activity is changing configurations.

Checks whether or not we can retain in the current composable context.

Checks whether or not we can retain in the current composable context.

Checks whether or not we can retain in the current composable context.

Checks whether or not we can retain in the current composable context.

Link copied to clipboard
fun <T : Any> rememberRetained(vararg inputs: Any?, key: String? = null, init: () -> T): T
fun <T> rememberRetained(vararg inputs: Any?, stateSaver: Saver<T, out Any>, key: String? = null, init: () -> MutableState<T>): MutableState<T>
fun <T : Any> rememberRetained(vararg inputs: Any?, saver: Saver<T, out Any>, key: String? = null, init: () -> T): T

Remember the value produced by init.

Link copied to clipboard
fun <T> rememberRetainedSaveable(vararg inputs: Any?, stateSaver: Saver<T, out Any>, key: String? = null, init: () -> MutableState<T>): MutableState<T>

A simple proxy to rememberRetained that uses the default autoSaver for stateSaver and a more explicit name.

fun <T : Any> rememberRetainedSaveable(vararg inputs: Any?, saver: Saver<T, out Any> = autoSaver(), key: String? = null, init: () -> T): T

A simple proxy to rememberRetained that uses the default autoSaver for saver and a more explicit name.

Link copied to clipboard