Join us for ⁠#Android11: The Beta Launch Show on June 3!

LayoutNode

class LayoutNode : Measurable
kotlin.Any
   ↳ androidx.ui.core.LayoutNode

The base type for all nodes from the tree generated from a component hierarchy.

Specific components are backed by a tree of nodes: Draw, Layout, GestureDetector. All other components are not represented in the backing hierarchy.

Summary

Nested classes

abstract

abstract

Public constructors

The base type for all nodes from the tree generated from a component hierarchy.

Public methods

Unit
attach(owner: Owner)

Set the Owner of this LayoutNode.

Unit

Remove the LayoutNode from the Owner.

Unit
draw(canvas: Canvas)

IntPx?

Returns the alignment line value for a given alignment line without affecting whether the flag for whether the alignment line was read.

List<ModifierInfo>

This returns a new List of Modifiers and the coordinates and any extra information that may be useful.

Boolean
hitTest(pointerPositionRelativeToScreen: PxPosition, hitPointerInputFilters: MutableList<PointerInputFilter>)

Carries out a hit test on the PointerInputModifiers associated with this LayoutNode and all PointerInputModifiers on all descendant LayoutNodes.

Unit
ignoreModelReads(block: () -> Unit)

Execute your code within the block if you want some code to not be observed for the model reads even if you are currently inside some observed scope like measuring.

Unit
insertAt(index: Int, instance: LayoutNode)

Inserts a child LayoutNode at a particular index.

Unit

IntPx
maxIntrinsicHeight(width: IntPx, layoutDirection: LayoutDirection)

Calculates the smallest height beyond which increasing the height never decreases the width.

IntPx
maxIntrinsicWidth(height: IntPx, layoutDirection: LayoutDirection)

Calculates the smallest width beyond which increasing the width never decreases the height.

Placeable
measure(constraints: Constraints, layoutDirection: LayoutDirection)

Measures the layout with constraints and a layoutDirection, returning a Placeable layout that has its new size.

IntPx
minIntrinsicHeight(width: IntPx, layoutDirection: LayoutDirection)

Calculates the minimum height that the layout can be such that the content of the layout will be painted correctly.

IntPx
minIntrinsicWidth(height: IntPx, layoutDirection: LayoutDirection)

Calculates the minimum width that the layout can be such that the content of the layout will be painted correctly.

Unit
move(from: Int, to: Int, count: Int)

Moves count elements starting at index from to index to.

Unit

Used to request a new draw pass from the owner.

Unit
place(x: IntPx, y: IntPx)

Unit
removeAt(index: Int, count: Int)

Removes one or more children, starting at index.

Unit

Used to request a new measurement + layout pass from the owner.

String

Extension functions

From androidx.ui.core
LayoutNode?

Executes selector on every parent of this LayoutNode and returns the closest LayoutNode to return true from selector or null if selector returns false for all ancestors.

Properties

Boolean

true when the parent's size depends on this LayoutNode's size

Boolean

List<LayoutNode>

The children of this LayoutNode, controlled by insertAt, move, and removeAt.

Constraints

The constraints used the last time layout was called.

LayoutCoordinates

Coordinates of just the contents of the LayoutNode, after being affected by all modifiers.

Int

The tree depth of the LayoutNode.

Boolean

IntPx

The measured height of this layout and all of its modifiers.

Boolean

true when inside layout

Boolean

true when inside measure

Boolean

Whether or not this has been placed in the hierarchy.

LayoutDirection

The layout direction of the layout node.

LayoutNode.MeasureBlocks

Blocks that define the measurement and intrinsic measurement of the layout.

MeasureScope

The scope used to run the MeasureBlocks.measure.

Modifier

The Modifier currently applied to this node.

Boolean

true when the layout has been measured or dirtied because the layout lambda accessed a model that has been dirtied.

Boolean

true when the layout has been dirtied by requestRemeasure.

(Owner) -> Unit

Callback to be executed whenever the LayoutNode is attached to a new Owner.

(Owner) -> Unit

Callback to be executed whenever the LayoutNode is detached from an Owner.

Owner?

The view system Owner.

LayoutNode?

The parent node in the LayoutNode hierarchy.

Any?

Data provided by the ParentData

Boolean

true when the current node is positioned during the measure pass, since it needs to compute alignment lines.

Ref<LayoutNode>?

Implementation oddity around composition; used to capture a reference to this LayoutNode when composed.

IntPx

The measured width of this layout and all of its modifiers.

Inherited extension properties

From androidx.ui.core
Any?

Retrieves the tag associated to a composable with the LayoutTag modifier.

Public constructors

<init>

LayoutNode()

The base type for all nodes from the tree generated from a component hierarchy.

Specific components are backed by a tree of nodes: Draw, Layout, GestureDetector. All other components are not represented in the backing hierarchy.

Public methods

attach

fun attach(owner: Owner): Unit

Set the Owner of this LayoutNode. This LayoutNode must not already be attached. owner must match its parent.owner.

detach

fun detach(): Unit

Remove the LayoutNode from the Owner. The owner must not be null before this call and its parent's owner must be null before calling this. This will also detach all children. After executing, the owner will be null.

draw

fun draw(canvas: Canvas): Unit

getAlignmentLine

fun getAlignmentLine(line: AlignmentLine): IntPx?

Returns the alignment line value for a given alignment line without affecting whether the flag for whether the alignment line was read.

getModifierInfo

fun getModifierInfo(): List<ModifierInfo>

This returns a new List of Modifiers and the coordinates and any extra information that may be useful. This is used for tooling to retrieve layout modifier and layer information.

hitTest

