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

androidx.ui.core

Classes

AlignmentLine

Defines an offset line that can be used by parent layouts to align and position their children.

AndroidComposeView

ComponentNode

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

Constraints

Immutable constraints used for measuring child Layouts.

ConsumedData

Describes what aspects of, and how much of, a change has been consumed.

DataNode

A ComponentNode that stores a value in the emitted hierarchy

DataNodeKey

The key used in DataNode.

DrawNode

Backing node for the Draw component.

FocusNode

Backing node that implements focus.

HorizontalAlignmentLine

A horizontal AlignmentLine.

LayoutNode

Backing node for Layout component.

LayoutTag

A ParentDataModifier which tags the target with the given tag.

MeasureScope

The receiver scope of a layout's measure lambda.

ModelObserver

Allows for easy model read observation.

MultiComposableMeasurables

A List of Measurables passed in as the argument to the Layout measureBlock when using the vararg variant.

Placeable

A Placeable corresponds to a child layout that can be positioned by its parent layout.

PointerId

An ID for a given pointer.

PointerInputChange

Describes a change that has occurred for a particular pointer, as well as how much of the change has been consumed (meaning, used by a node in the UI).

PointerInputData

Data associated with a pointer.

PointerInputNode

Backing node for handling pointer events.

PopupProperties

Ref

RepaintBoundaryNode

SemanticsComponentNode

VerticalAlignmentLine

A vertical AlignmentLine.

Type-aliases

IntrinsicMeasureBlock

A function for performing intrinsic measurement.

MeasureBlock

A function for performing layout measurement.

MultiMeasureBlock

PointerInputHandler

A function used to react to and modify PointerInputChanges.

Enums

Alignment

Represents a positioning of a point inside a 2D box.

Direction

DropDownAlignment

The DropdownPopup is aligned below its parent relative to its left or right corner.

LayoutDirection

A class for defining layout directions.

PointerEventPass

The enumeration of passes where PointerInputChange traverses up and down the UI tree.

Top-level functions summary

Unit
Clip(shape: Shape, crossinline children: () -> Unit)

Clips the children with the provided shape.

Unit
ComposeView(children: () -> Unit)

Composes a view containing ui composables into a view composition.

Unit
CurrentTextStyleProvider(value: TextStyle, children: () -> Unit)

This component is used to set the current value of the Text style ambient.

Unit
Draw(noinline onPaint: Density.(canvas: Canvas, parentSize: PxSize) -> Unit)

Use Draw to get a Canvas to paint into the parent.

Unit
Draw(crossinline children: () -> Unit, noinline onPaint: DrawReceiver.(canvas: Canvas, parentSize: PxSize) -> Unit)

A Draw scope that accepts children to allow modifying the canvas for children.

Unit
DrawShadow(shape: Shape, elevation: Dp)

Draws the shadow.

Unit
DropdownPopup(dropDownAlignment: DropDownAlignment = DropDownAlignment.Left, offset: IntPxPosition = IntPxPosition(IntPx.Zero, IntPx.Zero), popupProperties: PopupProperties = PopupProperties(), children: () -> Unit)

Opens a popup with the given content.

Unit
Layout(children: () -> Unit, minIntrinsicWidthMeasureBlock: IntrinsicMeasureBlock, minIntrinsicHeightMeasureBlock: IntrinsicMeasureBlock, maxIntrinsicWidthMeasureBlock: IntrinsicMeasureBlock, maxIntrinsicHeightMeasureBlock: IntrinsicMeasureBlock, modifier: Modifier = Modifier.None, measureBlock: MeasureBlock)

Layout is the main core component for layout.

Unit
Layout(children: () -> Unit, modifier: Modifier = Modifier.None, measureBlock: MeasureBlock)

Layout is the main core component for layout.

Unit
Layout(vararg childrenArray: () -> Unit, modifier: Modifier = Modifier.None, measureBlock: MultiMeasureBlock)

Temporary component that allows composing and indexing measurables of multiple composables.

LayoutNode.MeasureBlocks

Default LayoutNode.MeasureBlocks object implementation, providing intrinsic measurements that use the measure block replacing the measure calls with intrinsic measurement calls.

Unit
OnChildPositioned(noinline onPositioned: (coordinates: LayoutCoordinates) -> Unit, crossinline children: () -> Unit)

onPositioned callback will be called with the final LayoutCoordinates of the children MeasureBox(es) after measuring.

Unit
OnPositioned(noinline onPositioned: (coordinates: LayoutCoordinates) -> Unit)

onPositioned callback will be called with the final LayoutCoordinates of the parent MeasureBox after measuring.

Unit
Opacity(opacity: Float, crossinline children: () -> Unit)

Makes its children partially transparent.

Unit
ParentData(data: Any, crossinline children: () -> Unit)

Provide data for the parent of a Layout, which can then be read from the corresponding Measurable.

Unit
PasswordTextField(value: String, onValueChange: (String) -> Unit = {}, textStyle: TextStyle? = null, mask: Char = '\u2022', imeAction: ImeAction = ImeAction.Unspecified, onFocus: () -> Unit = {}, onBlur: () -> Unit = {}, focusIdentifier: String? = null, onImeActionPerformed: (ImeAction) -> Unit = {})

A user interface element for entering and modifying password text.

Unit
PointerInput(noinline pointerInputHandler: PointerInputHandler, noinline cancelHandler: () -> Unit, noinline initHandler: (CustomEventDispatcher) -> Unit = null, noinline customEventHandler: (CustomEvent, PointerEventPass) -> Unit = null, crossinline children: () -> Unit)

PointerInput is the compose ui core component for receiving and interacting with pointer input.

Unit
Popup(alignment: Alignment = Alignment.TopLeft, offset: IntPxPosition = IntPxPosition(IntPx.Zero, IntPx.Zero), popupProperties: PopupProperties = PopupProperties(), children: () -> Unit)

Opens a popup with the given content.

Unit
RepaintBoundary(name: String? = null, children: () -> Unit)

A repaint boundary blocks parents from having to repaint when contained children are invalidated.

Unit
TestTag(tag: String, children: () -> Unit)

Unit
Text(text: String, modifier: Modifier = Modifier.None, style: TextStyle? = null, softWrap: Boolean = DefaultSoftWrap, overflow: TextOverflow = DefaultOverflow, maxLines: Int = DefaultMaxLines, onTextLayout: (TextLayoutResult) -> Unit = {})

Simplified version of Text component with minimal set of customizations.

Unit
Text(text: AnnotatedString, modifier: Modifier = Modifier.None, style: TextStyle? = null, softWrap: Boolean = DefaultSoftWrap, overflow: TextOverflow = DefaultOverflow, maxLines: Int = DefaultMaxLines, onTextLayout: (TextLayoutResult) -> Unit = {})

The Text composable displays text that uses multiple different styles.

Unit
TextField(value: String, modifier: Modifier = Modifier.None, onValueChange: (String) -> Unit = {}, textStyle: TextStyle? = null, keyboardType: KeyboardType = KeyboardType.Text, imeAction: ImeAction = ImeAction.Unspecified, onFocus: () -> Unit = {}, onBlur: () -> Unit = {}, focusIdentifier: String? = null, onImeActionPerformed: (ImeAction) -> Unit = {}, visualTransformation: VisualTransformation? = null)

