The second Android 11 Developer Preview is now available, test it out and share your feedback.

AndroidComposeView

class AndroidComposeView : ViewGroup, AndroidOwner, SemanticsTreeProvider
kotlin.Any
   ↳ android.view.View
   ↳ android.view.ViewGroup
   ↳ androidx.ui.core.AndroidComposeView

Summary

Public constructors

<init>(context: Context)

Public methods

Unit
addAndroidView(view: View, layoutNode: LayoutNode)

Called to inform the owner that a new Android View was attached to the hierarchy.

Unit

IntPxPosition

Returns the most global position of the owner that Compose can access (such as the device screen).

Unit
callDraw(canvas: Canvas, node: ComponentNode, parentSize: PxSize)

Causes the node to draw into canvas.

OwnedLayer
createLayer(drawLayerModifier: DrawLayerModifier, drawBlock: (Canvas, Density) -> Unit)

Creates and returns an OwnedLayer for the given drawLayerModifier.

List<SemanticsNode>

Returns all (merged) SemanticsNodes in the tree represented by this SemanticsTreeProvider

Unit

Iterates through all LayoutNodes that have requested layout and measures and lays them out

Unit

Observe model reads during draw of node, executed in block.

Unit
observeLayerModelReads(layer: OwnedLayer, block: () -> Unit)

Unit
observeLayoutModelReads(node: LayoutNode, block: () -> Unit)

Observe model reads during layout of node, executed in block.

Unit
observeMeasureModelReads(node: LayoutNode, block: () -> Unit)

Observe model reads during measure of node, executed in block.

Unit

Called by ComponentNode when it is attached to the view system and now has an owner.

Boolean

InputConnection?

Unit

Called by ComponentNode when it is detached from the view system, such as during ComponentNode.removeAt.

Unit

Called from a DrawNode, this registers with the underlying view system that a redraw of the given drawNode is required.

Unit
onInvalidate(layoutNode: LayoutNode)

Called from a LayoutNode, this registers with the underlying view system that a redraw of the given layoutNode is required.

Unit

Called by LayoutNode to indicate the new position of layoutNode.

Unit

Unit

Called when some params of RepaintBoundaryNode are updated.

Unit

Called by LayoutNode to request the Owner a new measurement+layout.

Unit
onSizeChange(layoutNode: LayoutNode)

Called by LayoutNode to indicate the new size of layoutNode.

Boolean

Unit

Observing the model reads are temporary disabled during the block execution.

Unit

Called to inform the owner that an Android View was detached from the hierarchy.

Unit

Protected methods

Unit

Unit

Unit

Unit

Unit
onDraw(canvas: Canvas)

Unit
onLayout(changed: Boolean, l: Int, t: Int, r: Int, b: 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.ui.core.android.view.ViewGroup
Unit

Disposes of a composition of the children of this 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.

From androidx.ui.node.android.view.View
T
View.getOrAddAdapter(id: Int, factory: () -> T)

Properties

Autofill?

AutofillTree

() -> Unit

Constraints

Density

Font.ResourceLoader

HapticFeedback

Provide haptic feedback to the user.

Long

Ref<AndroidComposeView>?

LayoutNode

SemanticsOwner

Boolean

true when layout should draw debug bounds.

TextInputService

Companion properties

Boolean

Enables additional (and expensive to do in production) assertions.

Public constructors

<init>

AndroidComposeView(context: Context)

Public methods

addAndroidView

fun addAndroidView(
    view: View,
    layoutNode: LayoutNode
): Unit

Called to inform the owner that a new Android View was attached to the hierarchy.

autofill

fun autofill(values: SparseArray<AutofillValue>): Unit

calculatePosition

fun calculatePosition(): IntPxPosition

Returns the most global position of the owner that Compose can access (such as the device screen).

callDraw

fun callDraw(
    canvas: Canvas,
    node: ComponentNode,
    parentSize: PxSize
): Unit

Causes the node to draw into canvas.

createLayer

fun createLayer(
    drawLayerModifier: DrawLayerModifier,
    drawBlock: (Canvas, Density) -> Unit
): OwnedLayer

Creates and returns an OwnedLayer for the given drawLayerModifier.

getAllSemanticNodes

fun getAllSemanticNodes(): List<SemanticsNode>

Returns all (merged) SemanticsNodes in the tree represented by this SemanticsTreeProvider

measureAndLayout

fun measureAndLayout(): Unit

Iterates through all LayoutNodes that have requested layout and measures and lays them out

observeDrawModelReads

fun observeDrawModelReads(
    node: RepaintBoundaryNode,
    block: () -> Unit
): Unit

Observe model reads during draw of node, executed in block.

observeLayerModelReads

fun observeLayerModelReads(
    layer: OwnedLayer,
    block: () -> Unit
): Unit

observeLayoutModelReads

fun observeLayoutModelReads(
    node: LayoutNode,
    block: () -> Unit
): Unit

Observe model reads during layout of node, executed in block.

observeMeasureModelReads

fun observeMeasureModelReads(
    node: LayoutNode,
    block: () -> Unit
): Unit

Observe model reads during measure of node, executed in block.

onAttach

fun onAttach(node: ComponentNode): Unit

Called by ComponentNode when it is attached to the view system and now has an owner. This is used by Owner to update ComponentNode.ownerData and track which nodes are associated with it. It will only be called when node is not already attached to an owner.

onCheckIsTextEditor

fun onCheckIsTextEditor(): Boolean

onCreateInputConnection

fun onCreateInputConnection(outAttrs: EditorInfo): InputConnection?

onDetach

fun onDetach(node: ComponentNode): Unit

Called by ComponentNode when it is detached from the view system, such as during ComponentNode.removeAt. This will only be called for nodes that are already ComponentNode.attached.

onInvalidate

fun onInvalidate(drawNode: DrawNode): Unit

Called from a DrawNode, this registers with the underlying view system that a redraw of the given drawNode is required. It may cause other nodes to redraw, if necessary.

onInvalidate

fun onInvalidate(layoutNode: LayoutNode): Unit

Called from a LayoutNode, this registers with the underlying view system that a redraw of the given layoutNode is required. It may cause other nodes to redraw, if necessary. Note that LayoutNodes are able to draw due to draw modifiers applied to them.

onPositionChange

fun onPositionChange(layoutNode: LayoutNode): Unit

Called by LayoutNode to indicate the new position of layoutNode. The owner may need to track updated layouts.

onProvideAutofillVirtualStructure

fun onProvideAutofillVirtualStructure(
    structure: ViewStructure?,
    flags: Int
): Unit

onRepaintBoundaryParamsChange

fun onRepaintBoundaryParamsChange(repaintBoundaryNode: RepaintBoundaryNode): Unit

Called when some params of RepaintBoundaryNode are updated. This is not causing re-recording of the RepaintBoundary, but updates params like outline, clipping, elevation or alpha.

onRequestMeasure

fun onRequestMeasure(layoutNode: LayoutNode): Unit

Called by LayoutNode to request the Owner a new measurement+layout.

onSizeChange

fun onSizeChange(layoutNode: LayoutNode): Unit

Called by LayoutNode to indicate the new size of layoutNode. The owner may need to track updated layouts.

onTouchEvent

fun onTouchEvent(event: MotionEvent): Boolean

pauseModelReadObserveration

fun pauseModelReadObserveration(block: () -> Unit): Unit

Observing the model reads are temporary disabled during the block execution. For example if we are currently within the measure stage and we want some code block to be skipped from the observing we disable if before calling the block, execute block and then enable it again.

removeAndroidView

fun removeAndroidView(view: View): Unit

Called to inform the owner that an Android View was detached from the hierarchy.

sendEvent

fun sendEvent(event: MotionEvent): Unit

Protected methods

dispatchDraw

protected fun dispatchDraw(canvas: Canvas): Unit

onAttachedToWindow

protected fun onAttachedToWindow(): Unit

onConfigurationChanged

protected fun onConfigurationChanged(newConfig: Configuration?): Unit

onDetachedFromWindow

protected fun onDetachedFromWindow(): Unit

onDraw

protected fun onDraw(canvas: Canvas): Unit

onLayout

protected fun onLayout(
    changed: Boolean,
    l: Int,
    t: Int,
    r: Int,
    b: Int
): Unit

onMeasure

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

Properties

autofill

val autofill: Autofill?

autofillTree

val autofillTree: AutofillTree

configurationChangeObserver

var configurationChangeObserver: () -> Unit

constraints

var constraints: Constraints

density

var density: Density

fontLoader

val fontLoader: Font.ResourceLoader

hapticFeedBack

val hapticFeedBack: HapticFeedback

Provide haptic feedback to the user. Use the Android version of haptic feedback.

measureIteration

var measureIteration: Long

ref

var ref: Ref<AndroidComposeView>?

root

val root: LayoutNode

semanticsOwner

val semanticsOwner: SemanticsOwner

showLayoutBounds

var showLayoutBounds: Boolean

true when layout should draw debug bounds.

textInputService

val textInputService: TextInputService

Companion properties

enableExtraAssertions

var enableExtraAssertions: Boolean

Enables additional (and expensive to do in production) assertions. Useful to be set to true during the tests covering our core logic.