The second Android 11 Developer Preview 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.

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.

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

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
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 = TextStyle.Default, 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.TopStart, offset: IntPxPosition = IntPxPosition(IntPx.Zero, IntPx.Zero), popupProperties: PopupProperties = PopupProperties(), children: () -> Unit)

Opens a popup with the given content.

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

Unit
Text(text: String, modifier: Modifier = Modifier.None, style: TextStyle = TextStyle.Default, 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 = TextStyle.Default, 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 = TextStyle.Default, 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 = TextStyle.Default, 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 = TextStyle.Default, 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, LayoutDirection) -> 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.

Modifier
drawClip(shape: Shape)

Clips the content to shape.

Modifier
drawLayer(drawLayerProperties: DrawLayerProperties)

Create a DrawLayerModifier with a given DrawLayerProperties.

Modifier
drawLayer(scaleX: Float = 1f, scaleY: Float = 1f, alpha: Float = 1f, elevation: Float = 0f, rotationX: Float = 0f, rotationY: Float = 0f, rotationZ: Float = 0f, outlineShape: Shape? = null, clipToBounds: Boolean = true, clipToOutline: Boolean = true)

Create a DrawLayerModifier with fixed properties.

Modifier
drawOpacity(opacity: Float)

Makes its children partially transparent.

Modifier
drawShadow(shape: Shape, elevation: Dp, clipToOutline: Boolean = true, opacity: Float = 1f)

Creates a DrawLayerModifier that draws the shadow.

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.

Modifier
onChildPositioned(onChildPositioned: (LayoutCoordinates) -> Unit)

Returns a modifier whose onChildPositioned is called with the final LayoutCoordinates of the children Layouts after measuring.

Modifier
onPositioned(onPositioned: (LayoutCoordinates) -> Unit)

Returns modifier whose onPositioned is called with the final LayoutCoordinates of the Layout after measuring.

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

Composition
subcomposeInto(container: ComponentNode, context: Context, parent: CompositionReference? = null, composable: () -> Unit)

Top-level properties summary

ProvidableAmbient<AndroidComposeView>

ProvidableAmbient<AnimationClockObservable>

ProvidableAmbient<Autofill?>

ProvidableAmbient<AutofillTree>

ProvidableAmbient<Configuration>

ProvidableAmbient<Context>

ProvidableAmbient<CoroutineContext>

ProvidableAmbient<Density>

Modifier

Clips the content to the bounds of the layer.

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
Unit

Disposes of a composition that was started using setContent.

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

Composes the given composable into the given activity.

Composition
Activity.setViewContent(composable: () -> Unit)

Sets the contentView of an activity to a FrameLayout, and composes the contents of the layout with the passed in composable.

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

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 Painter
DrawModifier
Painter.asModifier(sizeToIntrinsics: Boolean = true, alignment: Alignment = Alignment.Center, scaleFit: ScaleFit = ScaleFit.Fit, alpha: Float = DefaultAlpha, colorFilter: ColorFilter? = null, rtl: Boolean = false)

Create a DrawModifier from this Painter.

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

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

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

Deprecated.

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

The onPaint lambda uses a Density receiver scope, to allow easy translation between Dp, Sp, and Px. The parentSize parameter indicates the layout size of the parent.

Deprecated: Draw composable is a common source of bugs as it's not a layout and takes parent size, but doesn't tell you that. Therefore, layout strategies, like androidx.ui.layout.Row or androidx.ui.layout.Column doesn't work with Draw. You should use draw modifier if you want to decorate existent layout with custom drawing, use existent drawing modifiers (androidx.ui.foundation.DrawBackground, androidx.ui.foundation.DrawBorder, Painter.toModifier)or use androidx.ui.foundation.Canvas to make a layout that takes space and allows custom drawing.

Draw

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

Deprecated.

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.

Deprecated: Draw composable is a common source of bugs as it's not a layout and takes parent size, but doesn't tell you that. Therefore, layout strategies, like androidx.ui.layout.Row or androidx.ui.layout.Column doesn't work with Draw. You should use drawWithContent modifier if you want to decorate existent layout with custom drawing

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.Box
import androidx.ui.foundation.shape.corner.RoundedCornerShape
import androidx.ui.layout.LayoutSize

Box(LayoutSize(400.dp, 200.dp)) {
    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
        Box(
            LayoutSize(popupWidth, popupHeight),
            shape = RoundedCornerShape(cornerSize),
            backgroundColor = 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.

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
import androidx.ui.foundation.Box
import androidx.ui.layout.LayoutSize

Column {
    Box(LayoutSize(20.dp), backgroundColor = Color.Green)
    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
    }) {
        Box(LayoutSize(20.dp), backgroundColor = Color.Blue)
    }
}

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
import androidx.ui.foundation.Box
import androidx.ui.layout.LayoutSize

