AbstractComposeView
-
android
abstract class AbstractComposeView : ViewGroup
| kotlin.Any | |||
| ↳ | android.view.View | ||
| ↳ | android.view.ViewGroup | ||
| ↳ | androidx.compose.ui.platform.AbstractComposeView |
ComposeView |
A |
Base class for custom android.view.Views implemented using Jetpack Compose UI. Subclasses should implement the Content function with the appropriate content. Calls to addView and its variants and overloads will fail with IllegalStateException.
By default, the composition is disposed according to ViewCompositionStrategy.Default. Call disposeComposition to dispose of the underlying composition earlier, or if the view is never initially attached to a window. (The requirement to dispose of the composition explicitly in the event that the view is never (re)attached is temporary.)
AbstractComposeView only supports being added into view hierarchies propagating LifecycleOwner and SavedStateRegistryOwner via androidx.lifecycle.setViewTreeLifecycleOwner and androidx.savedstate.setViewTreeSavedStateRegistryOwner. In most cases you will already have it set up correctly as androidx.activity.ComponentActivity, androidx.fragment.app.Fragment and androidx.navigation.NavController will provide the correct values.
Summary
Public constructors |
|
|---|---|
AbstractComposeView( |
android
|
Public functions |
||
|---|---|---|
abstract Unit |
The Jetpack Compose UI content for this view. |
android
|
open Unit |
android
|
|
open Unit |
android
|
|
open Unit |
addView(child: View?, params: ViewGroup.LayoutParams?) |
android
|
open Unit |
addView(child: View?, index: Int, params: ViewGroup.LayoutParams?) |
android
|
open Unit |
android
|
|
Unit |
Perform initial composition for this view. |
android
|
Unit |
Dispose of the underlying composition and |
android
|
open Boolean |
android
|
|
open Unit |
onRtlPropertiesChanged(layoutDirection: Int) |
android
|
Unit |
Set the |
android
|
open Unit |
setTransitionGroup(isTransitionGroup: Boolean) |
android
|
Unit |
Set the strategy for managing disposal of this View's internal composition. |
android
|
open Boolean |
android
|
Protected functions |
||
|---|---|---|
open Boolean |
addViewInLayout(child: View?, index: Int, params: ViewGroup.LayoutParams?) |
android
|
open Boolean |
addViewInLayout( |
android
|
open Unit |
android
|
|
final Unit |
android
|
|
final Unit |
android
|
Public properties |
||
|---|---|---|
AutoClearFocusBehavior |
Controls behavior for how focus should be automatically cleared for this |
android
|
Boolean |
|
android
|
Boolean |
Enables the display of visual layout bounds for the Compose UI content of this view. |
android
|
Protected properties |
||
|---|---|---|
open Boolean |
If |
android
|
Extension properties |
||
|---|---|---|
Boolean |
Indicates whether access to |
android
|
Inherited functions |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Public constructors
AbstractComposeView
AbstractComposeView(
context: Context,
attrs: AttributeSet? = null,
defStyleAttr: Int = 0
)
Public functions
Content
@Composable
@UiComposable
abstract fun Content(): Unit
The Jetpack Compose UI content for this view. Subclasses must implement this method to provide content. Initial composition will occur when the view becomes attached to a window or when createComposition is called, whichever comes first.
createComposition
fun createComposition(): Unit
Perform initial composition for this view. Once this method is called or the view becomes attached to a window, either disposeComposition must be called or the LifecycleOwner returned by findViewTreeLifecycleOwner must reach the Lifecycle.State.DESTROYED state for the composition to be cleaned up properly. (This restriction is temporary.)
If this method is called when the composition has already been created it has no effect.
This method should only be called if this view isAttachedToWindow or if a parent CompositionContext has been set explicitly.
disposeComposition
fun disposeComposition(): Unit
Dispose of the underlying composition and requestLayout. A new composition will be created if createComposition is called or when needed to lay out this view.
setParentCompositionContext
fun setParentCompositionContext(parent: CompositionContext?): Unit
Set the CompositionContext that should be the parent of this view's composition. If parent is null it will be determined automatically from the window the view is attached to.
setViewCompositionStrategy
fun setViewCompositionStrategy(strategy: ViewCompositionStrategy): Unit
Set the strategy for managing disposal of this View's internal composition. Defaults to ViewCompositionStrategy.Default.
This View's composition is a live resource that must be disposed to ensure that long-lived references to it do not persist
See ViewCompositionStrategy for more information.
Protected functions
addViewInLayout
protected open fun addViewInLayout(child: View?, index: Int, params: ViewGroup.LayoutParams?): Boolean
addViewInLayout
protected open fun addViewInLayout(
child: View?,
index: Int,
params: ViewGroup.LayoutParams?,
preventRequestLayout: Boolean
): Boolean
Public properties
autoClearFocusBehavior
var autoClearFocusBehavior: AutoClearFocusBehavior
Controls behavior for how focus should be automatically cleared for this ComposeView when responding to input. The default value is AutoClearFocusBehavior.Default.
This property should be set prior to first composition.
hasComposition
val hasComposition: Boolean
true if this View is host to an active Compose UI composition. An active composition may consume resources.
showLayoutBounds
@InternalComposeUiApi
var showLayoutBounds: Boolean
Enables the display of visual layout bounds for the Compose UI content of this view. This is typically configured using the system developer setting for "Show layout bounds."
Protected properties
shouldCreateCompositionOnAttachedToWindow
protected open val shouldCreateCompositionOnAttachedToWindow: Boolean
If true, this View's composition will be created when it becomes attached to a window for the first time. Defaults to true.
Subclasses may choose to override this property to prevent this eager initial composition in cases where the view's content is not yet ready. Initial composition will still occur when this view is first measured.
Extension properties
consumeWindowInsets
var AbstractComposeView.consumeWindowInsets: Boolean
Indicates whether access to WindowInsets within the content should consume the Android android.view.WindowInsets. The default value is false, meaning that access to WindowInsets.Companion will not consume all the Android WindowInsets and instead adjust the insets based on the position of child Views.
This property should be set prior to first composition.