AbstractComposeView

Known direct subclasses
ComposeView

A android.view.View that can host Jetpack Compose UI content.


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(
    context: Context,
    attrs: AttributeSet?,
    defStyleAttr: Int
)
android

Public functions

abstract Unit

The Jetpack Compose UI content for this view.

android
open Unit
addView(child: View?)
android
open Unit
addView(child: View?, index: Int)
android
open Unit
addView(child: View?, params: ViewGroup.LayoutParams?)
android
open Unit
addView(child: View?, index: Int, params: ViewGroup.LayoutParams?)
android
open Unit
addView(child: View?, width: Int, height: Int)
android
Unit

Perform initial composition for this view.

android
Unit

Perform initial composition for this view, even if this view isn't attached to the hierarchy.

android
Unit

Dispose of the underlying composition and requestLayout.

android
open Boolean
android
open Unit
onRtlPropertiesChanged(layoutDirection: Int)
android
Unit

Set the CompositionContext that should be the parent of this view's composition.

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(
    child: View?,
    index: Int,
    params: ViewGroup.LayoutParams?,
    preventRequestLayout: Boolean
)
android
open Unit
android
final Unit
onLayout(changed: Boolean, left: Int, top: Int, right: Int, bottom: Int)
android
final Unit
onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int)
android

Public properties

AutoClearFocusBehavior

Controls behavior for how focus should be automatically cleared for this ComposeView when responding to input.

android
Boolean

true if this View is host to an active Compose UI composition.

android
open Boolean
android
Boolean

Enables the display of visual layout bounds for the Compose UI content of this view.

android

Protected properties

open Boolean

If true, this View's composition will be created when it becomes attached to a window for the first time.

android

Extension properties

Boolean

Indicates whether access to WindowInsets within the content should consume the Android android.view.WindowInsets.

android

Inherited functions

