androidx.ui.core

Classes

AbsoluteAlignment

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

AlignmentLine

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

CombinedModifier

A node in a Modifier chain.

Constraints

Immutable constraints used for measuring child Layouts or LayoutModifiers.

Constraints2

Immutable constraints used for measuring child Layouts or LayoutModifiers.

ConsumedData

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

ContentDrawScope

Receiver scope for drawing content into a layout, where the content can be drawn between other canvas operations.

FixedScale

ContentScale implementation that always scales the dimension by the provided fixed floating point value

HorizontalAlignmentLine

A horizontal AlignmentLine.

IntrinsicMeasureScope

The receiver scope of a layout's intrinsic measurements lambdas.

LayoutNode

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

Measured

Read-only wrapper over Placeable that exposes the measurement result with no placing ability.

MeasureScope

The receiver scope of a layout's measure lambda.

ModelObserver

Allows for easy model read observation.

ModifierInfo

Used by tooling to examine the modifiers on a LayoutNode.

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.

Ref

Value holder general purpose class.

TransformOrigin

A two-dimensional position represented as a fraction of the Layer's width and height

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

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

AndroidOwner
AndroidOwner(context: Context, lifecycleOwner: LifecycleOwner? = null)

Constraints2
Constraints2(minWidth: Int = 0, maxWidth: Int = Constraints2.Infinity, minHeight: Int = 0, maxHeight: Int = Constraints2.Infinity)

Create a Constraints2.

Unit
DropdownPopup(dropDownAlignment: DropDownAlignment = DropDownAlignment.Start, offset: IntPxPosition = IntPxPosition(IntPx.Zero, IntPx.Zero), isFocusable: Boolean = false, onDismissRequest: () -> Unit = null, children: <ERROR CLASS>, Unit: <ERROR CLASS>)

Opens a popup with the given content.

Unit
Layout(children: <ERROR CLASS>, Unit: <ERROR CLASS>, minIntrinsicWidthMeasureBlock: IntrinsicMeasureBlock, minIntrinsicHeightMeasureBlock: IntrinsicMeasureBlock, maxIntrinsicWidthMeasureBlock: IntrinsicMeasureBlock, maxIntrinsicHeightMeasureBlock: IntrinsicMeasureBlock, modifier: Modifier = Modifier, measureBlock: MeasureBlock)

Layout is the main core component for layout.

