ForgetfulRetainedValuesStore


The ForgetfulRetainedValuesStore is an implementation of RetainedValuesStore that is incapable of retaining any exited values. When installed as the LocalRetainedValuesStore, all invocations of retain will behave like a standard remember. RetainObserver callbacks are still dispatched instead of RememberObserver callbacks, meaning that this class will always immediately retire a value as soon as it exits composition.

Summary

Public functions

open Any?
getExitedValueOrElse(key: Any, defaultValue: Any?)

If this store is currently retaining exited values and has a value previously created with the given key, its original record is returned and removed from the list of exited kept objects that this store is tracking.

Cmn

Protected functions

open Unit

Called when this store first starts to retain exited values (i.e. when isRetainingExitedValues transitions from false to true).

Cmn
open Unit

Called when this store stops retaining exited values (i.e. when isRetainingExitedValues transitions from true to false).

Cmn
open Unit
saveExitingValue(key: Any, value: Any?)

Invoked when a retained value is exiting composition while this store is retaining exited values.

Cmn

Inherited functions

From androidx.compose.runtime.retain.RetainedValuesStore
final Unit

Registers the given observer with this RetainStateProvider to be notified when the value of isRetainingExitedValues changes.

Cmn
final Unit

Removes a previously registered observer.

Cmn
Unit

Called to increment the number of requests to retain exited values.

Cmn
Unit

Clears a previous call to requestRetainExitedValues.

Cmn

Inherited properties

From androidx.compose.runtime.retain.RetainedValuesStore
final Boolean

Returns whether retained values should continue to be held when they are removed from the composition hierarchy.

Cmn
Int
Cmn

Public functions

getExitedValueOrElse

open fun getExitedValueOrElse(key: Any, defaultValue: Any?): Any?

If this store is currently retaining exited values and has a value previously created with the given key, its original record is returned and removed from the list of exited kept objects that this store is tracking.

Parameters
key: Any

The keys to resolve a retained value that has left composition

defaultValue: Any?

A value to be returned if there are no retained values that have exited composition and are being held by this RetainedValuesStore for the given key.

Returns
Any?

A retained value for key if there is one and it hasn't already re-entered composition, otherwise defaultValue.

Protected functions

onStartRetainingExitedValues

protected open fun onStartRetainingExitedValues(): Unit

Called when this store first starts to retain exited values (i.e. when isRetainingExitedValues transitions from false to true). When this is called, implementors should prepare to begin to store values they receive from saveExitingValue.

onStopRetainingExitedValues

protected open fun onStopRetainingExitedValues(): Unit

Called when this store stops retaining exited values (i.e. when isRetainingExitedValues transitions from true to false). After this is called, all exited values that have been kept and not restored via getExitedValueOrElse should be retired.

Implementors MUST invoke RetainObserver.onRetired for all exited and unrestored RememberObservers when this method is invoked.

saveExitingValue

protected open fun saveExitingValue(key: Any, value: Any?): Unit

Invoked when a retained value is exiting composition while this store is retaining exited values. It is up to the implementation of this method to decide whether and how to store these values so that they can later be retrieved by getExitedValueOrElse.

The given key are not guaranteed to be unique. To handle duplicate keys, implementors should return retained values with the same keys from getExitedValueOrElse in the opposite order they are received by saveExitingValue.

If the implementation of this store does not accept this value into its kept exited object list, it MUST call RetainObserver.onRetired if value implements RetainObserver.