A user interface element for entering and modifying text.

Unit
TextField(value: TextFieldValue, modifier: Modifier = Modifier.None, onValueChange: (TextFieldValue) -> Unit = {}, textStyle: TextStyle? = null, keyboardType: KeyboardType = KeyboardType.Text, imeAction: ImeAction = ImeAction.Unspecified, onFocus: () -> Unit = {}, onBlur: () -> Unit = {}, focusIdentifier: String? = null, onImeActionPerformed: (ImeAction) -> Unit = {}, visualTransformation: VisualTransformation? = null)

A user interface element for entering and modifying text.

Unit
TextField(model: TextFieldValue, compositionRange: TextRange?, modifier: Modifier = Modifier.None, onValueChange: (TextFieldValue, TextRange?) -> Unit = { _, _ -> }, textStyle: TextStyle? = null, keyboardType: KeyboardType = KeyboardType.Text, imeAction: ImeAction = ImeAction.Unspecified, onFocus: () -> Unit = {}, onBlur: () -> Unit = {}, focusIdentifier: String? = null, onImeActionPerformed: (ImeAction) -> Unit = {}, visualTransformation: VisualTransformation? = null)

A user interface element for entering and modifying text.

Unit
WithConstraints(modifier: Modifier = Modifier.None, children: (Constraints) -> Unit)

A composable that defines its own content according to the available space, based on the incoming constraints.

TextStyle

This effect is used to read the current value of the Text style ambient.

Unit

Disposes the root view of the Activity.

DrawModifier
draw(onDraw: Density.(canvas: Canvas, size: PxSize) -> Unit)

Creates a DrawModifier that calls onDraw before the contents of the layout.

DrawModifier
drawWithContent(onDraw: DrawReceiver.(canvas: Canvas, size: PxSize) -> Unit)

Creates a DrawModifier that allows the developer to draw before or after the layout's contents.

Boolean
isPopupLayout(view: View, testTag: String? = null)

Returns whether the given view is an underlying decor view of a popup.

String
simpleIdentityToString(obj: Any, name: String? = null)

Top-level properties summary

ProvidableAmbient<AndroidComposeView>

ProvidableAmbient<AnimationClockObservable>

ProvidableAmbient<Autofill?>

ProvidableAmbient<AutofillTree>

ProvidableAmbient<Configuration>

ProvidableAmbient<Context>

ProvidableAmbient<CoroutineContext>

ProvidableAmbient<Density>

HorizontalAlignmentLine

AlignmentLine defined by the baseline of a first line of a Text.

ProvidableAmbient<FocusManager>

ProvidableAmbient<Font.ResourceLoader>

ProvidableAmbient<HapticFeedback>

The ambient to provide haptic feedback to the user.

HorizontalAlignmentLine

AlignmentLine defined by the baseline of the last line of a Text.

ProvidableAmbient<LayoutDirection>

DataNodeKey<(LayoutCoordinates) -> Unit>

DataNodeKey for OnChildPositioned callback

DataNodeKey<(LayoutCoordinates) -> Unit>

DataNodeKey for OnPositioned callback

DataNodeKey<Any>

DataNodeKey for ParentData

ProvidableAmbient<TextInputService?>

Extension functions summary

For android.app.Activity
Composition
Activity.setContent(content: () -> Unit)

Composes the given composable into the given activity.

For android.view.ViewGroup
Composition
ViewGroup.setContent(content: () -> Unit)

Composes the given composable into the given view.

For ComponentNode
Unit

Inserts a child ComponentNode at a last index.

ComponentNode?

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

LayoutNode?

Executes block on first level of LayoutNode descendants of this ComponentNode and returns the last LayoutNode to return true from block.

Boolean

Returns true if this ComponentNode has no descendant LayoutNodes.

Boolean

Returns true if this ComponentNode currently has an ComponentNode.owner.

Owner

Returns ComponentNode.owner or throws if it is null.

Unit

Executes block on first level of LayoutNode descendants of this ComponentNode.

For PointerInputChange
Boolean

Boolean

Boolean

Boolean

Boolean

PointerInputChange

PointerInputChange
PointerInputChange.consumePositionChange(consumedDx: Px, consumedDy: Px)

PxPosition

PxPosition

Boolean

Boolean

For Constraints
IntPxSize

Takes a size and returns the closest size to it that satisfies the constraints.

Constraints
Constraints.enforce(otherConstraints: Constraints)

Returns the result of coercing the current constraints in a different set of constraints.

Constraints
Constraints.offset(horizontal: IntPx = 0.ipx, vertical: IntPx = 0.ipx)

Returns the Constraints obtained by offsetting the current instance with the given values.

Boolean

Takes a size and returns whether it satisfies the current constraints.

For SemanticsNode
SemanticsNode?

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

For AlignmentLine
IntPx
AlignmentLine.merge(position1: IntPx, position2: IntPx)

Merges two values of the current alignment line.

For Rect
Rect

RectF

For Painter
DrawModifier
Painter.toModifier(alpha: Float = DefaultAlpha, colorFilter: ColorFilter? = null, rtl: Boolean = false)

Create a DrawModifier from this Painter.

Extension properties summary

For LayoutCoordinates
PxBounds

The boundaries of this layout inside the root composable.

PxBounds

The global boundaries of this layout inside.

PxPosition

The global position of this layout.

PxPosition

The position of this layout inside the root composable.

For Constraints
Boolean

Whether or not the upper bound on the maximum height.

Boolean

Whether or not the upper bound on the maximum width.

Boolean

Whether there is exactly one height value that satisfies the constraints.

Boolean

Whether there is exactly one width value that satisfies the constraints.

Boolean

Whether the area of a component respecting these constraints will definitely be 0.

For Measurable
Any?

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

Top-level functions

Clip

@Composable inline fun Clip(
    shape: Shape,
    crossinline children: () -> Unit
): Unit

Clips the children with the provided shape.

Parameters
shape: Shape the Shape used for clipping.

ComposeView

@Composable fun ComposeView(children: () -> Unit): Unit

Composes a view containing ui composables into a view composition.

CurrentTextStyleProvider

@Composable fun CurrentTextStyleProvider(
    value: TextStyle,
    children: () -> Unit
): Unit

This component is used to set the current value of the Text style ambient. The given style will be merged with the current style values for any missing attributes. Any Text components included in this component's children will be styled with this style unless styled explicitly.

Draw

@Composable inline fun Draw(noinline onPaint: Density.(canvas: Canvas, parentSize: PxSize) -> Unit): Unit

Use Draw to get a Canvas to paint into the parent.

Example usage:

import androidx.compose.remember
import androidx.ui.core.Draw
import androidx.ui.graphics.Paint
import androidx.ui.unit.toRect

val paint = remember { Paint() }
Draw { canvas, parentSize ->
    paint.color = Color.Black
    canvas.drawRect(parentSize.toRect(), paint)
}
The onPaint lambda uses a Density receiver scope, to allow easy translationbetween Dp, Sp, and Px. The parentSize parameter indicates the layout size ofthe parent.

Draw