From android.view.View
Unit
addFocusables(views: ArrayList<View>, direction: Int)
android
Unit
android
Unit
android
Unit
android
ViewPropertyAnimator
android
Unit
android
Unit
android
Unit
android
Boolean
android
Boolean
awakenScrollBars(startDelay: Int)
android
Boolean
awakenScrollBars(startDelay: Int, invalidate: Boolean)
android
Unit
android
Unit
android
Unit
android
Unit
android
Boolean
android
open Boolean
android
open Boolean
android
open Boolean
android
Boolean
android
Boolean
android
Unit
android
Unit
android
Unit
android
Boolean
android
Unit
android
Unit
android
Unit
android
Int
android
Int
android
Int
android
Unit
android
WindowInsets
android
Int
android
Int
android
Int
android
AccessibilityNodeInfo
android
open Unit
android
Unit
android
Boolean
android
Boolean
dispatchNestedFling(velocityX: Float, velocityY: Float, consumed: Boolean)
android
Boolean
dispatchNestedPreFling(velocityX: Float, velocityY: Float)
android
Boolean
dispatchNestedPrePerformAccessibilityAction(
    action: Int,
    arguments: Bundle?
)
android
Boolean
dispatchNestedPreScroll(
    dx: Int,
    dy: Int,
    consumed: IntArray?,
    offsetInWindow: IntArray?
)
android
Boolean
dispatchNestedScroll(
    dxConsumed: Int,
    dyConsumed: Int,
    dxUnconsumed: Int,
    dyUnconsumed: Int,
    offsetInWindow: IntArray?
)
android
Boolean
android
Unit
draw(canvas: Canvas)
android
Unit
android
OnBackInvokedDispatcher?
android
T
<T : View> findViewById(id: Int)
android
T
<T : View> findViewWithTag(tag: Any)
android
Boolean
android
View
focusSearch(direction: Int)
android
Unit
forceHasOverlappingRendering(hasOverlappingRendering: Boolean)
android
Unit
android
Unit
generateDisplayHash(
    hashAlgorithm: String,
    bounds: Rect?,
    executor: Executor,
    callback: DisplayHashResultCallback
)
android
IntArray
android
Boolean
getClipBounds(outRect: Rect)
android
Bitmap
android
Unit
getDrawingRect(outRect: Rect)
android
ArrayList<View>
getFocusables(direction: Int)
android
Unit
android
Boolean
android
Boolean
getGlobalVisibleRect(r: Rect, globalOffset: Point)
android
Unit
getHitRect(outRect: Rect)
android
open Int
@ViewDebug.ExportedProperty(category = "layout", mapping = [@ViewDebug.IntToString(from = 0, to = "RESOLVED_DIRECTION_LTR"), @ViewDebug.IntToString(from = 1, to = "RESOLVED_DIRECTION_RTL")])
getLayoutDirection()
android
Boolean
android
Unit
android
Unit
android
Unit
android
ViewParent
android
open ViewParent
android
Any
getTag(key: Int)
android
open Int
@ViewDebug.ExportedProperty(category = "text", mapping = [@ViewDebug.IntToString(from = 0, to = "INHERIT"), @ViewDebug.IntToString(from = 1, to = "GRAVITY"), @ViewDebug.IntToString(from = 2, to = "TEXT_START"), @ViewDebug.IntToString(from = 3, to = "TEXT_END"), @ViewDebug.IntToString(from = 4, to = "CENTER"), @ViewDebug.IntToString(from = 5, to = "VIEW_START"), @ViewDebug.IntToString(from = 6, to = "VIEW_END")])
getTextAlignment()
android
open Int
@ViewDebug.ExportedProperty(category = "text", mapping = [@ViewDebug.IntToString(from = 0, to = "INHERIT"), @ViewDebug.IntToString(from = 1, to = "FIRST_STRONG"), @ViewDebug.IntToString(from = 2, to = "ANY_RTL"), @ViewDebug.IntToString(from = 3, to = "LTR"), @ViewDebug.IntToString(from = 4, to = "RTL"), @ViewDebug.IntToString(from = 5, to = "LOCALE"), @ViewDebug.IntToString(from = 6, to = "FIRST_STRONG_LTR"), @ViewDebug.IntToString(from = 7, to = "FIRST_STRONG_RTL")])
getTextDirection()
android
Unit
android
Boolean
android
Boolean
android
Boolean
android
Boolean
android
Boolean
android
Boolean
android
Boolean
android
Boolean
android
Unit
android
Unit
invalidate(dirty: Rect)
android
Unit
invalidate(l: Int, t: Int, r: Int, b: Int)
android
Unit
android
Unit
android
open Boolean
android
open Boolean
android
open Boolean
android
open Boolean
android
Boolean
android
open View
keyboardNavigationClusterSearch(currentCluster: View, direction: Int)
android
Unit
measure(widthMeasureSpec: Int, heightMeasureSpec: Int)
android
Unit
android
Unit
android
Unit
android
Unit
android
WindowInsets
android
Unit
android
Boolean
android
Boolean
android
Unit
android
Unit
android
InputConnection
android
Unit
onCreateViewTranslationRequest(
    supportedFormats: IntArray,
    requestsCollector: Consumer<ViewTranslationRequest>
)
android
Unit
onCreateVirtualViewTranslationRequests(
    virtualIds: LongArray,
    supportedFormats: IntArray,
    requestsCollector: Consumer<ViewTranslationRequest>
)
android
Unit
android
Boolean
android
Unit
onDraw(canvas: Canvas)
android
Unit
android
Unit
android
Boolean
android
Unit
android
Unit
android
Unit
onFocusChanged(
    gainFocus: Boolean,
    direction: Int,
    previouslyFocusedRect: Rect?
)
android
Boolean
android
Unit
android
Boolean
android
Unit
android
Unit
android
Boolean
onKeyDown(keyCode: Int, event: KeyEvent)
android
Boolean
onKeyLongPress(keyCode: Int, event: KeyEvent)
android
Boolean
onKeyMultiple(keyCode: Int, repeatCount: Int, event: KeyEvent)
android
Boolean
onKeyPreIme(keyCode: Int, event: KeyEvent)
android
Boolean
onKeyShortcut(keyCode: Int, event: KeyEvent)
android
Boolean
onKeyUp(keyCode: Int, event: KeyEvent)
android
Unit
onOverScrolled(
    scrollX: Int,
    scrollY: Int,
    clampedX: Boolean,
    clampedY: Boolean
)
android
Unit
android
Unit
android
Unit
android
Unit
android
Unit
android
Unit
android
Unit
android
ContentInfo?
android
Unit
android
Parcelable?
android
Unit
onScreenStateChanged(screenState: Int)
android
Unit
onScrollCaptureSearch(
    localVisibleRect: Rect,
    windowOffset: Point,
    targets: Consumer<ScrollCaptureTarget>
)
android
Unit
onScrollChanged(l: Int, t: Int, oldl: Int, oldt: Int)
android
Boolean
onSetAlpha(alpha: Int)
android
Unit
onSizeChanged(w: Int, h: Int, oldw: Int, oldh: Int)
android
Unit
android
Boolean
android
Boolean
android
Unit
android
Unit
android
Unit
android
Unit
onVisibilityChanged(changedView: View, visibility: Int)
android
Unit
onWindowFocusChanged(hasWindowFocus: Boolean)
android
Unit
android
Unit
android
Boolean
overScrollBy(
    deltaX: Int,
    deltaY: Int,
    scrollX: Int,
    scrollY: Int,
    scrollRangeX: Int,
    scrollRangeY: Int,
    maxOverScrollX: Int,
    maxOverScrollY: Int,
    isTouchEvent: Boolean
)
android
Boolean
performAccessibilityAction(action: Int, arguments: Bundle?)
android
Boolean
android
Boolean
android
Boolean
android
Boolean
performHapticFeedback(feedbackConstant: Int)
android
Boolean
android
Boolean
performHapticFeedback(feedbackConstant: Int, flags: Int)
android
Boolean
android
Boolean
android
ContentInfo?
android
Unit
playSoundEffect(soundConstant: Int)
android
Boolean
post(action: Runnable)
android
Boolean
postDelayed(action: Runnable, delayMillis: Long)
android
Unit
android
Unit
postInvalidate(left: Int, top: Int, right: Int, bottom: Int)
android
Unit
postInvalidateDelayed(delayMilliseconds: Long)
android
Unit
postInvalidateDelayed(
    delayMilliseconds: Long,
    left: Int,
    top: Int,
    right: Int,
    bottom: Int
)
android
Unit
android
Unit
postInvalidateOnAnimation(left: Int, top: Int, right: Int, bottom: Int)
android
Unit
android
Unit
postOnAnimationDelayed(action: Runnable, delayMillis: Long)
android
Unit
android
Unit
android
Boolean
android
Unit
android
Unit
android
Unit
android
Unit
android
Unit
android
open Unit