fun hitTest(
    pointerPositionRelativeToScreen: PxPosition,
    hitPointerInputFilters: MutableList<PointerInputFilter>
): Boolean

Carries out a hit test on the PointerInputModifiers associated with this LayoutNode and all PointerInputModifiers on all descendant LayoutNodes.

If pointerPositionRelativeToScreen is within the bounds of any tested PointerInputModifiers, the PointerInputModifier is added to hitPointerInputFilters and true is returned.

Parameters
pointerPositionRelativeToScreen: PxPosition The tested pointer position, which is relative to the device screen.
hitPointerInputFilters: MutableList<PointerInputFilter> The collection that the hit PointerInputFilters will be added to if hit.
Return
True if any PointerInputFilters were hit and thus added to hitPointerInputFilters.

ignoreModelReads

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

Execute your code within the block if you want some code to not be observed for the model reads even if you are currently inside some observed scope like measuring.

insertAt

fun insertAt(
    index: Int,
    instance: LayoutNode
): Unit

Inserts a child LayoutNode at a particular index. If this LayoutNode owner is not null then instance will become attached also. instance must have a null parent.

layout

fun layout(): Unit

maxIntrinsicHeight

fun maxIntrinsicHeight(
    width: IntPx,
    layoutDirection: LayoutDirection
): IntPx

Calculates the smallest height beyond which increasing the height never decreases the width.

maxIntrinsicWidth

fun maxIntrinsicWidth(
    height: IntPx,
    layoutDirection: LayoutDirection
): IntPx

Calculates the smallest width beyond which increasing the width never decreases the height.

measure

fun measure(
    constraints: Constraints,
    layoutDirection: LayoutDirection
): Placeable

Measures the layout with constraints and a layoutDirection, returning a Placeable layout that has its new size. A Measurable can only be measured once inside a layout pass.

minIntrinsicHeight

fun minIntrinsicHeight(
    width: IntPx,
    layoutDirection: LayoutDirection
): IntPx

Calculates the minimum height that the layout can be such that the content of the layout will be painted correctly.

minIntrinsicWidth

fun minIntrinsicWidth(
    height: IntPx,
    layoutDirection: LayoutDirection
): IntPx

Calculates the minimum width that the layout can be such that the content of the layout will be painted correctly.

move

fun move(
    from: Int,
    to: Int,
    count: Int
): Unit

Moves count elements starting at index from to index to. The to index is related to the position before the change, so, for example, to move an element at position 1 to after the element at position 2, from should be 1 and to should be 3. If the elements were LayoutNodes A B C D E, calling move(1, 3, 1) would result in the LayoutNodes being reordered to A C B D E.

onInvalidate

fun onInvalidate(): Unit

Used to request a new draw pass from the owner.

place

fun place(
    x: IntPx,
    y: IntPx
): Unit

removeAt

fun removeAt(
    index: Int,
    count: Int
): Unit

Removes one or more children, starting at index.

requestRemeasure

fun requestRemeasure(): Unit

Used to request a new measurement + layout pass from the owner.

toString

fun toString(): String

Properties

affectsParentSize

var affectsParentSize: Boolean

true when the parent's size depends on this LayoutNode's size

canMultiMeasure

var canMultiMeasure: Boolean

Deprecated.

children

val children: List<LayoutNode>

The children of this LayoutNode, controlled by insertAt, move, and removeAt.

constraints

var constraints: Constraints

The constraints used the last time layout was called.

coordinates

val coordinates: LayoutCoordinates

Coordinates of just the contents of the LayoutNode, after being affected by all modifiers.

depth

var depth: Int

The tree depth of the LayoutNode. This is valid only when owner is not null.

handlesParentData

var handlesParentData: Boolean

Deprecated.

height

val height: IntPx

The measured height of this layout and all of its modifiers. Shortcut for size.height.

isLayingOut

var isLayingOut: Boolean

true when inside layout

isMeasuring

var isMeasuring: Boolean

true when inside measure

isPlaced

var isPlaced: Boolean

Whether or not this has been placed in the hierarchy.

layoutDirection

var layoutDirection: LayoutDirection

The layout direction of the layout node.

measureBlocks

var measureBlocks: LayoutNode.MeasureBlocks

Blocks that define the measurement and intrinsic measurement of the layout.

measureScope

val measureScope: MeasureScope

The scope used to run the MeasureBlocks.measure.

modifier

var modifier: Modifier

The Modifier currently applied to this node.

needsRelayout

var needsRelayout: Boolean

true when the layout has been measured or dirtied because the layout lambda accessed a model that has been dirtied.

needsRemeasure

var needsRemeasure: Boolean

true when the layout has been dirtied by requestRemeasure. false after the measurement has been complete (place has been called).

onAttach

var onAttach: (Owner) -> Unit

Callback to be executed whenever the LayoutNode is attached to a new Owner.

onDetach

var onDetach: (Owner) -> Unit

Callback to be executed whenever the LayoutNode is detached from an Owner.

owner

var owner: Owner?

The view system Owner. This null until attach is called

parent

var parent: LayoutNode?

The parent node in the LayoutNode hierarchy. This is null when the LayoutNode is attached (has an owner) and is the root of the tree or has not had add called for it.

parentData

val parentData: Any?

Data provided by the ParentData

positionedDuringMeasurePass

var positionedDuringMeasurePass: Boolean

true when the current node is positioned during the measure pass, since it needs to compute alignment lines.

ref

var ref: Ref<LayoutNode>?

Implementation oddity around composition; used to capture a reference to this LayoutNode when composed. This is a reverse property that mutates its right-hand side.

width

val width: IntPx

The measured width of this layout and all of its modifiers. Shortcut for size.width.