@Composable inline fun Draw(
    crossinline children: () -> Unit,
    noinline onPaint: DrawReceiver.(canvas: Canvas, parentSize: PxSize) -> Unit
): Unit

A Draw scope that accepts children to allow modifying the canvas for children. The children are drawn when DrawReceiver.drawChildren is called. If the onPaint does not call DrawReceiver.drawChildren then it will be called after the lambda.

Example usage:

import androidx.compose.remember
import androidx.ui.core.Draw
import androidx.ui.core.Text
import androidx.ui.geometry.Rect
import androidx.ui.graphics.Paint
import androidx.ui.unit.toRect

val children = @Composable {
    Text("Hello World")
}
val paint = remember { Paint() }
Draw(children) { canvas, parentSize ->
    // Draw the highlight behind the text
    paint.color = Color.Yellow
    paint.style = PaintingStyle.fill
    val rect = parentSize.toRect()
    canvas.drawRect(rect, paint)

    // Draw the text
    drawChildren()

    // Draw the border on top of the text
    paint.style = PaintingStyle.stroke
    val strokeWidth = 2.dp.toIntPx().value.toFloat()
    paint.color = Color.Black
    paint.strokeWidth = strokeWidth
    val outlineRect = Rect(
        left = strokeWidth / 2,
        top = strokeWidth / 2,
        right = rect.right - (strokeWidth / 2),
        bottom = rect.bottom - (strokeWidth / 2)
    )
    canvas.drawRect(outlineRect, paint)
}

DrawShadow

@Composable inline fun DrawShadow(
    shape: Shape,
    elevation: Dp
): Unit

Draws the shadow. The elevation defines the visual dept of the physical object. The physical object has a shape specified by shape.

Example usage:

import androidx.ui.core.DrawShadow

DrawShadow(shape = RectangleShape, elevation = 12.dp)
Parameters
elevation: Dp The z-coordinate at which to place this physical object.
shape: Shape Defines a shape of the physical object

DropdownPopup

@Composable fun DropdownPopup(
    dropDownAlignment: DropDownAlignment = DropDownAlignment.Left,
    offset: IntPxPosition = IntPxPosition(IntPx.Zero, IntPx.Zero),
    popupProperties: PopupProperties = PopupProperties(),
    children: () -> Unit
): Unit

Opens a popup with the given content.

The dropdown popup is positioned below its parent, using the dropDownAlignment and offset. The dropdown popup is visible as long as it is part of the composition hierarchy.

import androidx.ui.core.DropdownPopup
import androidx.ui.foundation.shape.DrawShape
import androidx.ui.foundation.shape.corner.RoundedCornerShape
import androidx.ui.layout.Container

val parentWidth = 400.dp
val parentHeight = 200.dp
Container(width = parentWidth, height = parentHeight) {
    val popupWidth = 200.dp
    val popupHeight = 50.dp
    val cornerSize = 16.dp

    // The popup will appear below the parent
    DropdownPopup(dropDownAlignment = DropDownAlignment.Left) {
        // Draw a rectangle shape with rounded corners inside the popup
        Container(width = popupWidth, height = popupHeight) {
            DrawShape(RoundedCornerShape(cornerSize), Color.White)
        }
    }
}
Parameters
dropDownAlignment: DropDownAlignment = DropDownAlignment.Left The left or right alignment below the parent.
offset: IntPxPosition = IntPxPosition(IntPx.Zero, IntPx.Zero) An offset from the original aligned position of the popup.
popupProperties: PopupProperties = PopupProperties() Provides extended set of properties to configure the popup.
children: () -> Unit The content to be displayed inside the popup.

Layout

@Composable fun Layout(
    children: () -> Unit,
    minIntrinsicWidthMeasureBlock: IntrinsicMeasureBlock,
    minIntrinsicHeightMeasureBlock: IntrinsicMeasureBlock,
    maxIntrinsicWidthMeasureBlock: IntrinsicMeasureBlock,
    maxIntrinsicHeightMeasureBlock: IntrinsicMeasureBlock,
    modifier: Modifier = Modifier.None,
    measureBlock: MeasureBlock
): Unit

Layout is the main core component for layout. It can be used to measure and position zero or more children.

Intrinsic measurement blocks define the intrinsic sizes of the current layout. These can be queried by the parent in order to understand, in specific cases, what constraints should the layout be measured with:

  • minIntrinsicWidthMeasureBlock defines the minimum width this layout can take, given a specific height, such that the content of the layout will be painted correctly
  • minIntrinsicHeightMeasureBlock defines the minimum height this layout can take, given a specific width, such that the content of the layout will be painted correctly
  • maxIntrinsicWidthMeasureBlock defines the minimum width such that increasing it further will not decrease the minimum intrinsic height
  • maxIntrinsicHeightMeasureBlock defines the minimum height such that increasing it further will not decrease the minimum intrinsic width

For a composable able to define its content according to the incoming constraints, see WithConstraints.

Example usage:

import androidx.ui.core.Constraints
import androidx.ui.core.Layout

// We build a layout that will occupy twice as much space as its children,
// and will position them to be bottom right aligned.
Layout(
    children,
    minIntrinsicWidthMeasureBlock = { measurables, h ->
        // The min intrinsic width of this layout will be twice the largest min intrinsic
        // width of a child. Note that we call minIntrinsicWidth with h / 2 for children,
        // since we should be double the size of the children.
        (measurables.map { it.minIntrinsicWidth(h / 2) }.maxBy { it.value } ?: 0.ipx) * 2
    },
    minIntrinsicHeightMeasureBlock = { measurables, w ->
        (measurables.map { it.minIntrinsicHeight(w / 2) }.maxBy { it.value } ?: 0.ipx) * 2
    },
    maxIntrinsicWidthMeasureBlock = { measurables, h ->
        (measurables.map { it.maxIntrinsicHeight(h / 2) }.maxBy { it.value } ?: 0.ipx) * 2
    },
    maxIntrinsicHeightMeasureBlock = { measurables, w ->
        (measurables.map { it.maxIntrinsicHeight(w / 2) }.maxBy { it.value } ?: 0.ipx) * 2
    }
) { measurables, constraints ->
    // measurables contains one element corresponding to each of our layout children.
    // constraints are the constraints that our parent is currently measuring us with.
    val childConstraints = Constraints(
        minWidth = constraints.minWidth / 2,
        minHeight = constraints.minHeight / 2,
        maxWidth = constraints.maxWidth / 2,
        maxHeight = constraints.maxHeight / 2
    )
    // We measure the children with half our constraints, to ensure we can be double
    // the size of the children.
    val placeables = measurables.map { it.measure(childConstraints) }
    val layoutWidth = (placeables.maxBy { it.width.value }?.width ?: 0.ipx) * 2
    val layoutHeight = (placeables.maxBy { it.height.value }?.height ?: 0.ipx) * 2
    // We call layout to set the size of the current layout and to provide the positioning
    // of the children. The children are placed relative to the current layout place.
    layout(layoutWidth, layoutHeight) {
        placeables.forEach { it.place(layoutWidth - it.width, layoutHeight - it.height) }
    }
}
Parameters
children: () -> Unit The children composable to be laid out.
modifier: Modifier = Modifier.None Modifiers to be applied to the layout.
minIntrinsicWidthMeasureBlock: IntrinsicMeasureBlock The minimum intrinsic width of the layout.
minIntrinsicHeightMeasureBlock: IntrinsicMeasureBlock The minimum intrinsic height of the layout.
maxIntrinsicWidthMeasureBlock: IntrinsicMeasureBlock The maximum intrinsic width of the layout.
maxIntrinsicHeightMeasureBlock: IntrinsicMeasureBlock The maximum intrinsic height of the layout.
measureBlock: MeasureBlock The block defining the measurement and positioning of the layout.

