{% setvar book_path %}/reference/androidx/_book.yaml{% endsetvar %} {% include "_shared/_reference-head-tags.html" %}

ViewCompositionStrategy

public interface ViewCompositionStrategy

Known direct subclasses
ViewCompositionStrategy.DisposeOnDetachedFromWindowOrReleasedFromPool

The composition will be disposed automatically when the view is detached from a window, unless it is part of a pooling container, such as RecyclerView.

ViewCompositionStrategy.DisposeOnDetachedFromWindow

ViewCompositionStrategy that disposes the composition whenever the view becomes detached from a window.

ViewCompositionStrategy.DisposeOnLifecycleDestroyed

ViewCompositionStrategy that disposes the composition when lifecycle is destroyed.

ViewCompositionStrategy.DisposeOnViewTreeLifecycleDestroyed

ViewCompositionStrategy that disposes the composition when the LifecycleOwner returned by findViewTreeLifecycleOwner of the next window the view is attached to is destroyed.


A strategy for managing the underlying Composition of Compose UI Views such as ComposeView and AbstractComposeView. See AbstractComposeView.setViewCompositionStrategy.

Compose views involve ongoing work and registering the composition with external event sources. These registrations can cause the composition to remain live and ineligible for garbage collection for long after the host View may have been abandoned. These resources and registrations can be released manually at any time by calling AbstractComposeView.disposeComposition and a new composition will be created automatically when needed. A ViewCompositionStrategy defines a strategy for disposing the composition automatically at an appropriate time.

By default, Compose UI views are configured to Default.

Summary

Nested types

This companion object may be used to define extension factory functions for other strategies to aid in discovery via autocomplete. e.g.: fun ViewCompositionStrategy.Companion.MyStrategy(): MyStrategy

ViewCompositionStrategy that disposes the composition whenever the view becomes detached from a window.

The composition will be disposed automatically when the view is detached from a window, unless it is part of a pooling container, such as RecyclerView.

ViewCompositionStrategy that disposes the composition when lifecycle is destroyed.

ViewCompositionStrategy that disposes the composition when the LifecycleOwner returned by findViewTreeLifecycleOwner of the next window the view is attached to is destroyed.

Public methods

abstract @NonNull Function0<Unit>

Install this strategy for view and return a function that will uninstall it later.

Public methods

installFor

abstract @NonNull Function0<UnitinstallFor(@NonNull AbstractComposeView view)

Install this strategy for view and return a function that will uninstall it later. This function should not be called directly; it is called by AbstractComposeView.setViewCompositionStrategy after uninstalling the previous strategy.