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.ui.test.android.view.View
Bitmap

Captures the underlying view's surface into bitmap.

From androidx.compose.ui.platform.android.view.ViewGroup
Composition
ViewGroup.setContent(recomposer: Recomposer, parentComposition: CompositionReference? = null, content: () -> Unit)

Composes the given composable into the given view.

Composition
ViewGroup.setContent(content: () -> Unit)

Composes the given composable into the given view.

Composition
ViewGroup.setViewContent(parent: CompositionReference? = null, 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.

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: Int,
    heightMeasureSpec: Int
): Unit

Properties

isDisposed

val isDisposed: Boolean

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