Layout

@Composable fun Layout(
    children: () -> Unit,
    modifier: Modifier = Modifier.None,
    measureBlock: MeasureBlock
): Unit

Layout is the main core component for layout. It can be used to measure and position zero or more children.

The intrinsic measurements of this layout will be calculated by running the measureBlock, while swapping measure calls with appropriate intrinsic measurements. Note that these provided implementations will not be accurate in all cases - when this happens, the other overload of Layout should be used to provide correct measurements.

For a composable able to define its content according to the incoming constraints, see WithConstraints.

Example usage:

import androidx.ui.core.Constraints
import androidx.ui.core.Layout

// We build a layout that will occupy twice as much space as its children,
// and will position them to be bottom right aligned.
Layout(children) { measurables, constraints ->
    // measurables contains one element corresponding to each of our layout children.
    // constraints are the constraints that our parent is currently measuring us with.
    val childConstraints = Constraints(
        minWidth = constraints.minWidth / 2,
        minHeight = constraints.minHeight / 2,
        maxWidth = constraints.maxWidth / 2,
        maxHeight = constraints.maxHeight / 2
    )
    // We measure the children with half our constraints, to ensure we can be double
    // the size of the children.
    val placeables = measurables.map { it.measure(childConstraints) }
    val layoutWidth = (placeables.maxBy { it.width.value }?.width ?: 0.ipx) * 2
    val layoutHeight = (placeables.maxBy { it.height.value }?.height ?: 0.ipx) * 2
    // We call layout to set the size of the current layout and to provide the positioning
    // of the children. The children are placed relative to the current layout place.
    layout(layoutWidth, layoutHeight) {
        placeables.forEach { it.place(layoutWidth - it.width, layoutHeight - it.height) }
    }
}
Parameters
children: () -> Unit The children composable to be laid out.
modifier: Modifier = Modifier.None Modifiers to be applied to the layout.
measureBlock: MeasureBlock The block defining the measurement and positioning of the layout.

Layout

@Composable fun Layout(
    vararg childrenArray: () -> Unit,
    modifier: Modifier = Modifier.None,
    measureBlock: MultiMeasureBlock
): Unit

Deprecated.

Temporary component that allows composing and indexing measurables of multiple composables. The logic here will be moved back to Layout, which will accept vararg children argument.

MeasuringIntrinsicsMeasureBlocks

fun MeasuringIntrinsicsMeasureBlocks(measureBlock: MeasureBlock): LayoutNode.MeasureBlocks

Default LayoutNode.MeasureBlocks object implementation, providing intrinsic measurements that use the measure block replacing the measure calls with intrinsic measurement calls.

OnChildPositioned

@Composable inline fun OnChildPositioned(
    noinline onPositioned: (coordinates: LayoutCoordinates) -> Unit,
    crossinline children: () -> Unit
): Unit

onPositioned callback will be called with the final LayoutCoordinates of the children MeasureBox(es) after measuring. Note that it will be called after a composition when the coordinates are finalized.

Usage example:

import androidx.ui.core.OnChildPositioned

Column {
    SizedRectangle(color = Color.Green, width = 20.dp, height = 20.dp)
    OnChildPositioned(onPositioned = { coordinates ->
        // This will be the size of the child SizedRectangle.
        coordinates.size
        // The position of the SizedRectangle relative to the application window.
        coordinates.globalPosition
        // The position of the SizedRectangle relative to the Compose root.
        coordinates.positionInRoot
        // These will be the alignment lines provided to the layout (empty for SizedRectangle)
        coordinates.providedAlignmentLines
        // This will a LayoutCoordinates instance corresponding to the Column.
        coordinates.parentCoordinates
    }) {
        SizedRectangle(color = Color.Blue, width = 20.dp, height = 20.dp)
    }
}

OnPositioned

@Composable inline fun OnPositioned(noinline onPositioned: (coordinates: LayoutCoordinates) -> Unit): Unit

onPositioned callback will be called with the final LayoutCoordinates of the parent MeasureBox after measuring. Note that it will be called after a composition when the coordinates are finalized.

Usage example:

import androidx.ui.core.OnPositioned

Column {
    SizedRectangle(color = Color.Green, width = 20.dp, height = 20.dp)
    SizedRectangle(color = Color.Blue, width = 20.dp, height = 20.dp)
    OnPositioned(onPositioned = { coordinates ->
        // This will be the size of the Column.
        coordinates.size
        // The position of the Column relative to the application window.
        coordinates.globalPosition
        // The position of the Column relative to the Compose root.
        coordinates.positionInRoot
        // These will be the alignment lines provided to the layout (empty here for Column).
        coordinates.providedAlignmentLines
        // This will a LayoutCoordinates instance corresponding to the parent of Column.
        coordinates.parentCoordinates
    })
}

Opacity

@Composable inline fun Opacity(
    opacity: Float,
    crossinline children: () -> Unit
): Unit

Makes its children partially transparent.

Example usage:

import androidx.ui.core.Opacity
import androidx.ui.foundation.shape.DrawShape

Opacity(opacity = 0.5f) {
    DrawShape(RectangleShape, Color.Red)
}
Parameters
opacity: Float the fraction of children's alpha value.

ParentData

@Composable inline fun ParentData(
    data: Any,
    crossinline children: () -> Unit
): Unit

Provide data for the parent of a Layout, which can then be read from the corresponding Measurable.

A containing Layout sometimes needs to mark children with attributes that can later be read during layout. data is assigned to the Measurable.parentData to be read. Normally ParentData is completely controlled by the containing Layout. For example, Row and Column layout models use parent data to access the flex value of their children during measurement (though that is achieved using the Inflexible and Flexible modifiers, rather than using this widget).

Example usage:

import androidx.ui.core.Layout
import androidx.ui.core.ParentData

val parentDataComposable = @Composable {
    ParentData(data = 5) {
        SizedRectangle(color = Color.Blue, width = 50.dp, height = 50.dp)
    }
}
Layout(parentDataComposable) { measurables, constraints ->
    // The parentData will be 5.
    measurables[0].parentData as Int
    layout(constraints.maxWidth, constraints.maxHeight) {}
}

PasswordTextField

@Composable fun PasswordTextField(
    value: String,
    onValueChange: (String) -> Unit = {},
    textStyle: TextStyle? = null,
    mask: Char = '\u2022',
    imeAction: ImeAction = ImeAction.Unspecified,
    onFocus: () -> Unit = {},
    onBlur: () -> Unit = {},
    focusIdentifier: String? = null,
    onImeActionPerformed: (ImeAction) -> Unit = {}
): Unit

A user interface element for entering and modifying password text.

