ForgetfulRetainScope


The ForgetfulRetainScope is an implementation of RetainScope that is incapable of keeping any exited values. When installed as the LocalRetainScope, 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?
getExitedValueOrDefault(key: Any, defaultIfAbsent: Any?)

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

Cmn

Protected functions

open Unit

Called when this scope first starts to keep exited values (i.e. when isKeepingExitedValues transitions from false to true).

Cmn
open Unit

Called when this scope stops keeping exited values (i.e. when isKeepingExitedValues transitions from true to false).

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

Invoked when a retained value is exiting composition while this scope is keeping exited values.

Cmn

Inherited functions

From androidx.compose.runtime.RetainScope
final Unit

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

Cmn
final Unit

Removes a previously registered observer.

Cmn
Unit

Called to increment the number of retain events requested.

Cmn
Unit

Clears a previous call to requestKeepExitedValues.

Cmn

Inherited properties

From androidx.compose.runtime.RetainScope
final Boolean

Returns whether the associated retain scenario is active, and associated scopes should retain objects as they are removed from the composition hierarchy.

Cmn

Public functions

getExitedValueOrDefault

open fun getExitedValueOrDefault(key: Any, defaultIfAbsent: Any?): Any?

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

Parameters
key: Any

The keys to resolve a retained value that has left composition

defaultIfAbsent: Any?

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

Returns
Any?

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

Protected functions

onStartKeepingExitedValues

protected open fun onStartKeepingExitedValues(): Unit

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

onStopKeepingExitedValues

protected open fun onStopKeepingExitedValues(): Unit

Called when this scope stops keeping exited values (i.e. when isKeepingExitedValues transitions from true to false). After this is called, all exited values that have been kept and not restored via getExitedValueOrDefault 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 scope is keeping 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 getExitedValueOrDefault.

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

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