Column {
    Box(LayoutSize(20.dp), backgroundColor = Color.Green)
    Box(LayoutSize(20.dp), backgroundColor = Color.Blue)
    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
    })
}

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
import androidx.ui.foundation.Box
import androidx.ui.layout.LayoutSize

val parentDataComposable = @Composable {
    ParentData(data = 5) {
        Box(LayoutSize(50.dp), backgroundColor = Color.Blue)
    }
}
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 = TextStyle.Default,
    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 = TextStyle.Default 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.TopStart,
    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.Box
import androidx.ui.foundation.shape.corner.RoundedCornerShape
import androidx.ui.layout.LayoutSize

Box {
    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
        Box(
            LayoutSize(popupWidth, popupHeight),
            shape = RoundedCornerShape(cornerSize),
            backgroundColor = Color.White
        )
    }
}
Parameters
alignment: Alignment = Alignment.TopStart 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.

TestTag

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

Text

@Composable fun Text(
    text: String,
    modifier: Modifier = Modifier.None,
    style: TextStyle = TextStyle.Default,
    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 = TextStyle.Default 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 = TextStyle.Default,
    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 = TextStyle.Default 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 = TextStyle.Default,
    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 = TextStyle.Default 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 = TextStyle.Default,
    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 = TextStyle.Default 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 = TextStyle.Default,
    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 = TextStyle.Default 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, LayoutDirection) -> 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
import androidx.ui.foundation.Box
import androidx.ui.layout.LayoutSize

WithConstraints { constraints, _ ->
    val rectangleHeight = 100.dp
    val threshold = with(DensityAmbient.current) { (rectangleHeight * 2).toIntPx() }
    if (constraints.maxHeight < threshold) {
        Box(LayoutSize(50.dp, rectangleHeight), backgroundColor = Color.Blue)
    } else {
        Column {
            Box(LayoutSize(50.dp, rectangleHeight), backgroundColor = Color.Blue)
            Box(LayoutSize(50.dp, rectangleHeight), backgroundColor = Color.Gray)
        }
    }
}
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

Deprecated.

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.

drawClip

fun drawClip(shape: Shape): Modifier

Clips the content to shape.

drawLayer

fun drawLayer(drawLayerProperties: DrawLayerProperties): Modifier

Create a DrawLayerModifier with a given DrawLayerProperties.

drawLayer

fun drawLayer(
    scaleX: Float = 1f,
    scaleY: Float = 1f,
    alpha: Float = 1f,
    elevation: Float = 0f,
    rotationX: Float = 0f,
    rotationY: Float = 0f,
    rotationZ: Float = 0f,
    outlineShape: Shape? = null,
    clipToBounds: Boolean = true,
    clipToOutline: Boolean = true
): Modifier

Create a DrawLayerModifier with fixed properties.

import androidx.ui.core.drawLayer
import androidx.ui.core.Text

Text("Hello World", drawLayer(alpha = 0.5f))
Parameters
scaleX: Float = 1f DrawLayerProperties.scaleX
scaleY: Float = 1f DrawLayerProperties.scaleY
alpha: Float = 1f DrawLayerProperties.alpha
elevation: Float = 0f DrawLayerProperties.elevation
rotationX: Float = 0f DrawLayerProperties.rotationX
rotationY: Float = 0f DrawLayerProperties.rotationY
rotationZ: Float = 0f DrawLayerProperties.rotationZ
outlineShape: Shape? = null DrawLayerProperties.outlineShape
clipToBounds: Boolean = true DrawLayerProperties.clipToBounds
clipToOutline: Boolean = true DrawLayerProperties.clipToOutline

drawOpacity

fun drawOpacity(opacity: Float): Modifier

Makes its children partially transparent.

Example usage:

import androidx.ui.core.drawOpacity
import androidx.ui.foundation.Box
import androidx.ui.layout.LayoutSize

Box(LayoutSize(100.dp) + drawOpacity(opacity = 0.5f), backgroundColor = Color.Red)
Parameters
opacity: Float the fraction of children's alpha value.

drawShadow

@Composable fun drawShadow(
    shape: Shape,
    elevation: Dp,
    clipToOutline: Boolean = true,
    opacity: Float = 1f
): Modifier