The PasswordTextField component renders an input with masking characters, i.e. bullet. Once input service modify the text, you will get callback onValueChange with new text. Then, you can set this new text so that this component renders up-to-date text from input service.

Example usage:

import androidx.compose.state
import androidx.ui.core.PasswordTextField

val state = state { "" }
PasswordTextField(
    value = state.value,
    onValueChange = { state.value = it }
)
Parameters
value: String The text to be shown in the TextField. If you want to specify cursor location or selection range, use TextField with TextFieldValue instead.
onValueChange: (String) -> Unit = {} Called when the input service updates the text. When the input service update the text, this callback is called with the updated text. If you want to observe the cursor location or selection range, use TextField with TextFieldValue instead.
textStyle: TextStyle? = null Style configuration that applies at character level such as color, font etc.
mask: Char = '\u2022' The character shown instead of plaint text.
imeAction: ImeAction = ImeAction.Unspecified The IME action. This IME action is honored by IME and may show specific icons on the keyboard. For example, search icon may be shown if ImeAction.Search is specified. Then, when user tap that key, the onImeActionPerformed callback is called with specified ImeAction.
onFocus: () -> Unit = {} Called when the input field gains focus.
onBlur: () -> Unit = {} Called when the input field loses focus.
focusIdentifier: String? = null Optional value to identify focus identifier. You can pass FocusManager.requestFocus to this value to move focus to this TextField. This identifier must be unique in your app. If you have duplicated identifiers, the behavior is undefined.
onImeActionPerformed: (ImeAction) -> Unit = {} Called when the input service requested an IME action. When the input service emitted an IME action, this callback is called with the emitted IME action. Note that this IME action may be different from what you specified in imeAction.

PointerInput

@Composable inline fun PointerInput(
    noinline pointerInputHandler: PointerInputHandler,
    noinline cancelHandler: () -> Unit,
    noinline initHandler: (CustomEventDispatcher) -> Unit = null,
    noinline customEventHandler: (CustomEvent, PointerEventPass) -> Unit = null,
    crossinline children: () -> Unit
): Unit

PointerInput is the compose ui core component for receiving and interacting with pointer input.

Pointer input includes all user input related to 2d positioning on the screen. This includes (but is not necessarily limited to) fingers touching the screen, a mouse moving across the screen, and stylus input.

PointerInput takes the virtual size of all of it's descendant Layout nodes and when a pointer comes in contact with the screen, hit testing is automatically done using that virtual size.

pointerInputHandler is invoked when pointers that have hit tested positive change.

cancelHandler is invoked to notify the handler that no more calls to pointerInputHandler will be made, until at least new pointers exist. This can occur for a few reasons:

  1. Android dispatches ACTION_CANCEL to AndroidComposeView.onTouchEvent.
  2. The PointerInputNode has been removed from the compose hierarchy.
  3. The PointerInputNode no longer has any descendant LayoutNodes and therefore does not know what region of the screen it should virtually exist in.

initHandler is invoked right after the PointerInputNode is hit tested and provides an implementation of CustomEventDispatcher.

customEventHandler is invoked whenever another PointerInput uses CustomEventDispatcher to send a custom event to other PointerInputs.

Parameters
pointerInputHandler: PointerInputHandler Invoked when pointers that have hit this PointerInput change.
cancelHandler: () -> Unit Invoked when a cancellation event occurs.
initHandler: (CustomEventDispatcher) -> Unit = null Invoked when an implementation of CustomEventDispatcher is provided.
customEventHandler: (CustomEvent, PointerEventPass) -> Unit = null Invoked when another PointerInput dispatches a CustomEvent.
children: () -> Unit The children composable that will be composed as a child, or children, of this PointerInput.

Popup

@Composable fun Popup(
    alignment: Alignment = Alignment.TopLeft,
    offset: IntPxPosition = IntPxPosition(IntPx.Zero, IntPx.Zero),
    popupProperties: PopupProperties = PopupProperties(),
    children: () -> Unit
): Unit

Opens a popup with the given content.

The popup is positioned relative to its parent, using the alignment and offset. The popup is visible as long as it is part of the composition hierarchy.

import androidx.ui.core.Popup
import androidx.ui.foundation.shape.DrawShape
import androidx.ui.foundation.shape.corner.RoundedCornerShape
import androidx.ui.layout.Container

Container {
    val popupWidth = 200.dp
    val popupHeight = 50.dp
    val cornerSize = 16.dp

    Popup(alignment = Alignment.Center) {
        // Draw a rectangle shape with rounded corners inside the popup
        Container(width = popupWidth, height = popupHeight) {
            DrawShape(RoundedCornerShape(cornerSize), Color.White)
        }
    }
}
Parameters
alignment: Alignment = Alignment.TopLeft The alignment relative to the parent.
offset: IntPxPosition = IntPxPosition(IntPx.Zero, IntPx.Zero) An offset from the original aligned position of the popup.
popupProperties: PopupProperties = PopupProperties() Provides extended set of properties to configure the popup.
children: () -> Unit The content to be displayed inside the popup.

RepaintBoundary

@Composable fun RepaintBoundary(
    name: String? = null,
    children: () -> Unit
): Unit

A repaint boundary blocks parents from having to repaint when contained children are invalidated. This is used when children are invalidated together and don't affect the parent. For example, a Button with a contained ripple does not need to invalidate its container when animating the ripple.

Parameters
name: String? = null The (optional) name of the RepaintBoundary. This is used for debugging and will be given to the tag on a View or the name of a RenderNode.
children: () -> Unit The contained children.

TestTag

@Composable fun TestTag(
    tag: String,
    children: () -> Unit
): Unit

Text

@Composable fun Text(
    text: String,
    modifier: Modifier = Modifier.None,
    style: TextStyle? = null,
    softWrap: Boolean = DefaultSoftWrap,
    overflow: TextOverflow = DefaultOverflow,
    maxLines: Int = DefaultMaxLines,
    onTextLayout: (TextLayoutResult) -> Unit = {}
): Unit

Simplified version of Text component with minimal set of customizations.

Parameters
text: String The text to be displayed.
modifier: Modifier = Modifier.None Modifier to apply to this layout node.
style: TextStyle? = null Style configuration for the text such as color, font, line height etc.
softWrap: Boolean = DefaultSoftWrap Whether the text should break at soft line breaks. If false, the glyphs in the text will be positioned as if there was unlimited horizontal space. If softWrap is false, overflow and TextAlign may have unexpected effects.
overflow: TextOverflow = DefaultOverflow How visual overflow should be handled.
maxLines: Int = DefaultMaxLines An optional maximum number of lines for the text to span, wrapping if necessary. If the text exceeds the given number of lines, it will be truncated according to overflow and softWrap. If it is not null, then it must be greater than zero.
onTextLayout: (TextLayoutResult) -> Unit = {} Callback that is executed when a new text layout is calculated.

Text

@Composable fun Text(
    text: AnnotatedString,
    modifier: Modifier = Modifier.None,
    style: TextStyle? = null,
    softWrap: Boolean = DefaultSoftWrap,
    overflow: TextOverflow = DefaultOverflow,
    maxLines: Int = DefaultMaxLines,
    onTextLayout: (TextLayoutResult) -> Unit = {}
): Unit

The Text composable displays text that uses multiple different styles. The text to display is described using a AnnotatedString.

Parameters
text: AnnotatedString AnnotatedString encoding a styled text.
modifier: Modifier = Modifier.None Modifier to apply to this layout node.
style: TextStyle? = null Style configuration for the text such as color, font, line height etc.
softWrap: Boolean = DefaultSoftWrap Whether the text should break at soft line breaks. If false, the glyphs in the text will be positioned as if there was unlimited horizontal space. If softWrap is false, overflow and TextAlign may have unexpected effects.
overflow: TextOverflow = DefaultOverflow How visual overflow should be handled.
maxLines: Int = DefaultMaxLines An optional maximum number of lines for the text to span, wrapping if necessary. If the text exceeds the given number of lines, it will be truncated according to overflow and softWrap. If it is not null, then it must be greater than zero.
onTextLayout: (TextLayoutResult) -> Unit = {} Callback that is executed when a new text layout is calculated.

TextField

@Composable fun TextField(
    value: String,
    modifier: Modifier = Modifier.None,
    onValueChange: (String) -> Unit = {},
    textStyle: TextStyle? = null,
    keyboardType: KeyboardType = KeyboardType.Text,
    imeAction: ImeAction = ImeAction.Unspecified,
    onFocus: () -> Unit = {},
    onBlur: () -> Unit = {},
    focusIdentifier: String? = null,
    onImeActionPerformed: (ImeAction) -> Unit = {},
    visualTransformation: VisualTransformation? = null
): Unit

A user interface element for entering and modifying text.

The TextField component renders an input and additional decorations set by input service which is software keyboard in Android. Once input service modify the text, you will get callback onValueChange with new text. Then, you can set this new text so that this component renders up-to-date text from input service.

Example usage:

import androidx.compose.state
import androidx.ui.core.TextField

val state = state { "" }
TextField(
    value = state.value,
    onValueChange = { state.value = it }
)

This is the most simple TextField that observes only text update and have control only for the text. If you want to change/observe the selection/cursor location, you can use TextField with TextFieldValue object.

Note: Please be careful if you setting text other than the one passed to onValueChange callback. Especially, it is not recommended to modify the text passed to onValueChange callback. The text change may be translated to full context reset by input service and end up with input session restart. This will be visible to users, for example, any ongoing composition text will be cleared or committed, then software keyboard may go back to the default one.

Parameters
value: String The text to be shown in the TextField. If you want to specify cursor location or selection range, use TextField with TextFieldValue instead.
onValueChange: (String) -> Unit = {} Called when the input service updates the text. When the input service update the text, this callback is called with the updated text. If you want to observe the cursor location or selection range, use TextField with TextFieldValue instead.
textStyle: TextStyle? = null Style configuration that applies at character level such as color, font etc.
keyboardType: KeyboardType = KeyboardType.Text The keyboard type to be used in this text field. Note that this input type is honored by IME and shows corresponding keyboard but this is not guaranteed. For example, some IME may send non-ASCII character even if you set KeyboardType.Ascii.
imeAction: ImeAction = ImeAction.Unspecified The IME action. This IME action is honored by IME and may show specific icons on the keyboard. For example, search icon may be shown if ImeAction.Search is specified. Then, when user tap that key, the onImeActionPerformed callback is called with specified ImeAction.
onFocus: () -> Unit = {} Called when the input field gains focus.
onBlur: () -> Unit = {} Called when the input field loses focus.
focusIdentifier: String? = null Optional value to identify focus identifier. You can pass FocusManager.requestFocus to this value to move focus to this TextField. This identifier must be unique in your app. If you have duplicated identifiers, the behavior is undefined.
onImeActionPerformed: (ImeAction) -> Unit = {} Called when the input service requested an IME action. When the input service emitted an IME action, this callback is called with the emitted IME action. Note that this IME action may be different from what you specified in imeAction.
visualTransformation: VisualTransformation? = null Optional visual filter for changing visual output of input field.

TextField

@Composable fun TextField(
    value: TextFieldValue,
    modifier: Modifier = Modifier.None,
    onValueChange: (TextFieldValue) -> Unit = {},
    textStyle: TextStyle? = null,
    keyboardType: KeyboardType = KeyboardType.Text,
    imeAction: ImeAction = ImeAction.Unspecified,
    onFocus: () -> Unit = {},
    onBlur: () -> Unit = {},
    focusIdentifier: String? = null,
    onImeActionPerformed: (ImeAction) -> Unit = {},
    visualTransformation: VisualTransformation? = null
): Unit

A user interface element for entering and modifying text.

The TextField component renders an input and additional decorations set by input service which is software keyboard in Android. Once input service modify the text, you will get callback onValueChange with new text. Then, you can set this new text so that this component renders up-to-date text from input service.

Example usage:

import androidx.compose.state
import androidx.ui.core.TextField
import androidx.ui.text.TextFieldValue

val state = state { TextFieldValue() }
TextField(
    value = state.value,
    onValueChange = { state.value = it }
)
Note: Please be careful if you setting model other than the one passed to onValueChangecallback including selection or cursor. Especially, it is not recommended to modify the modelpassed to onValueChange callback. Any change to text, selection or cursor may be translated tofull context reset by input service and end up with input session restart. This will be visibleto users, for example, any ongoing composition text will be cleared or committed, then softwarekeyboard may go back to the default one.
Parameters
value: TextFieldValue The TextFieldValue to be shown in the TextField.
onValueChange: (TextFieldValue) -> Unit = {} Called when the input service updates the text, selection or cursor. When the input service update the text, selection or cursor, this callback is called with the updated TextFieldValue. If you want to observe the composition text, use TextField with compositionRange instead.
textStyle: TextStyle? = null Style configuration that applies at character level such as color, font etc.
keyboardType: KeyboardType = KeyboardType.Text The keyboard type to be used in this text field. Note that this input type is honored by IME and shows corresponding keyboard but this is not guaranteed. For example, some IME may send non-ASCII character even if you set KeyboardType.Ascii.
imeAction: ImeAction = ImeAction.Unspecified The IME action. This IME action is honored by IME and may show specific icons on the keyboard. For example, search icon may be shown if ImeAction.Search is specified. Then, when user tap that key, the onImeActionPerformed callback is called with specified ImeAction.
onFocus: () -> Unit = {} Called when the input field gains focus.
onBlur: () -> Unit = {} Called when the input field loses focus.
focusIdentifier: String? = null Optional value to identify focus identifier. You can pass FocusManager.requestFocus to this value to move focus to this TextField. This identifier must be unique in your app. If you have duplicated identifiers, the behavior is undefined.
onImeActionPerformed: (ImeAction) -> Unit = {} Called when the input service requested an IME action. When the input service emitted an IME action, this callback is called with the emitted IME action. Note that this IME action may be different from what you specified in imeAction.
visualTransformation: VisualTransformation? = null Optional visual filter for changing visual output of input field.

TextField

@Composable fun TextField(
    model: TextFieldValue,
    compositionRange: TextRange?,
    modifier: Modifier = Modifier.None,
    onValueChange: (TextFieldValue, TextRange?) -> Unit = { _, _ -> },
    textStyle: TextStyle? = null,
    keyboardType: KeyboardType = KeyboardType.Text,
    imeAction: ImeAction = ImeAction.Unspecified,
    onFocus: () -> Unit = {},
    onBlur: () -> Unit = {},
    focusIdentifier: String? = null,
    onImeActionPerformed: (ImeAction) -> Unit = {},
    visualTransformation: VisualTransformation? = null
): Unit

A user interface element for entering and modifying text.

The TextField component renders an input and additional decorations set by input service which is software keyboard in Android. Once input service modify the text, you will get callback onValueChange with new text. Then, you can set this new text so that this component renders up-to-date text from input service.

Example usage:

import androidx.compose.state
import androidx.ui.core.TextField
import androidx.ui.text.TextFieldValue

val model = state { TextFieldValue() }
val composition = state<TextRange?> { null }
TextField(
    model = model.value,
    compositionRange = composition.value,
    onValueChange = { newModel, newComposition ->
        model.value = newModel
        composition.value = newComposition
    }
)

It is not recommended to use this component unless you are interested in composition region. The composition text is set by input service and you don't have control of it. If you modify composition, the input service may confuse and restart new input session. Also please do not expect no composition range at the beginning of input session. The input service may convert existing text to composition text at the beginning of the input session.

Note: Please be careful if you setting model other than the one passed to onValueChange callback including selection or cursor. Especially, it is not recommended to modify the model passed to onValueChange callback. Any change to text, selection or cursor may be translated to full context reset by input service and end up with input session restart. This will be visible to users, for example, any ongoing composition text will be cleared or committed, then software keyboard may go back to the default one.

Parameters
model: TextFieldValue The TextFieldValue to be shown in the TextField.
onValueChange: (TextFieldValue, TextRange?) -> Unit = { _, _ -> } Called when the input service updates the text, selection or cursor. When the input service update the text, selection or cursor, this callback is called with the updated TextFieldValue.
textStyle: TextStyle? = null Style configuration that applies at character level such as color, font etc.
keyboardType: KeyboardType = KeyboardType.Text The keyboard type to be used in this text field. Note that this input type is honored by IME and shows corresponding keyboard but this is not guaranteed. For example, some IME may send non-ASCII character even if you set KeyboardType.Ascii.
imeAction: ImeAction = ImeAction.Unspecified The IME action. This IME action is honored by IME and may show specific icons on the keyboard. For example, search icon may be shown if ImeAction.Search is specified. Then, when user tap that key, the onImeActionPerformed callback is called with specified ImeAction.
onFocus: () -> Unit = {} Called when the input field gains focus.
onBlur: () -> Unit = {} Called when the input field loses focus.
focusIdentifier: String? = null Optional value to identify focus identifier. You can pass FocusManager.requestFocus to this value to move focus to this TextField. This identifier must be unique in your app. If you have duplicated identifiers, the behavior is undefined.
onImeActionPerformed: (ImeAction) -> Unit = {} Called when the input service requested an IME action. When the input service emitted an IME action, this callback is called with the emitted IME action. Note that this IME action may be different from what you specified in imeAction.
visualTransformation: VisualTransformation? = null Optional visual filter for changing visual output of input field.

WithConstraints

@Composable fun WithConstraints(
    modifier: Modifier = Modifier.None,
    children: (Constraints) -> Unit
): Unit

A composable that defines its own content according to the available space, based on the incoming constraints. Example usage:

import androidx.ui.core.WithConstraints

WithConstraints { constraints ->
    val rectangleHeight = 100.dp
    val threshold = with(DensityAmbient.current) { (rectangleHeight * 2).toIntPx() }
    if (constraints.maxHeight < threshold) {
        SizedRectangle(color = Color.Blue, width = 50.dp, height = rectangleHeight)
    } else {
        Column {
            SizedRectangle(color = Color.Blue, width = 50.dp, height = rectangleHeight)
            SizedRectangle(color = Color.Gray, width = 50.dp, height = rectangleHeight)
        }
    }
}
The composable will compose the given children, and will position the resulting layout composablesin a parent Layout. This layout will be as small as possible such that it can fit itschildren. If the composition yields multiple layout children, these will be all placed at thetop left of the WithConstraints, so consider wrapping them in an additional commonparent if different positioning is preferred.
Parameters
modifier: Modifier = Modifier.None Modifier to be applied to the introduced layout.

currentTextStyle

@Composable fun currentTextStyle(): TextStyle

This effect is used to read the current value of the Text style ambient. Any Text components included in this component's children will be styled with this style unless styled explicitly.

disposeActivityComposition

fun disposeActivityComposition(activity: Activity): Unit

Disposes the root view of the Activity.

draw

fun draw(onDraw: Density.(canvas: Canvas, size: PxSize) -> Unit): DrawModifier

Creates a DrawModifier that calls onDraw before the contents of the layout.

drawWithContent

fun drawWithContent(onDraw: DrawReceiver.(canvas: Canvas, size: PxSize) -> Unit): DrawModifier

Creates a DrawModifier that allows the developer to draw before or after the layout's contents. It also allows the modifier to adjust the layout's canvas.

isPopupLayout

@TestOnly fun isPopupLayout(
    view: View,
    testTag: String? = null
): Boolean

Returns whether the given view is an underlying decor view of a popup. If the given testTag is supplied it also verifies that the popup has such tag assigned.

Parameters
view: View View to verify.
testTag: String? = null If provided, tests that the given tag in defined on the popup.

simpleIdentityToString

fun simpleIdentityToString(
    obj: Any,
    name: String? = null
): String

Top-level properties

AndroidComposeViewAmbient

val AndroidComposeViewAmbient: ProvidableAmbient<AndroidComposeView>

AnimationClockAmbient

val AnimationClockAmbient: ProvidableAmbient<AnimationClockObservable>

AutofillAmbient

val AutofillAmbient: ProvidableAmbient<Autofill?>

AutofillTreeAmbient

val AutofillTreeAmbient: ProvidableAmbient<AutofillTree>

ConfigurationAmbient

val ConfigurationAmbient: ProvidableAmbient<Configuration>

ContextAmbient

val ContextAmbient: ProvidableAmbient<Context>

CoroutineContextAmbient

val CoroutineContextAmbient: ProvidableAmbient<CoroutineContext>

DensityAmbient

val DensityAmbient: ProvidableAmbient<Density>

FirstBaseline

val FirstBaseline: HorizontalAlignmentLine

AlignmentLine defined by the baseline of a first line of a Text.

FocusManagerAmbient

val FocusManagerAmbient: ProvidableAmbient<FocusManager>

FontLoaderAmbient

val FontLoaderAmbient: ProvidableAmbient<Font.ResourceLoader>

HapticFeedBackAmbient

val HapticFeedBackAmbient: ProvidableAmbient<HapticFeedback>

The ambient to provide haptic feedback to the user.

LastBaseline

val LastBaseline: HorizontalAlignmentLine

AlignmentLine defined by the baseline of the last line of a Text.

LayoutDirectionAmbient

val LayoutDirectionAmbient: ProvidableAmbient<LayoutDirection>

OnChildPositionedKey

