Objects implementing this interface are notified when they are initially used in a composition and when they are no longer being used.
An object enters the composition if it is remembered in at least one place in a composition. Compose may implicitly remember an object if doing so is required to restart the composition later, such as for composable function parameters. An object leaves a composition when it is no longer remembered anywhere in that composition.
Implementations of CompositionLifecycleObserver should generally not expose those object references outside of their immediate usage sites. A CompositionLifecycleObserver reference that is propagated to multiple parts of a composition might remain present in the composition for longer than expected if it is remembered (explicitly or implicitly) elsewhere in the same composition, and a CompositionLifecycleObserver that appears in more than one composition may have its lifecycle callback methods called multiple times in no meaningful order and on multiple threads. Implementations intending to support this use case should implement atomic reference counting or a similar strategy to correctly manage resources.
Called when this object successfully enters a composition.
Called when this object leaves a composition.
open fun onEnter(): Unit
Called when this object successfully enters a composition. This method is called on the composition's apply thread.
open fun onLeave(): Unit
Called when this object leaves a composition. This method is called on the composition's apply thread.