This function is deprecated. Deprecated in Java

android
Boolean
android
Boolean
requestFocus(direction: Int)
android
Boolean
android
open Unit
android
Unit
android
Unit
android
Boolean
android
Boolean
requestRectangleOnScreen(rectangle: Rect, immediate: Boolean)
android
Boolean
requestRectangleOnScreen(rectangle: Rect, immediate: Boolean, source: Int)
android
Unit
android
Unit
android
T
<T : View> requireViewById(id: Int)
android
Unit
android
Unit
android
Unit
saveAttributeDataForStyleable(
    context: Context,
    styleable: IntArray,
    attrs: AttributeSet?,
    t: TypedArray,
    defStyleAttr: Int,
    defStyleRes: Int
)
android
Unit
android
Unit
scheduleDrawable(who: Drawable, what: Runnable, when: Long)
android
Unit
scrollBy(x: Int, y: Int)
android
Unit
scrollTo(x: Int, y: Int)
android
Unit
android
Unit
android
Unit
setAccessibilityDataSensitive(accessibilityDataSensitive: Int)
android
Unit
setAllowClickWhenDisabled(clickableWhenDisabled: Boolean)
android
Unit
android
Unit
android
Unit
setAutofillHints(vararg autofillHints: String)
android
Unit
android
Unit
android
Unit
android
Unit
android
Unit
setHandwritingBoundsOffsets(
    offsetLeft: Float,
    offsetTop: Float,
    offsetRight: Float,
    offsetBottom: Float
)
android
Unit
setHasTransientState(hasTransientState: Boolean)
android
Unit
setIsCredential(isCredential: Boolean)
android
Unit
setIsHandwritingDelegate(isHandwritingDelegate: Boolean)
android
Unit
android
Unit
setLayerType(layerType: Int, paint: Paint?)
android
Unit
setLeftTopRightBottom(left: Int, top: Int, right: Int, bottom: Int)
android
Unit
setMeasuredDimension(measuredWidth: Int, measuredHeight: Int)
android
Unit
android
Unit
android
Unit
android
Unit
android
Unit
android
Unit
android
Unit
android
Unit
android
Unit
android
Unit
android
Unit
setOnReceiveContentListener(
    mimeTypes: Array<String>?,
    listener: OnReceiveContentListener?
)
android
Unit
android
Unit
android
Unit
android
Unit
setPadding(left: Int, top: Int, right: Int, bottom: Int)
android
Unit
setPaddingRelative(start: Int, top: Int, end: Int, bottom: Int)
android
Unit
android
Unit
setRenderEffect(renderEffect: RenderEffect?)
android
Unit
android
Unit
setScrollIndicators(indicators: Int, mask: Int)
android
Unit
setTag(key: Int, tag: Any)
android
Unit
android
Unit
android
Unit
setWillNotCacheDrawing(willNotCacheDrawing: Boolean)
android
Unit
setWillNotDraw(willNotDraw: Boolean)
android
Boolean
android
Boolean
android
ActionMode
android
ActionMode
android
Unit
android
Boolean
startDrag(
    data: ClipData,
    shadowBuilder: View.DragShadowBuilder,
    myLocalState: Any,
    flags: Int
)
android
Boolean
startDragAndDrop(
    data: ClipData,
    shadowBuilder: View.DragShadowBuilder,
    myLocalState: Any,
    flags: Int
)
android
Boolean
android
Unit
android
open String
android
Unit
android
Unit
android
Unit
android
Unit
android
Unit
android
Boolean
android
Boolean
android
Boolean
android
From android.view.ViewGroup
Unit
android
Unit
addExtraDataToAccessibilityNodeInfo(
    info: AccessibilityNodeInfo,
    extraDataKey: String,
    arguments: Bundle?
)
android
Unit
addFocusables(views: ArrayList<View>, direction: Int, focusableMode: Int)
android
Unit
addKeyboardNavigationClusters(
    views: MutableCollection<View>,
    direction: Int
)
android
Boolean
android
Unit
android
Unit
attachLayoutAnimationParameters(
    child: View,
    params: ViewGroup.LayoutParams,
    index: Int,
    count: Int
)
android
Unit
attachViewToParent(child: View, index: Int, params: ViewGroup.LayoutParams)
android
Unit
android
Boolean
android
Boolean
android
Unit
android
Unit
childHasTransientStateChanged(
    child: View,
    childHasTransientState: Boolean
)
android
Unit
android
Unit
android
Unit
android
Unit
android
Unit
debug(depth: Int)
android
Unit
android
Unit
android
Unit
android
Unit
detachViewsFromParent(start: Int, count: Int)
android
WindowInsets
android
Boolean
android
Unit
android
Unit
dispatchCreateViewTranslationRequest(
    viewIds: MutableMap<AutofillIdLongArray>,
    supportedFormats: IntArray,
    capability: TranslationCapability,
    requests: MutableList<ViewTranslationRequest>
)
android
Unit
android
Boolean
android
Unit
android
Unit
android
Unit
android
Unit
android
Boolean
android
Boolean
android
Boolean
android
Boolean
android
Boolean
android
Boolean
android
Unit
android
Unit
android
Unit
android
Unit
android
Unit
android
Unit
dispatchScrollCaptureSearch(
    localVisibleRect: Rect,
    windowOffset: Point,
    targets: Consumer<ScrollCaptureTarget>
)
android
Unit
android
Unit
android
Unit
android
Unit
android
Unit
android
Unit
android
Boolean
android
Boolean
android
Boolean
dispatchUnhandledMove(focused: View, direction: Int)
android
Unit
dispatchVisibilityChanged(changedView: View, visibility: Int)
android
Unit
android
Unit
android
Unit
android
WindowInsets
android
WindowInsetsAnimation.Bounds
android
Unit
android
Unit
android
Boolean
drawChild(canvas: Canvas, child: View, drawingTime: Long)
android
Unit
android
Unit
android
View
android
OnBackInvokedDispatcher?
android
Unit
findViewsWithText(
    outViews: ArrayList<View>,
    text: CharSequence,
    flags: Int
)
android
View
focusSearch(focused: View, direction: Int)
android
Unit
android
Boolean
android
ViewGroup.LayoutParams
android
ViewGroup.LayoutParams
android
ViewGroup.LayoutParams
android
View
getChildAt(index: Int)
android
Int
getChildDrawingOrder(drawingPosition: Int)
android
Int
getChildDrawingOrder(childCount: Int, drawingPosition: Int)
android
Boolean
android
Boolean
getChildVisibleRect(child: View, r: Rect, offset: Point)
android
Boolean
android
Boolean
android
Int
android
Unit
invalidateChild(child: View, dirty: Rect)
android
ViewParent
invalidateChildInParent(location: IntArray, dirty: Rect)
android
Unit
android
Unit
layout(l: Int, t: Int, r: Int, b: Int)
android
Unit
measureChild(
    child: View,
    parentWidthMeasureSpec: Int,
    parentHeightMeasureSpec: Int
)
android
Unit
measureChildWithMargins(
    child: View,
    parentWidthMeasureSpec: Int,
    widthUsed: Int,
    parentHeightMeasureSpec: Int,
    heightUsed: Int
)
android
Unit
measureChildren(widthMeasureSpec: Int, heightMeasureSpec: Int)
android
Unit
notifySubtreeAccessibilityStateChanged(
    child: View,
    source: View,
    changeType: Int
)
android
Unit
android
Unit
android
IntArray
android
Unit
onDescendantInvalidated(child: View, target: View)
android
Unit
android
Boolean
android
Boolean
android
Boolean
onNestedFling(
    target: View,
    velocityX: Float,
    velocityY: Float,
    consumed: Boolean
)
android
Boolean
onNestedPreFling(target: View, velocityX: Float, velocityY: Float)
android
Boolean
onNestedPrePerformAccessibilityAction(
    target: View,
    action: Int,
    args: Bundle?
)
android
Unit
onNestedPreScroll(target: View, dx: Int, dy: Int, consumed: IntArray)
android
Unit
onNestedScroll(
    target: View,
    dxConsumed: Int,
    dyConsumed: Int,
    dxUnconsumed: Int,
    dyUnconsumed: Int
)
android
Unit
onNestedScrollAccepted(child: View, target: View, axes: Int)
android
Boolean
onRequestFocusInDescendants(direction: Int, previouslyFocusedRect: Rect)
android
Boolean
android
PointerIcon
onResolvePointerIcon(event: MotionEvent, pointerIndex: Int)
android
Boolean
onStartNestedScroll(child: View, target: View, nestedScrollAxes: Int)
android
Unit
android
Unit
onViewAdded(child: View)
android
Unit
android
Unit
propagateRequestedFrameRate(frameRate: Float, forceOverride: Boolean)
android
Unit
android
Unit
android
Unit
android
Unit
removeDetachedView(child: View, animate: Boolean)
android
Unit
android
Unit
removeViewAt(index: Int)
android
Unit
android
Unit
removeViews(start: Int, count: Int)
android
Unit
removeViewsInLayout(start: Int, count: Int)
android
Unit
requestChildFocus(child: View, focused: View)
android
Boolean
requestChildRectangleOnScreen(
    child: View,
    rectangle: Rect,
    immediate: Boolean
)
android
Unit
android
Boolean
requestFocus(direction: Int, previouslyFocusedRect: Rect)
android
Boolean
android
Unit
android
Boolean
android
Unit
android
Unit
android
Unit
android
Unit
android
Unit
android
Unit
android
Boolean
android
Boolean
showContextMenuForChild(originalView: View, x: Float, y: Float)
android
ActionMode
startActionModeForChild(
    originalView: View,
    callback: ActionMode.Callback
)
android
ActionMode
startActionModeForChild(
    originalView: View,
    callback: ActionMode.Callback,
    type: Int
)
android
Unit
android
Unit
android
Unit
android
Unit
android
From android.view.ViewParent
Boolean
requestChildRectangleOnScreen(
    child: View,
    rectangle: Rect,
    immediate: Boolean,
    source: Int
)
android