Creates a DrawLayerModifier that draws the shadow. The elevation defines the visual depth of the physical object. The physical object has a shape specified by shape.

Example usage:

import androidx.ui.core.drawShadow
import androidx.ui.foundation.Box
import androidx.ui.layout.LayoutSize

Box(drawShadow(shape = RectangleShape, elevation = 12.dp) + LayoutSize(100.dp, 100.dp))
Parameters
elevation: Dp The z-coordinate at which to place this physical object.
shape: Shape Defines a shape of the physical object
clipToOutline: Boolean = true When active, the content drawing clips to the outline.
opacity: Float = 1f The opacity of the layer, including the shadow.

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.

onChildPositioned

fun onChildPositioned(onChildPositioned: (LayoutCoordinates) -> Unit): Modifier

Returns a modifier whose onChildPositioned is called with the final LayoutCoordinates of the children Layouts after measuring. Note that it will be called after a composition when the coordinates are finalized.

Usage example:

import androidx.ui.core.onChildPositioned
import androidx.ui.foundation.Box
import androidx.ui.layout.Column
import androidx.ui.layout.LayoutSize

Column(onChildPositioned { 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
}) {
    Box(LayoutSize(20.dp), backgroundColor = Color.Green)
}

onPositioned

fun onPositioned(onPositioned: (LayoutCoordinates) -> Unit): Modifier

Returns modifier whose onPositioned is called with the final LayoutCoordinates of the Layout after measuring. Note that it will be called after a composition when the coordinates are finalized.

Usage example:

import androidx.ui.core.onPositioned
import androidx.ui.foundation.Box
import androidx.ui.layout.Column
import androidx.ui.layout.LayoutSize

Column(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
}) {
    Box(LayoutSize(20.dp), backgroundColor = Color.Green)
    Box(LayoutSize(20.dp), backgroundColor = Color.Blue)
}

simpleIdentityToString

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

subcomposeInto

@MainThread fun subcomposeInto(
    container: ComponentNode,
    context: Context,
    parent: CompositionReference? = null,
    composable: () -> Unit
): Composition

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>

DrawClipToBounds

val DrawClipToBounds: Modifier

Clips the content to the bounds of the layer.

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

asModifier

@Composable fun Painter.asModifier(
    sizeToIntrinsics: Boolean = true,
    alignment: Alignment = Alignment.Center,
    scaleFit: ScaleFit = ScaleFit.Fit,
    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.asModifier
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().asModifier(
                alpha = 0.5f,
                colorFilter = ColorFilter(Color.Cyan, BlendMode.srcIn)
            ),
    width = 300.dp,
    height = 300.dp
) { /* intentionally empty */ }
Parameters
sizeToIntrinsics: Boolean = true : Flag to indicate whether this PainterModifier should be involved with appropriately sizing the component it is associated with. True if the intrinsic size should influence the size of the component, false otherwise. A value of false here is equivalent to the underlying Painter having no intrinsic size, that is Painter.intrinsicSize returns PxSize.UnspecifiedSize
alignment: Alignment = Alignment.Center : Specifies the rule used to place the contents of the Painter within the specified bounds, the default of Alignment.Center centers the content within the specified rendering bounds
scaleFit: ScaleFit = ScaleFit.Fit : Specifies the rule used to scale the content of the Painter within the specified bounds, the default of ScaleFit.Fit scales the content to be as large as possible within the specified bounds while still maintaining the aspect ratio of its intrinsic size
alpha: Float = DefaultAlpha : Specifies the opacity to render the contents of the underlying Painter
colorFilter: ColorFilter? = null : Specifies an optional tint to apply to the contents of the Painter when drawn in the specified area
rtl: Boolean = false : Flag to indicate contents of the Painter should render for right to left languages

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

disposeComposition

fun Activity.disposeComposition(): Unit

Deprecated.

Disposes of a composition that was started using setContent. This is a convenience method around Composition.dispose.

disposeComposition

fun ViewGroup.disposeComposition(): Unit

Deprecated.

Disposes of a composition of the children of this view. This is a convenience method around Composition.dispose.

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.

setViewContent

fun Activity.setViewContent(composable: () -> Unit): Composition

Sets the contentView of an activity to a FrameLayout, and composes the contents of the layout with the passed in composable.

setViewContent

fun ViewGroup.setViewContent(
    parent: CompositionReference? = null,
    composable: () -> Unit
): Composition

Composes the children of the view with the passed in composable.

toFrameworkRect

fun Rect.toFrameworkRect(): Rect

toFrameworkRectF

fun Rect.toFrameworkRectF(): RectF

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.