Google is committed to advancing racial equity for Black communities. See how.

AbstractComposeView

abstract class AbstractComposeView : ViewGroup
kotlin.Any
   ↳ android.view.View
   ↳ android.view.ViewGroup
   ↳ androidx.compose.ui.platform.AbstractComposeView

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.

This android.view.View requires that the window it is attached to contains a ViewTreeLifecycleOwner. This androidx.lifecycle.LifecycleOwner is used to dispose of the underlying composition when the host Lifecycle is destroyed, permitting the view to be attached and detached repeatedly while preserving the composition. 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.)

Summary

Public constructors
<init>(context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0)

Base class for custom android.view.Views implemented using Jetpack Compose UI.

Public methods
abstract Unit

The Jetpack Compose UI content for this view.

open Unit
addView(child: View?)

open Unit
addView(child: View?, index: Int)

open Unit
addView(child: View?, width: Int, height: Int)

open Unit
addView(child: View?, params: LayoutParams?)

open Unit
addView(child: View?, index: Int, params: LayoutParams?)

Unit

Perform initial composition for this view.

Unit

Dispose of the underlying composition.

Protected methods
open Boolean
addViewInLayout(child: View?, index: Int, params: LayoutParams?)

open Boolean
addViewInLayout(child: View?, index: Int, params: LayoutParams?, preventRequestLayout: Boolean)

open Unit

Unit
onLayout(changed: Boolean, left: Int, top: Int, right: Int, bottom: Int)

Unit
onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int)

Inherited extension functions
From androidx.core.view.android.view.ViewGroup
operator Boolean

Returns true if view is found in this view group.

Unit
ViewGroup.forEach(action: (view: View) -> Unit)

Performs the given action on each view in this view group.

Unit
ViewGroup.forEachIndexed(action: (index: Int, view: View) -> Unit)

Performs the given action on each view in this view group, providing its sequential index.

operator View
ViewGroup.get(index: Int)

Returns the view at index.

Boolean

Returns true if this view group contains no views.

Boolean

Returns true if this view group contains one or more views.

operator MutableIterator<View>

Returns a MutableIterator over the views in this view group.

operator Unit

Removes view from this view group.

operator Unit

Adds view to this view group.

From androidx.core.view.android.view.View
Unit
View.doOnAttach(crossinline action: (view: View) -> Unit)

Performs the given action when this view is attached to a window.

Unit
View.doOnDetach(crossinline action: (view: View) -> Unit)

Performs the given action when this view is detached from a window.

Unit
View.doOnLayout(crossinline action: (view: View) -> Unit)

Performs the given action when this view is laid out.

Unit
View.doOnNextLayout(crossinline action: (view: View) -> Unit)

Performs the given action when this view is next laid out.

OneShotPreDrawListener
View.doOnPreDraw(crossinline action: (view: View) -> Unit)

Performs the given action when the view tree is about to be drawn.

Bitmap
View.drawToBitmap(config: Config = Bitmap.Config.ARGB_8888)

Return a Bitmap representation of this View.

Runnable
View.postDelayed(delayInMillis: Long, crossinline action: () -> Unit)

Version of View.postDelayed which re-orders the parameters, allowing the action to be placed outside of parentheses.

Runnable
View.postOnAnimationDelayed(delayInMillis: Long, crossinline action: () -> Unit)

Version of View.postOnAnimationDelayed which re-orders the parameters, allowing the action to be placed outside of parentheses.

Unit
View.setPadding(@Px size: Int)

Sets the view's padding.

Unit

Executes block with the View's layoutParams and reassigns the layoutParams with the updated version.

Unit
View.updateLayoutParams(block: T.() -> Unit)

Executes block with a typed version of the View's layoutParams and reassigns the layoutParams with the updated version.

Unit
View.updatePadding(@Px left: Int = paddingLeft, @Px top: Int = paddingTop, @Px right: Int = paddingRight, @Px bottom: Int = paddingBottom)

Updates this view's padding.

Unit
View.updatePaddingRelative(@Px start: Int = paddingStart, @Px top: Int = paddingTop, @Px end: Int = paddingEnd, @Px bottom: Int = paddingBottom)

Updates this view's relative padding.

From androidx.fragment.app.android.view.View
F