Inherited properties

From android.view.View
open View.AccessibilityDelegate
android
open Int
android
open AccessibilityNodeProvider
android
open CharSequence?
android
open Int
android
open Int
android
open String?
android
open String?
android
open Float
android
open Animation
android
open Matrix?
android
open IBinder
android
open MutableMap<IntInt>
android
open Array<String>?
android
AutofillId
android
open Int
android
open AutofillValue?
android
open Drawable
android
open BlendMode?
android
open ColorStateList?
android
open PorterDuff.Mode?
android
open Int
android
Int
android
open Float
android
open Int
android
open Float
android
open Rect
android
Boolean
android
ContentCaptureSession?
android
open CharSequence
android
Int
android
Context
android
open ContextMenu.ContextMenuInfo
android
Boolean
android
open Display
android
IntArray
android
open Bitmap
android
open Int
android
open Int
android
open Long
android
open Float
android
open Int
android
open Boolean
android
open Boolean
android
open Int
android
open Drawable
android
open Int
android
open BlendMode?
android
open ColorStateList?
android
open PorterDuff.Mode?
android
open Float
android
open Handler
android
open Float
android
open Float
android
open Float
android
open Float
android
open Int
android
open Runnable?
android
Boolean
android
Int
android
open Int
android
open Int
android
open Drawable?
android
open Drawable?
android
open Int
android
open Int
android
open Int
android
open Int
android
open Boolean
android
open Boolean
android
open Boolean
android
open Boolean
android
open Boolean
android
open Boolean
android
open Boolean
android
Boolean
android
open Boolean
android
open Boolean
android
open Boolean
android
open Boolean
android
open Boolean
android
open Boolean
android
Boolean
android
Boolean
android
open Boolean
android
Boolean
android
open Boolean
android
open Boolean
android
open Boolean
android
open Boolean
android
open Boolean
android
open Boolean
android
open Boolean
android
open Boolean
android
Boolean
android
Boolean
android
open Boolean
android
open Boolean
android
open Boolean
android
Boolean
android
open Boolean
android
open Boolean
android
open Boolean
android
open Boolean
android
open Boolean
android
open Boolean
android
open Boolean
android
open Boolean
android
open Boolean
android
Boolean
android
open Boolean
android
open Boolean
android
open Boolean
android
open Boolean
android
open Boolean
android
open Boolean
android
open Boolean
android
Boolean
android
open Boolean
android
open Boolean
android
Boolean
android
open Boolean
android
open Boolean
android
open Boolean
android
open Boolean
android
open Boolean
android
open KeyEvent.DispatcherState
android
open Int
android
open Int
android
open Int
android
open ViewGroup.LayoutParams
android
Int
android
open Float
android
open Int
android
open Matrix
android
Int
android
Int
android
Int
android
Int
android
Int
android
open Int
android
open Int
android
open Int
android
open Int
android
open Int
android
open Int
android
open Int
android
open Int
android
open View.OnFocusChangeListener
android
open Int
android
open ViewOutlineProvider
android
open Int
android
open Int
android
open Int
android
open Int
android
open Int
android
open Int
android
open Int
android
open Int
android
final ViewParent
android
open ViewParent
android
OutcomeReceiver<GetCredentialResponseGetCredentialException>?
android
GetCredentialRequest?
android
open Float
android
open Float
android
open PointerIcon
android
MutableList<Rect>
android
open Array<String>?
android
open Float
android
open Resources
android
Boolean
android
Int
android
open Float
android
open Int
android
open AttachedSurfaceControl?
android
open View
android
open WindowInsets
android
open Float
android
open Float
android
open Float
android
open Float
android
open Float
android
open Int
android
open Int
android
open Int
android
open Int
android
open Int
android
open Int
android
Int
android
Int
android
open Int
android
open Int
android
CharSequence?
android
open StateListAnimator
android
open Int
android
open Int
android
open CharSequence?
android
open MutableList<Rect>
android
open Int
android
open Any
android
open Int
android
open Int
android
open CharSequence?
android
Int
android
open Float
android
open Int
android
open TouchDelegate
android
open ArrayList<View>
android
open Float
android
open String
android
open Float
android
open Float
android
open Float
android
open Long
android
open Int
android
open Int
android
open Drawable?
android
open Drawable?
android
open Int
android
open ViewTranslationResponse?
android
open ViewTreeObserver
android
open Int
android
Int
android
open Int
android
open WindowId
android
open WindowInsetsController?
android
open Int
android
open IBinder
android
open Int
android
open Float
android
open Float
android
open Float
android
From android.view.ViewGroup

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.

addView

open fun addView(child: View?): Unit

addView

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

addView

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

addView

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

addView

open fun addView(child: View?, width: Int, height: Int): 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 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.

For best results in composing while the ComposeView isn't attached, use the version of this with ComposeViewContext as an argument.

createComposition

fun createComposition(composeViewContext: ComposeViewContext): Unit

Perform initial composition for this view, even if this view isn't attached to the hierarchy. If the view is never attached to the hierarchy, disposeComposition must be called for the composition to be cleaned up properly. If the view is attached to the hierarchy after createComposition, detaching it will clean up the composition, so calling disposeComposition is unnecessary.

If this method is called when the composition has already been created, it will update the composeViewContext being used for the composition.

The composeViewContext values override any previously set setParentCompositionContext value. The composeViewContext values are used for all composition information, including LifecycleOwner, SavedStateRegistryOwner, and window information pulled from the ComposeViewContext's attached View.

import androidx.compose.material.Text
import androidx.compose.ui.platform.ComposeView
import androidx.compose.ui.platform.ComposeViewContext

// The developer will call this when the user is expected to need to see this content within
// a few frames. It allows the content to be composed before it is shown. When it is attached
// to the hierarchy, the composition will have been complete, so it only needs to be laid out
// and drawn.
fun prefetchComposeViewContent(
    context: Context,
    composeViewContext: ComposeViewContext,
): ComposeView {
    val composeView = ComposeView(context)
    composeView.setContent {
        // Sample content
        Text("This is composed without being attached to hierarchy")
    }
    // Start composing right now
    composeView.createComposition(composeViewContext)
    // The composeView can be attached to the hierarchy when it is needed.
    return composeView
}
Parameters
composeViewContext: ComposeViewContext

The ComposeViewContext to use for the composition. The ComposeViewContext.view must be attached to the hierarchy.

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.

isTransitionGroup

open fun isTransitionGroup(): Boolean

onRtlPropertiesChanged

open fun onRtlPropertiesChanged(layoutDirection: Int): Unit

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.

setTransitionGroup

open fun setTransitionGroup(isTransitionGroup: Boolean): Unit

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.

shouldDelayChildPressedState

open fun shouldDelayChildPressedState(): Boolean

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

onAttachedToWindow

protected open fun onAttachedToWindow(): Unit

onLayout

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

onMeasure

protected final fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int): Unit

Public properties

autoClearFocusBehavior

var autoClearFocusBehaviorAutoClearFocusBehavior

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 hasCompositionBoolean

true if this View is host to an active Compose UI composition. An active composition may consume resources.

isTransitionGroup

open var isTransitionGroupBoolean

showLayoutBounds

@InternalComposeUiApi
var showLayoutBoundsBoolean

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 shouldCreateCompositionOnAttachedToWindowBoolean

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

AbstractComposeView.consumeWindowInsets

var AbstractComposeView.consumeWindowInsetsBoolean

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.