🌈 Create new beautiful Compose Gradients with our new wesite ->
Interface

ViewCompositionStrategy

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

Source set: Android
public interface ViewCompositionStrategy

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.

Functions

installFor

Source set: Android
public fun installFor(view: AbstractComposeView): () -> Unit

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.

Members

Companion

Source set: Android
public companion object

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

Properties

Default

Source set: Android
public val Default: ViewCompositionStrategy

The default strategy for AbstractComposeView and ComposeView.

Currently, this is DisposeOnDetachedFromWindowOrReleasedFromPool, though this implementation detail may change.

DisposeOnDetachedFromWindowOrReleasedFromPool

Source set: Android
public object DisposeOnDetachedFromWindowOrReleasedFromPool : ViewCompositionStrategy

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.

When not within a pooling container, this behaves exactly the same as DisposeOnDetachedFromWindow.

Functions

installFor

Source set: Android
override fun installFor(view: AbstractComposeView): () -> Unit

DisposeOnDetachedFromWindow

Source set: Android
public object DisposeOnDetachedFromWindow : ViewCompositionStrategy

ViewCompositionStrategy that disposes the composition whenever the view becomes detached from a window. If the user of a Compose UI view never explicitly calls AbstractComposeView.createComposition, this strategy is always safe and will always clean up composition resources with no explicit action required - just use the view like any other View and let garbage collection do the rest. (If AbstractComposeView.createComposition is called while the view is detached from a window, AbstractComposeView.disposeComposition must be called manually if the view is not later attached to a window.)

Functions

installFor

Source set: Android
override fun installFor(view: AbstractComposeView): () -> Unit

DisposeOnLifecycleDestroyed

Source set: Android
public class DisposeOnLifecycleDestroyed(private val lifecycle: Lifecycle) :
        ViewCompositionStrategy

ViewCompositionStrategy that disposes the composition when lifecycle is destroyed. This strategy is appropriate for Compose UI views that share a 1-1 relationship with a known LifecycleOwner.

Functions

installFor

Source set: Android
override fun installFor(view: AbstractComposeView): () -> Unit

DisposeOnViewTreeLifecycleDestroyed

Source set: Android
public object DisposeOnViewTreeLifecycleDestroyed : ViewCompositionStrategy

ViewCompositionStrategy that disposes the composition when the LifecycleOwner returned by findViewTreeLifecycleOwner of the next window the view is attached to is destroyed. This strategy is appropriate for Compose UI views that share a 1-1 relationship with their closest LifecycleOwner, such as a Fragment view.

Functions

installFor

Source set: Android
override fun installFor(view: AbstractComposeView): () -> Unit