Unit
Layout(children: <ERROR CLASS>, Unit: <ERROR CLASS>, modifier: Modifier = Modifier, 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
MultiMeasureLayout(modifier: Modifier = Modifier, children: <ERROR CLASS>, Unit: <ERROR CLASS>, measureBlock: MeasureBlock)

Unit
PassThroughLayout(modifier: Modifier = Modifier, children: <ERROR CLASS>, Unit: <ERROR CLASS>)

Unit
Popup(alignment: Alignment = Alignment.TopStart, offset: IntPxPosition = IntPxPosition(IntPx.Zero, IntPx.Zero), isFocusable: Boolean = false, onDismissRequest: () -> Unit = null, children: <ERROR CLASS>, Unit: <ERROR CLASS>)

Opens a popup with the given content.

Unit
Popup(popupPositionProvider: PopupPositionProvider, isFocusable: Boolean = false, onDismissRequest: () -> Unit = null, children: <ERROR CLASS>, Unit: <ERROR CLASS>)

Opens a popup with the given content.

Unit
TestTag(tag: String, children: <ERROR CLASS>, Unit: <ERROR CLASS>)

Applies a tag to allow this element to be found in tests.

TransformOrigin
TransformOrigin(pivotFractionX: Float, pivotFractionY: Float)

Constructs a TransformOrigin from the given fractional values from the Layer's width and height

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

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

DrawModifier
draw(onDraw: DrawScope.() -> Unit)

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

DrawModifier

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(context: Context, container: LayoutNode, recomposer: Recomposer, parent: CompositionReference? = null, composable: <ERROR CLASS>, Unit: <ERROR CLASS>)

Composition
subcomposeInto(container: LayoutNode, context: Context, parent: CompositionReference? = null, composable: <ERROR CLASS>, Unit: <ERROR CLASS>)

Top-level properties summary

ProvidableAmbient<AnimationClockObservable>

The default animation clock used for animations when an explicit clock isn't provided.

ProvidableAmbient<Autofill?>

The ambient that can be used to trigger autofill actions.

ProvidableAmbient<AutofillTree>

The ambient that can be used to add AutofillNodes to the autofill tree.

ProvidableAmbient<ClipboardManager>

The ambient to provide communication with platform clipboard service.

ProvidableAmbient<Configuration>

The Android Configuration.

ProvidableAmbient<Context>

Provides a Context that can be used by Android applications.

ProvidableAmbient<Density>

Provides the Density to be used to transform between density-independent pixelunits (DP) and pixel units or scale-independent pixel units (SP) and pixel units.

ProvidableAmbient<FocusManager>

The ambient to provide focus manager.

ProvidableAmbient<HapticFeedback>

The ambient to provide haptic feedback to the user.

ProvidableAmbient<LayoutDirection>

ProvidableAmbient<LifecycleOwner>

The ambient containing the current LifecycleOwner.

ProvidableAmbient<TextInputService?>

The ambient to provide communication with platform text input service.

ProvidableAmbient<TextToolbar>

ProvidableAmbient<UriHandler>

The ambient to provide functionality related to URL, e.

Extension functions summary

For android.app.Activity
Composition
Activity.setViewContent(composable: <ERROR CLASS>, Unit: <ERROR CLASS>)

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
Composition
ViewGroup.setContent(recomposer: Recomposer, content: <ERROR CLASS>, Unit: <ERROR CLASS>)

Composes the given composable into the given view.

Composition
ViewGroup.setContent(content: <ERROR CLASS>, Unit: <ERROR CLASS>)

Composes the given composable into the given view.

Composition
ViewGroup.setViewContent(parent: CompositionReference? = null, composable: <ERROR CLASS>, Unit: <ERROR CLASS>)

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

For androidx.activity.ComponentActivity
Composition
ComponentActivity.setContent(recomposer: Recomposer = Recomposer.current(), content: <ERROR CLASS>, Unit: <ERROR CLASS>)

Composes the given composable into the given activity.

For PointerInputChange
Boolean

True if any aspect of this PointerInputChange has been consumed.

Boolean

True if any of this PointerInputChange's movement has been consumed.

Boolean

True if this PointerInputChange represents a pointer coming in contact with the screen and that change has not been consumed.

Boolean

True if this PointerInputChange represents a pointer coming in contact with the screen, whether or not that change has been consumed.

Boolean

True if this PointerInputChange represents a pointer breaking contact with the screen and that change has not been consumed.

Boolean

True if this PointerInputChange represents a pointer breaking contact with the screen, whether or not that change has been consumed.

PointerInputChange

Consumes all changes associated with the PointerInputChange

PointerInputChange

Consume the up or down change of this PointerInputChange if there is an up or down change to consume.

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

Consumes some portion of the position change of this PointerInputChange.

PxPosition

The distance that the pointer has moved on the screen minus any distance that has been consumed.

PxPosition

The distance that the pointer has moved on the screen, ignoring any distance that may have been consumed.

Boolean

True if this PointerInputChange represents a pointer moving on the screen and some of that movement has not been consumed.

Boolean

True if this PointerInputChange represents a pointer moving on the screen ignoring how much of that movement may have been consumed.

For Painter
DrawModifier
Painter.asModifier(sizeToIntrinsics: Boolean = true, alignment: Alignment = Alignment.Center, contentScale: ContentScale = ContentScale.Inside, alpha: Float = DefaultAlpha, colorFilter: ColorFilter? = null, rtl: Boolean = false)

Create a DrawModifier from this Painter.

For Modifier
Modifier

Clip the content to shape.

Modifier

Clip the content to the bounds of a layer defined at this modifier.

Modifier
Modifier.composed(factory: Modifier.() -> Modifier)

Declare a just-in-time composition of a Modifier that will be composed for each element it modifies.

Modifier
Modifier.drawBehind(onDraw: DrawScope.() -> Unit)

Draw into a Canvas behind the modified content.

Modifier
Modifier.drawLayer(scaleX: Float = 1f, scaleY: Float = 1f, alpha: Float = 1f, translationX: Float = 0f, translationY: Float = 0f, shadowElevation: Float = 0f, rotationX: Float = 0f, rotationY: Float = 0f, rotationZ: Float = 0f, transformOrigin: TransformOrigin = TransformOrigin.Center, shape: Shape = RectangleShape, clip: Boolean = false)

Draw the content into a layer.

Modifier

Draw content with modified opacity (alpha) that may be less than 1.

Modifier
Modifier.drawShadow(elevation: Dp, shape: Shape = RectangleShape, clip: Boolean = elevation > 0.dp, opacity: Float = 1f)

Creates a DrawLayerModifier that draws the shadow.

Modifier

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

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

Invoke onChildPositioned with the LayoutCoordinates of each child element after each one is positioned.

Modifier

Invoke onPositioned with the LayoutCoordinates of the element after positioning.

Modifier
Modifier.paint(painter: Painter, sizeToIntrinsics: Boolean = true, alignment: Alignment = Alignment.Center, contentScale: ContentScale = ContentScale.Inside, alpha: Float = DefaultAlpha, colorFilter: ColorFilter? = null)

Paint the content using painter.

Modifier

Tag the element with tag to identify the element within its parent.

Modifier

Applies a tag to allow modified element to be found in tests.

Modifier

Creates a ZIndexModifier that controls the drawing order for the children of the same layout parent.

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 Constraints2
IntSize

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

Constraints2
Constraints2.enforce(otherConstraints: Constraints2)

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

Constraints2
Constraints2.offset(horizontal: Int = 0, vertical: Int = 0)

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 LayoutNode
LayoutNode?

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

For Composer
Modifier

Materialize any instance-specific composed modifiers for applying to a raw tree node.

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

Merges two values of the current alignment line.

For ContentScale
Float
ContentScale.scale(srcSize: Size, dstSize: Size)

Convenience method to compute the scale factor from Size parameters

For Rect
Rect

Creates a new instance of android.graphics.Rect with the same bounds specified in the given Rect

RectF

Creates a new instance of android.graphics.RectF with the same bounds specified in the given Rect

Extension properties summary

For android.content.res.Configuration
LayoutDirection

Return the layout direction set by the Locale.

For LayoutCoordinates
PxBounds

Returns the bounding box of the child in the parent's content area, including any clipping done with respect to the parent.

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

Returns the position of the top-left in the parent's content area or (0, 0) for the root.

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

AndroidOwner

fun AndroidOwner(
    context: Context,
    lifecycleOwner: LifecycleOwner? = null
): AndroidOwner

This function creates an instance of AndroidOwner

Parameters
context: Context Context to use to create a View
lifecycleOwner: LifecycleOwner? = null Current LifecycleOwner. When it is not provided we will try to get the owner using ViewTreeLifecycleOwner when we will be attached.

Constraints2

fun Constraints2(
    minWidth: Int = 0,
    maxWidth: Int = Constraints2.Infinity,
    minHeight: Int = 0,
    maxHeight: Int = Constraints2.Infinity
): Constraints2

Create a Constraints2. minWidth and minHeight must be positive and maxWidth and maxHeight must be greater than or equal to minWidth and minHeight, respectively, or Infinity.

@Composable fun DropdownPopup(
    dropDownAlignment: DropDownAlignment = DropDownAlignment.Start,
    offset: IntPxPosition = IntPxPosition(IntPx.Zero, IntPx.Zero),
    isFocusable: Boolean = false,
    onDismissRequest: () -> Unit = null,
    children: <ERROR CLASS>,
    Unit: <ERROR CLASS>
): 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.preferredSize

Box(Modifier.preferredSize(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.Start) {
        // Draw a rectangle shape with rounded corners inside the popup
        Box(
            Modifier.preferredSize(popupWidth, popupHeight),
            shape = RoundedCornerShape(cornerSize),
            backgroundColor = Color.White
        )
    }
}
Parameters
dropDownAlignment: DropDownAlignment = DropDownAlignment.Start The start or end alignment below the parent.
offset: IntPxPosition = IntPxPosition(IntPx.Zero, IntPx.Zero) An offset from the original aligned position of the popup.
isFocusable: Boolean = false Indicates if the popup can grab the focus.
onDismissRequest: () -> Unit = null Executes when the popup tries to dismiss itself. This happens when the popup is focusable and the user clicks outside.
children: <ERROR CLASS> The content to be displayed inside the popup.

Layout

@Composable fun Layout(
    children: <ERROR CLASS>,
    Unit: <ERROR CLASS>,
    minIntrinsicWidthMeasureBlock: IntrinsicMeasureBlock,
    minIntrinsicHeightMeasureBlock: IntrinsicMeasureBlock,
    maxIntrinsicWidthMeasureBlock: IntrinsicMeasureBlock,
    maxIntrinsicHeightMeasureBlock: IntrinsicMeasureBlock,
    modifier: Modifier = Modifier,
    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: <ERROR CLASS> The children composable to be laid out.
modifier: Modifier = Modifier 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: <ERROR CLASS>,
    Unit: <ERROR CLASS>,
    modifier: Modifier = Modifier,
    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: <ERROR CLASS> The children composable to be laid out.
modifier: Modifier = Modifier 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.

MultiMeasureLayout

@Composable fun MultiMeasureLayout(
    modifier: Modifier = Modifier,
    children: <ERROR CLASS>,
    Unit: <ERROR CLASS>,
    measureBlock: MeasureBlock
): Unit

Deprecated.

PassThroughLayout

@Composable fun PassThroughLayout(
    modifier: Modifier = Modifier,
    children: <ERROR CLASS>,
    Unit: <ERROR CLASS>
): Unit

Deprecated.

@Composable fun Popup(
    alignment: Alignment = Alignment.TopStart,
    offset: IntPxPosition = IntPxPosition(IntPx.Zero, IntPx.Zero),
    isFocusable: Boolean = false,
    onDismissRequest: () -> Unit = null,
    children: <ERROR CLASS>,
    Unit: <ERROR CLASS>
): 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.preferredSize

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(
            Modifier.preferredSize(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. Offset respects the Ltr/Rtl context, thus in Ltr it will be added to the original aligned position and in Rtl it will be subtracted from it.
isFocusable: Boolean = false Indicates if the popup can grab the focus.
onDismissRequest: () -> Unit = null Executes when the popup tries to dismiss itself. This happens when the popup is focusable and the user clicks outside.
children: <ERROR CLASS> The content to be displayed inside the popup.
@Composable fun Popup(
    popupPositionProvider: PopupPositionProvider,
    isFocusable: Boolean = false,
    onDismissRequest: () -> Unit = null,
    children: <ERROR CLASS>,
    Unit: <ERROR CLASS>
): Unit

Opens a popup with the given content.

The popup is positioned using a custom popupPositionProvider.

import androidx.ui.core.Popup
import androidx.ui.foundation.Box
import androidx.ui.foundation.shape.corner.RoundedCornerShape
import androidx.ui.layout.preferredSize

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(
            Modifier.preferredSize(popupWidth, popupHeight),
            shape = RoundedCornerShape(cornerSize),
            backgroundColor = Color.White
        )
    }
}
Parameters
popupPositionProvider: PopupPositionProvider Provides the screen position of the popup.
isFocusable: Boolean = false Indicates if the popup can grab the focus.
onDismissRequest: () -> Unit = null Executes when the popup tries to dismiss itself. This happens when the popup is focusable and the user clicks outside.
children: <ERROR CLASS> The content to be displayed inside the popup.

TestTag

@Composable fun TestTag(
    tag: String,
    children: <ERROR CLASS>,
    Unit: <ERROR CLASS>
): Unit

Applies a tag to allow this element to be found in tests.

This is a convenience method for a Semantics that sets SemanticsPropertyReceiver.testTag.

Note that this does not, by itself, create a semantics boundary. If the element you are setting this on does not already create a boundary, you will need to create one.

TransformOrigin

inline fun TransformOrigin(
    pivotFractionX: Float,
    pivotFractionY: Float
): TransformOrigin

Constructs a TransformOrigin from the given fractional values from the Layer's width and height

WithConstraints

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

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

import androidx.ui.core.WithConstraints
import androidx.ui.foundation.Box
import androidx.ui.layout.Column
import androidx.ui.layout.preferredSize

WithConstraints {
    val rectangleHeight = 100.dp
    if (maxHeight < rectangleHeight * 2) {
        Box(Modifier.preferredSize(50.dp, rectangleHeight), backgroundColor = Color.Blue)
    } else {
        Column {
            Box(Modifier.preferredSize(50.dp, rectangleHeight), backgroundColor = Color.Blue)
            Box(Modifier.preferredSize(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 Modifier to be applied to the introduced layout.

draw

fun draw(onDraw: DrawScope.() -> Unit): DrawModifier

Deprecated.

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

drawWithContent

fun drawWithContent(onDraw: ContentDrawScope.() -> Unit): DrawModifier

Deprecated.

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

Deprecated.

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

Column(Modifier.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(Modifier.preferredSize(20.dp), backgroundColor = Color.Green)
}

onPositioned

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

Deprecated.

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

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

simpleIdentityToString

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

subcomposeInto

@MainThread fun subcomposeInto(
    context: Context,
    container: LayoutNode,
    recomposer: Recomposer,
    parent: CompositionReference? = null,
    composable: <ERROR CLASS>,
    Unit: <ERROR CLASS>
): Composition

subcomposeInto

@MainThread fun subcomposeInto(
    container: LayoutNode,
    context: Context,
    parent: CompositionReference? = null,
    composable: <ERROR CLASS>,
    Unit: <ERROR CLASS>
): Composition

Deprecated.

Top-level properties

AnimationClockAmbient

val AnimationClockAmbient: ProvidableAmbient<AnimationClockObservable>

The default animation clock used for animations when an explicit clock isn't provided.

AutofillAmbient

val AutofillAmbient: ProvidableAmbient<Autofill?>

The ambient that can be used to trigger autofill actions. Eg. Autofill.requestAutofillForNode.

AutofillTreeAmbient

val AutofillTreeAmbient: ProvidableAmbient<AutofillTree>

The ambient that can be used to add AutofillNodes to the autofill tree. The AutofillTree is a temporary data structure that will be replaced by Autofill Semantics (b/138604305).

ClipboardManagerAmbient

val ClipboardManagerAmbient: ProvidableAmbient<ClipboardManager>

The ambient to provide communication with platform clipboard service.

ConfigurationAmbient

val ConfigurationAmbient: ProvidableAmbient<Configuration>

The Android Configuration. The Configuration is useful for determining how to organize the UI.

ContextAmbient

val ContextAmbient: ProvidableAmbient<Context>

Provides a Context that can be used by Android applications.

DensityAmbient

val DensityAmbient: ProvidableAmbient<Density>

Provides the Density to be used to transform between density-independent pixelunits (DP) and pixel units or scale-independent pixel units (SP) and pixel units. This is typically used when a DP is provided and it must be converted in the body of Layout or DrawModifier.

FocusManagerAmbient

val FocusManagerAmbient: ProvidableAmbient<FocusManager>

Deprecated.

The ambient to provide focus manager.

HapticFeedBackAmbient

val HapticFeedBackAmbient: ProvidableAmbient<HapticFeedback>

The ambient to provide haptic feedback to the user.

LayoutDirectionAmbient

val LayoutDirectionAmbient: ProvidableAmbient<LayoutDirection>

Deprecated.

LifecycleOwnerAmbient

val LifecycleOwnerAmbient: ProvidableAmbient<LifecycleOwner>

The ambient containing the current LifecycleOwner.

TextInputServiceAmbient

val TextInputServiceAmbient: ProvidableAmbient<TextInputService?>

The ambient to provide communication with platform text input service.

TextToolbarAmbient

val TextToolbarAmbient: ProvidableAmbient<TextToolbar>

UriHandlerAmbient

val UriHandlerAmbient: ProvidableAmbient<UriHandler>

The ambient to provide functionality related to URL, e.g. open URI.

Extension functions

anyChangeConsumed

fun PointerInputChange.anyChangeConsumed(): Boolean

True if any aspect of this PointerInputChange has been consumed.

anyPositionChangeConsumed

fun PointerInputChange.anyPositionChangeConsumed(): Boolean

True if any of this PointerInputChange's movement has been consumed.

asModifier

@Composable fun Painter.asModifier(
    sizeToIntrinsics: Boolean = true,
    alignment: Alignment = Alignment.Center,
    contentScale: ContentScale = ContentScale.Inside,
    alpha: Float = DefaultAlpha,
    colorFilter: ColorFilter? = null,
    rtl: Boolean = false
): DrawModifier

Deprecated.

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

import androidx.ui.foundation.Image
import androidx.ui.foundation.drawBackground
import androidx.ui.geometry.Size
import androidx.ui.layout.padding

class CustomPainter : Painter() {

    override val intrinsicSize: Size
        get() = Size(300.0f, 300.0f)

    override fun DrawScope.onDraw() {
        drawCircle(
            center = center,
            radius = size.minDimension / 2.0f,
            color = Color.Red
        )
    }
}

Image(
    modifier =
        Modifier.drawBackground(Color.Gray)
            .padding(30.dp)
            .drawBackground(Color.Yellow),
    painter = CustomPainter()
)
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
contentScale: ContentScale = ContentScale.Inside : Specifies the rule used to scale the content of the Painter within the specified bounds, the default of ContentScale.Inside 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

True if this PointerInputChange represents a pointer coming in contact with the screen and that change has not been consumed.

changedToDownIgnoreConsumed

fun PointerInputChange.changedToDownIgnoreConsumed(): Boolean

True if this PointerInputChange represents a pointer coming in contact with the screen, whether or not that change has been consumed.

changedToUp

fun PointerInputChange.changedToUp(): Boolean

True if this PointerInputChange represents a pointer breaking contact with the screen and that change has not been consumed.

changedToUpIgnoreConsumed

fun PointerInputChange.changedToUpIgnoreConsumed(): Boolean

True if this PointerInputChange represents a pointer breaking contact with the screen, whether or not that change has been consumed.

clip

fun Modifier.clip(shape: Shape): Modifier

Clip the content to shape.

Parameters
shape: Shape the content will be clipped to this Shape.

clipToBounds

fun Modifier.clipToBounds(): Modifier

Clip the content to the bounds of a layer defined at this modifier.

composed

fun Modifier.composed(factory: Modifier.() -> Modifier): Modifier

Declare a just-in-time composition of a Modifier that will be composed for each element it modifies. composed may be used to implement stateful modifiers that have instance-specific state for each modified element, allowing the same Modifier instance to be safely reused for multiple elements while maintaining element-specific state.

materialize must be called to create instance-specific modifiers if you are directly applying a Modifier to an element tree node.

constrain

fun Constraints.constrain(size: IntPxSize): IntPxSize

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

constrain

fun Constraints2.constrain(size: IntSize): IntSize

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

consumeAllChanges

fun PointerInputChange.consumeAllChanges(): PointerInputChange

Consumes all changes associated with the PointerInputChange

Note: This function creates a modified copy of this PointerInputChange

consumeDownChange

fun PointerInputChange.consumeDownChange(): PointerInputChange

Consume the up or down change of this PointerInputChange if there is an up or down change to consume.

Note: This function creates a modified copy of this PointerInputChange.

consumePositionChange

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

Consumes some portion of the position change of this PointerInputChange.

Note: This function creates a modified copy of this PointerInputChange

Parameters
consumedDx: Px The amount of position change on the x axis to consume.
consumedDy: Px The amount of position change on the y axis to consume.

drawBehind

fun Modifier.drawBehind(onDraw: DrawScope.() -> Unit): Modifier

Draw into a Canvas behind the modified content.

drawLayer

fun Modifier.drawLayer(
    scaleX: Float = 1f,
    scaleY: Float = 1f,
    alpha: Float = 1f,
    translationX: Float = 0f,
    translationY: Float = 0f,
    shadowElevation: Float = 0f,
    rotationX: Float = 0f,
    rotationY: Float = 0f,
    rotationZ: Float = 0f,
    transformOrigin: TransformOrigin = TransformOrigin.Center,
    shape: Shape = RectangleShape,
    clip: Boolean = false
): Modifier

Draw the content into a layer. This permits applying special effects and transformations:

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

Text("Hello World", Modifier.drawLayer(alpha = 0.5f, clip = true))
Parameters
scaleX: Float = 1f DrawLayerModifier.scaleX
scaleY: Float = 1f DrawLayerModifier.scaleY
alpha: Float = 1f DrawLayerModifier.alpha
shadowElevation: Float = 0f DrawLayerModifier.shadowElevation
rotationX: Float = 0f DrawLayerModifier.rotationX
rotationY: Float = 0f DrawLayerModifier.rotationY
rotationZ: Float = 0f DrawLayerModifier.rotationZ
shape: Shape = RectangleShape DrawLayerModifier.shape
clip: Boolean = false DrawLayerModifier.clip

drawOpacity

fun Modifier.drawOpacity(opacity: Float): Modifier

Draw content with modified opacity (alpha) that may be less than 1.

Example usage:

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

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

drawShadow

fun Modifier.drawShadow(
    elevation: Dp,
    shape: Shape = RectangleShape,
    clip: Boolean = elevation > 0.dp,
    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.

Note that elevation is only affecting the shadow size and doesn't change the drawing order. Use zIndex modifier if you want to draw the elements with larger elevation after all the elements with a smaller one.

Example usage:

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

Box(
    Modifier.drawShadow(12.dp, RectangleShape)
        .preferredSize(100.dp, 100.dp)
)
Parameters
elevation: Dp The elevation for the shadow in pixels
shape: Shape = RectangleShape Defines a shape of the physical object
clip: Boolean = elevation > 0.dp When active, the content drawing clips to the shape.
opacity: Float = 1f The opacity of the layer, including the shadow.

drawWithContent

fun Modifier.drawWithContent(onDraw: ContentDrawScope.() -> Unit): Modifier

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.

enforce

fun Constraints.enforce(otherConstraints: Constraints): Constraints

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

enforce

fun Constraints2.enforce(otherConstraints: Constraints2): Constraints2

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

findClosestParentNode

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

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

materialize

fun Composer<*>.materialize(modifier: Modifier): Modifier

Materialize any instance-specific composed modifiers for applying to a raw tree node. Call right before setting the returned modifier on an emitted node. You almost certainly do not need to call this function directly.

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.

offset

fun Constraints2.offset(
    horizontal: Int = 0,
    vertical: Int = 0
): Constraints2

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

onChildPositioned

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

Invoke onChildPositioned with the LayoutCoordinates of each child element after each one is positioned. 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.preferredSize

Column(Modifier.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(Modifier.preferredSize(20.dp), backgroundColor = Color.Green)
}

onPositioned

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

Invoke onPositioned with the LayoutCoordinates of the element after positioning. 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.preferredSize

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

paint

fun Modifier.paint(
    painter: Painter,
    sizeToIntrinsics: Boolean = true,
    alignment: Alignment = Alignment.Center,
    contentScale: ContentScale = ContentScale.Inside,
    alpha: Float = DefaultAlpha,
    colorFilter: ColorFilter? = null
): Modifier

Paint the content using painter.

Parameters
sizeToIntrinsics: Boolean = true true to size the element relative to Painter.intrinsicSize
alignment: Alignment = Alignment.Center specifies alignment of the painter relative to content
contentScale: ContentScale = ContentScale.Inside strategy for scaling painter if its size does not match the content size
alpha: Float = DefaultAlpha opacity of painter
colorFilter: ColorFilter? = null optional ColorFilter to apply to painter

positionChange

fun PointerInputChange.positionChange(): PxPosition

The distance that the pointer has moved on the screen minus any distance that has been consumed.

positionChangeIgnoreConsumed

fun PointerInputChange.positionChangeIgnoreConsumed(): PxPosition

The distance that the pointer has moved on the screen, ignoring any distance that may have been consumed.

positionChanged

fun PointerInputChange.positionChanged(): Boolean

True if this PointerInputChange represents a pointer moving on the screen and some of that movement has not been consumed.

positionChangedIgnoreConsumed

fun PointerInputChange.positionChangedIgnoreConsumed(): Boolean

True if this PointerInputChange represents a pointer moving on the screen ignoring how much of that movement may have been consumed.

satisfiedBy

fun Constraints.satisfiedBy(size: IntPxSize): Boolean

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

satisfiedBy

fun Constraints2.satisfiedBy(size: IntSize): Boolean

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

scale

fun ContentScale.scale(
    srcSize: Size,
    dstSize: Size
): Float

Convenience method to compute the scale factor from Size parameters

setContent

fun ViewGroup.setContent(
    recomposer: Recomposer,
    content: <ERROR CLASS>,
    Unit: <ERROR CLASS>
): Composition

Composes the given composable into the given view.

Note that this ViewGroup should have an unique id for the saved instance state mechanism to be able to save and restore the values used within the composition. See View.setId.

Parameters
recomposer: Recomposer The Recomposer to coordinate scheduling of composition updates
content: <ERROR CLASS> Composable that will be the content of the view.

setContent

fun ViewGroup.setContent(
    content: <ERROR CLASS>,
    Unit: <ERROR CLASS>
): Composition

Deprecated.

Composes the given composable into the given view.

Note that this ViewGroup should have an unique id for the saved instance state mechanism to be able to save and restore the values used within the composition. See View.setId.

Parameters
content: <ERROR CLASS> Composable that will be the content of the view.

setContent

fun ComponentActivity.setContent(
    recomposer: Recomposer = Recomposer.current(),
    content: <ERROR CLASS>,
    Unit: <ERROR CLASS>
): Composition

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

Composition.dispose is called automatically when the Activity is destroyed.

Parameters
recomposer: Recomposer = Recomposer.current() The Recomposer to coordinate scheduling of composition updates
content: <ERROR CLASS> A @Composable function declaring the UI contents

setViewContent

fun Activity.setViewContent(
    composable: <ERROR CLASS>,
    Unit: <ERROR CLASS>
): 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: <ERROR CLASS>,
    Unit: <ERROR CLASS>
): Composition

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

tag

fun Modifier.tag(tag: Any): Modifier

Tag the element with tag to identify the element within its parent.

testTag

fun Modifier.testTag(tag: String): Modifier

Applies a tag to allow modified element to be found in tests.

This is a convenience method for a semantics that sets SemanticsPropertyReceiver.testTag.

Note that this does not, by itself, create a semantics boundary. If the element you are setting this on does not already create a boundary, you will need to create one.

toAndroidRect

fun Rect.toAndroidRect(): Rect

Creates a new instance of android.graphics.Rect with the same bounds specified in the given Rect

toAndroidRectF

fun Rect.toAndroidRectF(): RectF

Creates a new instance of android.graphics.RectF with the same bounds specified in the given Rect

zIndex

fun Modifier.zIndex(zIndex: Float): Modifier

Creates a ZIndexModifier that controls the drawing order for the children of the same layout parent. A child with larger zIndex will be drawn after all the children with smaller zIndex. When children have the same zIndex the original order in which the items were added into the parent layout is applied. Note that if there would be multiple ZIndexModifier modifiers applied for the same layout only the first one in the modifiers chain will be used. If no ZIndexModifiers applied for the layout then zIndex for this Layout is 0.

import androidx.ui.core.zIndex
import androidx.ui.foundation.Text
import androidx.ui.layout.Stack

Stack {
    Text("Drawn second", Modifier.zIndex(1f))
    Text("Drawn first")
}

Extension properties

boundsInParent

val LayoutCoordinates.boundsInParent: PxBounds

Returns the bounding box of the child in the parent's content area, including any clipping done with respect to the parent. For the root, the bounds is positioned at (0, 0) and sized to the size of the root.

boundsInRoot

val LayoutCoordinates.boundsInRoot: PxBounds

The boundaries of this layout inside the root composable.

globalBounds

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.

hasFixedHeight

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

hasFixedWidth

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

isZero

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

localeLayoutDirection

val Configuration.localeLayoutDirection: LayoutDirection

Return the layout direction set by the Locale.

A convenience getter that translates Configuration.getLayoutDirection result into LayoutDirection instance.

positionInParent

val LayoutCoordinates.positionInParent: PxPosition

Returns the position of the top-left in the parent's content area or (0, 0) for the root.

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.