val OnChildPositionedKey: DataNodeKey<(LayoutCoordinates) -> Unit>

DataNodeKey for OnChildPositioned callback

OnPositionedKey

val OnPositionedKey: DataNodeKey<(LayoutCoordinates) -> Unit>

DataNodeKey for OnPositioned callback

ParentDataKey

val ParentDataKey: DataNodeKey<Any>

DataNodeKey for ParentData

TextInputServiceAmbient

val TextInputServiceAmbient: ProvidableAmbient<TextInputService?>

Extension functions

add

fun ComponentNode.add(child: ComponentNode): Unit

Inserts a child ComponentNode at a last index. If this ComponentNode isAttached then child will become isAttacheded also. child must have a null ComponentNode.parent.

anyPositionChangeConsumed

fun PointerInputChange.anyPositionChangeConsumed(): Boolean

changedToDown

fun PointerInputChange.changedToDown(): Boolean

changedToDownIgnoreConsumed

fun PointerInputChange.changedToDownIgnoreConsumed(): Boolean

changedToUp

fun PointerInputChange.changedToUp(): Boolean

changedToUpIgnoreConsumed

fun PointerInputChange.changedToUpIgnoreConsumed(): Boolean

constrain

fun Constraints.constrain(size: IntPxSize): IntPxSize

Takes a size and returns the closest size to it that satisfies the constraints.

consumeDownChange

fun PointerInputChange.consumeDownChange(): PointerInputChange

consumePositionChange

fun PointerInputChange.consumePositionChange(
    consumedDx: Px,
    consumedDy: Px
): PointerInputChange

enforce

fun Constraints.enforce(otherConstraints: Constraints): Constraints

Returns the result of coercing the current constraints in a different set of constraints.

findClosestParentNode

fun ComponentNode.findClosestParentNode(selector: (ComponentNode) -> Boolean): ComponentNode?

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

findClosestParentNode

fun SemanticsNode.findClosestParentNode(selector: (SemanticsNode) -> Boolean): SemanticsNode?

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

findLastLayoutChild

fun ComponentNode.findLastLayoutChild(block: (LayoutNode) -> Boolean): LayoutNode?

Executes block on first level of LayoutNode descendants of this ComponentNode and returns the last LayoutNode to return true from block.

hasNoLayoutDescendants

fun ComponentNode.hasNoLayoutDescendants(): Boolean

Returns true if this ComponentNode has no descendant LayoutNodes.

isAttached

fun ComponentNode.isAttached(): Boolean

Returns true if this ComponentNode currently has an ComponentNode.owner. Semantically, this means that the ComponentNode is currently a part of a component tree.

merge

fun AlignmentLine.merge(
    position1: IntPx,
    position2: IntPx
): IntPx

Merges two values of the current alignment line.

offset

fun Constraints.offset(
    horizontal: IntPx = 0.ipx,
    vertical: IntPx = 0.ipx
): Constraints

Returns the Constraints obtained by offsetting the current instance with the given values.

positionChange

fun PointerInputChange.positionChange(): PxPosition

positionChangeIgnoreConsumed

fun PointerInputChange.positionChangeIgnoreConsumed(): PxPosition

positionChanged

fun PointerInputChange.positionChanged(): Boolean

positionChangedIgnoreConsumed

fun PointerInputChange.positionChangedIgnoreConsumed(): Boolean

requireOwner

fun ComponentNode.requireOwner(): Owner

Returns ComponentNode.owner or throws if it is null.

satisfiedBy

fun Constraints.satisfiedBy(size: IntPxSize): Boolean

Takes a size and returns whether it satisfies the current constraints.

setContent

fun Activity.setContent(content: () -> Unit): Composition

Composes the given composable into the given activity. The composable will become the root view of the given activity.

Parameters
content: () -> Unit Composable that will be the content of the activity.

setContent

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

Composes the given composable into the given view.

Parameters
content: () -> Unit Composable that will be the content of the view.

toFrameworkRect

fun Rect.toFrameworkRect(): Rect

toFrameworkRectF

fun Rect.toFrameworkRectF(): RectF

toModifier

@Composable fun Painter.toModifier(
    alpha: Float = DefaultAlpha,
    colorFilter: ColorFilter? = null,
    rtl: Boolean = false
): DrawModifier

Create a DrawModifier from this Painter. This modifier is memoized and re-used across subsequent compositions

import androidx.ui.core.toModifier
import androidx.ui.foundation.DrawBackground
import androidx.ui.geometry.Offset
import androidx.ui.graphics.ColorFilter
import androidx.ui.graphics.Paint
import androidx.ui.layout.Container
import androidx.ui.layout.LayoutPadding
import androidx.ui.unit.Px
import androidx.ui.unit.PxSize

class CustomPainter : Painter() {

    val paint = Paint().apply {
        this.color = Color.Red
    }

    override val intrinsicSize: PxSize
        get() = PxSize(
            Px(300.0f),
            Px(300.0f)
        )

    override fun onDraw(canvas: Canvas, bounds: PxSize) {
        val size = intrinsicSize
        val width = size.width.value
        val height = size.height.value
        canvas.drawCircle(
            Offset(
                width / 2.0f,
                height / 2.0f
            ),
            width / 2.0f,
            paint
        )
    }
}

Container(
    modifier =
    DrawBackground(Color.Gray) +
            LayoutPadding(30.dp) +
            DrawBackground(Color.Yellow) +
            CustomPainter().toModifier(
                alpha = 0.5f,
                colorFilter = ColorFilter(Color.Cyan, BlendMode.srcIn)
            ),
    width = 300.dp,
    height = 300.dp
) { /* intentionally empty */ }

visitLayoutChildren

fun ComponentNode.visitLayoutChildren(block: (LayoutNode) -> Unit): Unit

Executes block on first level of LayoutNode descendants of this ComponentNode.

Extension properties

boundsInRoot

inline val LayoutCoordinates.boundsInRoot: PxBounds

The boundaries of this layout inside the root composable.

globalBounds

inline val LayoutCoordinates.globalBounds: PxBounds

The global boundaries of this layout inside.

globalPosition

inline val LayoutCoordinates.globalPosition: PxPosition

The global position of this layout.

hasBoundedHeight

val Constraints.hasBoundedHeight: Boolean

Whether or not the upper bound on the maximum height.

See Also

hasBoundedWidth

val Constraints.hasBoundedWidth: Boolean

Whether or not the upper bound on the maximum width.

See Also

hasFixedHeight

val Constraints.hasFixedHeight: Boolean

Whether there is exactly one height value that satisfies the constraints.

hasFixedWidth

val Constraints.hasFixedWidth: Boolean

Whether there is exactly one width value that satisfies the constraints.

isZero

val Constraints.isZero: Boolean

Whether the area of a component respecting these constraints will definitely be 0. This is true when at least one of maxWidth and maxHeight are 0.

positionInRoot

inline val LayoutCoordinates.positionInRoot: PxPosition

The position of this layout inside the root composable.

tag

val Measurable.tag: Any?

Retrieves the tag associated to a composable with the LayoutTag modifier. For a parent data value to be returned by this property when not using the LayoutTag modifier, the parent data value should implement the LayoutTagParentData interface.