setObserver

Function

Common
@ExperimentalComposeRuntimeApi
public fun Composition.setObserver(observer: CompositionObserver): CompositionObserverHandle?

Observe the composition. Calling this twice on the same composition will implicitly dispose the previous observer. the CompositionObserver will be called for this composition and all sub-composition, transitively, for which this composition is a context. If setObserver is called on a sub-composition, it will override the parent composition observer for itself and all its sub-compositions.

Parameters

observerthe observer that will be informed of composition events for this composition and all sub-compositions for which this composition is the composition context. Observing a composition will prevent the parent composition's observer from receiving composition events about this composition.

Returns

a handle that allows the observer to be disposed and detached from the composition. Disposing an observer for a composition with a parent observer will begin sending the events to the parent composition's observer. A null indicates the composition does not support being observed.