Function

setObserver

Observe the composition.

setObserver

Source set: Common
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.

The observer is resolved once per composition pass, between CompositionObserver.onBeginComposition and CompositionObserver.onEndComposition. Setting or replacing the observer while a pass is in progress takes effect starting with the next pass.

Parameters

observer the 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.

Return

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.

Jetpack Compose beyond MaterialFree components, screens and templates for apps that don’t look like Google’s. Copy them into your app, or let your coding agent add them.Browse for free

Content updated: