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

Owner

interface Owner
androidx.ui.core.Owner

Owner implements the connection to the underlying view system. On Android, this connects to Android android.view.Views and all layout, draw, input, and accessibility is hooked through them.

Summary

Public methods

abstract IntPxPosition

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

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

Causes the node to draw into canvas.

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

Creates and returns an OwnedLayer for the given drawLayerModifier.

abstract Unit

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

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

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

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

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

abstract Unit

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

abstract Unit

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

abstract Unit

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

abstract Unit
onInvalidate(layoutNode: LayoutNode)

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

abstract Unit

Called by LayoutNode to indicate the new position of layoutNode.

abstract Unit

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

abstract Unit
onSizeChange(layoutNode: LayoutNode)

Called by LayoutNode to indicate the new size of layoutNode.

abstract Unit

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

abstract Boolean

Ask the system to provide focus to this owner.

abstract Unit

Allows other components to be notified when the UiSavedStateRegistry became available.

Properties

abstract Autofill?

The Autofill class can be used to perform autofill operations.

abstract AutofillTree

A data structure used to store autofill information.

abstract () -> Unit

Used for updating the ConfigurationAmbient when configuration changes - consume the configuration ambient instead of changing this observer if you are writing a component that adapts to configuration changes.

abstract Density

abstract Font.ResourceLoader

abstract HapticFeedback

Provide haptic feedback to the user.

abstract Long

abstract LayoutNode

The root layout node in the component tree.

abstract UiSavedStateRegistry?

The current instance of UiSavedStateRegistry.

abstract SemanticsOwner

abstract Boolean

true when layout should draw debug bounds.

abstract TextInputService

Companion properties

Boolean

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

Public methods

calculatePosition

abstract fun calculatePosition(): IntPxPosition

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

callDraw

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

Causes the node to draw into canvas.

createLayer

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

Creates and returns an OwnedLayer for the given drawLayerModifier.

measureAndLayout

abstract fun measureAndLayout(): Unit

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

observeLayoutModelReads

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

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

observeMeasureModelReads

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

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

onAttach

abstract 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.

onDetach

abstract 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

abstract 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

abstract 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

abstract fun onPositionChange(layoutNode: LayoutNode): Unit

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

onRequestMeasure

abstract fun onRequestMeasure(layoutNode: LayoutNode): Unit

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

onSizeChange

abstract fun onSizeChange(layoutNode: LayoutNode): Unit

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

pauseModelReadObserveration

abstract 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.

requestFocus

abstract fun requestFocus(): Boolean

Ask the system to provide focus to this owner.

Return
true if the system granted focus to this owner. False otherwise.

setOnSavedStateRegistryAvailable

abstract fun setOnSavedStateRegistryAvailable(callback: (UiSavedStateRegistry) -> Unit): Unit

Allows other components to be notified when the UiSavedStateRegistry became available.

Properties

autofill

abstract val autofill: Autofill?

The Autofill class can be used to perform autofill operations. It is used as an ambient.

autofillTree

abstract val autofillTree: AutofillTree

A data structure used to store autofill information. It is used by components that want to provide autofill semantics. TODO(ralu): Replace with SemanticsTree. This is a temporary hack until we have a semantics tree implemented.

configurationChangeObserver

abstract var configurationChangeObserver: () -> Unit

Used for updating the ConfigurationAmbient when configuration changes - consume the configuration ambient instead of changing this observer if you are writing a component that adapts to configuration changes.

density

abstract val density: Density

fontLoader

abstract val fontLoader: Font.ResourceLoader

hapticFeedBack

abstract val hapticFeedBack: HapticFeedback

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

measureIteration

abstract val measureIteration: Long

root

abstract val root: LayoutNode

The root layout node in the component tree.

savedStateRegistry

abstract val savedStateRegistry: UiSavedStateRegistry?

The current instance of UiSavedStateRegistry. If it's null you can wait for it to became available using setOnSavedStateRegistryAvailable.

semanticsOwner

abstract val semanticsOwner: SemanticsOwner

showLayoutBounds

abstract var showLayoutBounds: Boolean

true when layout should draw debug bounds.

textInputService

abstract 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.