Find a Fragment associated with a View.

From androidx.navigation.android.view.View
NavController

Find a NavController associated with a View.

From androidx.lifecycle.android.view.View
LifecycleOwner?

Locates the LifecycleOwner responsible for managing this View, if present.

ViewModelStoreOwner?

Locates the ViewModelStoreOwner associated with this View, if present.

From androidx.savedstate.android.view.View
SavedStateRegistryOwner?

Locates the SavedStateRegistryOwner associated with this View, if present.

From androidx.compose.ui.platform.android.view.ViewGroup
Composition
ViewGroup.setContent(parent: CompositionReference = Recomposer.current(), content: () -> Unit)

Composes the given composable into the given view.

Composition
ViewGroup.setViewContent(parent: CompositionReference = Recomposer.current(), composable: () -> Unit)

Composes the children of the view with the passed in composable.

Properties
Boolean

true if disposeComposition has been called, either explicitly or by the host window's ViewTreeLifecycleOwner being destroyed.

Inherited extension properties
From androidx.core.view.android.view.View
Sequence<View>

Returns a Sequence over this view and its descendants recursively.

Sequence<ViewParent>

Returns a Sequence of the parent chain of this view by repeatedly calling View.getParent.

Boolean

Returns true when this view's visibility is View.GONE, false otherwise.

Boolean

Returns true when this view's visibility is View.INVISIBLE, false otherwise.

Boolean

Returns true when this view's visibility is View.VISIBLE, false otherwise.

Int

Returns the bottom margin if this view's LayoutParams is a ViewGroup.MarginLayoutParams, otherwise 0.

Int

Returns the end margin if this view's LayoutParams is a ViewGroup.MarginLayoutParams, otherwise 0.

Int

Returns the left margin if this view's LayoutParams is a ViewGroup.MarginLayoutParams, otherwise 0.

Int

Returns the right margin if this view's LayoutParams is a ViewGroup.MarginLayoutParams, otherwise 0.

Int

Returns the start margin if this view's LayoutParams is a ViewGroup.MarginLayoutParams, otherwise 0.

Int

Returns the top margin if this view's LayoutParams is a ViewGroup.MarginLayoutParams, otherwise 0.

From androidx.core.view.android.view.ViewGroup
Sequence<View>

Returns a Sequence over the immediate child views in this view group.

Sequence<View>

Returns a Sequence over the child views in this view group recursively.

Int

Returns the number of views in this view group.

Public constructors

<init>

AbstractComposeView(
    context: Context,
    attrs: AttributeSet? = null,
    defStyleAttr: Int = 0)

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.

This android.view.View requires that the window it is attached to contains a ViewTreeLifecycleOwner. This androidx.lifecycle.LifecycleOwner is used to dispose of the underlying composition when the host Lifecycle is destroyed, permitting the view to be attached and detached repeatedly while preserving the composition. 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.)

Public methods

Content

@Composable 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.

addView

open fun addView(child: View?): Unit

addView

open fun addView(
    child: View?,
    index: Int
): Unit

addView

open fun addView(
    child: View?,
    width: Int,
    height: Int
): Unit

addView

open fun addView(
    child: View?,
    params: LayoutParams?
): Unit

addView

open fun addView(
    child: View?,
    index: Int,
    params: LayoutParams?
): Unit

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 ViewTreeLifecycleOwner 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. If it is called after the composition is disposed it will throw IllegalStateException.

disposeComposition

fun disposeComposition(): Unit

Dispose of the underlying composition. The result of this call is permanent; once disposed a ComposeView cannot be used again and will remain empty.

Protected methods

addViewInLayout

protected open fun addViewInLayout(
    child: View?,
    index: Int,
    params: LayoutParams?
): Boolean

addViewInLayout

protected open fun addViewInLayout(
    child: View?,
    index: Int,
    params: LayoutParams?,
    preventRequestLayout: Boolean
): Boolean

onAttachedToWindow

protected open fun onAttachedToWindow(): Unit

onLayout

protected fun onLayout(
    changed: Boolean,
    left: Int,
    top: Int,
    right: Int,
    bottom: Int
): Unit

onMeasure

protected fun onMeasure(
    widthMeasureSpec: