androidx.compose.runtime.retain

Interfaces

RetainObserver

Objects implementing this interface are notified of their usage in retain.

Cmn
RetainedEffectResult

The return type of a built RetainedEffect.

Cmn
RetainedValuesStore

A RetainedValuesStore acts as a storage area for objects being retained.

Cmn

Classes

ManagedRetainedValuesStore

A ManagedRetainedValuesStore is the default implementation of RetainedValuesStore that can be used to define custom retention periods in the composition hierarchy.

Cmn
RetainedEffectScope

Receiver scope for RetainedEffect that offers the onRetire clause that should be the last statement in any call to RetainedEffect.

Cmn
RetainedValuesStoreRegistry

A RetainedValuesStoreRegistry creates and manages RetainedValuesStore instances for collections of items.

Cmn

Objects

ForgetfulRetainedValuesStore

The ForgetfulRetainedValuesStore is an implementation of RetainedValuesStore that is incapable of retaining any exited values.

Cmn

Composables

LocalRetainedValuesStoreProvider

Installs the given RetainedValuesStore over the provided content such that all values retained in the content lambda are owned by store.

Cmn
RetainedEffect
Cmn
retain

Remember the value produced by calculation and retain it in the LocalRetainedValuesStore.

Cmn
retainManagedRetainedValuesStore

Retains a ManagedRetainedValuesStore.

Cmn
retainRetainedValuesStoreRegistry

Returns a retained instance of a new RetainedValuesStoreRegistry.

Cmn

Top-level properties summary

Top-level properties

LocalRetainedValuesStore

val LocalRetainedValuesStoreProvidableCompositionLocal<RetainedValuesStore>

The RetainedValuesStore in which retain values will be tracked in. Since a RetainedValuesStore controls retention scenarios and signals when to start and end the retention of objects removed from composition, a composition hierarchy may have several RetainedValuesStores to introduce retention periods to specific pieces of content.

The default implementation is a ForgetfulRetainedValuesStore that causes retain to behave the same as remember. On Android, a lifecycle-aware RetainedValuesStore is installed at the root of the composition that retains values across configuration changes.

If this CompositionLocal is updated, all values previously returned by retain will be adopted to the new store and will follow the new store's retention lifecycle.

Always prefer LocalRetainedValuesStoreProvider to setting this local directly. This local is exposed providable as an escape hatch for installing a platform- or library-specific LocalRetainedValuesStore at the root of the hierarchy and for testing custom RetainedValuesStore implementations. Stores installed through this local directly will NOT receive the default calls into RetainedValuesStore.onContentEnteredComposition and RetainedValuesStore.onContentExitComposition provided by LocalRetainedValuesStoreProvider.