androidx.wear.protolayout.modifiers
Interfaces
LayoutModifier |
An ordered, immutable collection of |
LayoutModifier.Element |
A single element contained within a |
Objects
LayoutModifier.Companion |
The companion object |
Top-level functions summary
ModifiersBuilders.Clickable |
clickable(Creates a |
ActionBuilders.LoadAction |
loadAction(Creates an action used to load (or reload) the layout contents. |
ModifiersBuilders.Padding |
Creates a |
ModifiersBuilders.Padding |
Creates a |
ModifiersBuilders.Padding |
padding(Creates a |
Extension functions summary
LayoutModifier |
@RequiresSchemaVersion(major = 1, minor = 500)Sets the background brush to |
LayoutModifier |
LayoutModifier.background(color: LayoutColor)Sets the background color to |
LayoutModifier |
LayoutModifier.border(width: @Dimension(unit = 0) Float, color: LayoutColor)Adds a modifier to apply a border around an element. |
LayoutModifier |
Clears the semantics, including |
LayoutModifier |
LayoutModifier.clickable(clickable: ModifiersBuilders.Clickable)Adds the clickable property of the modified element. |
LayoutModifier |
LayoutModifier.clickable(action: ActionBuilders.Action, id: String?)Adds the clickable property of the modified element. |
ModifiersBuilders.Clickable |
ProtoLayoutScope.clickable(Creates a |
LayoutModifier |
LayoutModifier.clip(corner: ModifiersBuilders.Corner)Clips the element to a rounded rectangle with corners specified in |
LayoutModifier |
LayoutModifier.clip(cornerRadius: @Dimension(unit = 0) Float)Clips the element to a rounded rectangle with four corners with |
LayoutModifier |
@RequiresSchemaVersion(major = 1, minor = 400)Clips the element to a rounded shape with |
LayoutModifier |
@RequiresSchemaVersion(major = 1, minor = 400)Clips the bottom left corner of the element with |
LayoutModifier |
@RequiresSchemaVersion(major = 1, minor = 400)Clips the bottom right corner of the element with |
LayoutModifier |
@RequiresSchemaVersion(major = 1, minor = 400)Clips the top left corner of the element with |
LayoutModifier |
@RequiresSchemaVersion(major = 1, minor = 400)Clips the top right corner of the element with |
LayoutModifier |
LayoutModifier.contentDescription(Adds content description to be read by accessibility services. |
LayoutModifier |
@RequiresSchemaVersion(major = 1, minor = 200)Adds a modifier to specify content transition that is triggered when element enters the layout. |
LayoutModifier |
@RequiresSchemaVersion(major = 1, minor = 200)Adds a modifier to specify content transition that is triggered when element enters the layout. |
LayoutModifier |
@RequiresSchemaVersion(major = 1, minor = 200)Adds a modifier to specify content transition that is triggered when element exits the layout. |
LayoutModifier |
@RequiresSchemaVersion(major = 1, minor = 200)Adds a modifier to specify content transition that is triggered when element exits the layout. |
LayoutModifier |
@RequiresSchemaVersion(major = 1, minor = 500)The recommended opacity modifier for Lottie animation or any other element that should appear as the layout is swiped to. |
LayoutModifier |
@RequiresSchemaVersion(major = 1, minor = 300)Sets the minimum width and height of the clickable area. |
LayoutModifier |
@RequiresSchemaVersion(major = 1, minor = 400)Adds a modifier to specify the opacity of the element with a value from 0 to 1, where 0 means the element is completely transparent and 1 means the element is completely opaque. |
LayoutModifier |
LayoutModifier.padding(all: @Dimension(unit = 0) Float)Applies |
LayoutModifier |
LayoutModifier.padding(padding: ModifiersBuilders.Padding)Applies additional space along each edge of the content. |
LayoutModifier |
LayoutModifier.padding(Applies |
LayoutModifier |
LayoutModifier.padding(Applies additional space along each edge of the content in |
LayoutModifier |
@RequiresSchemaVersion(major = 1, minor = 600)Mark the element as heading for a section of content for accessibility purpose. |
LayoutModifier |
LayoutModifier.semanticsRole(semanticsRole: Int)Adds the semantic role of user interface element. |
ModifiersBuilders.Modifiers |
Creates a |
LayoutModifier |
@RequiresSchemaVersion(major = 1, minor = 300)Adds a modifier to specify the visibility of the element. |
Top-level functions
clickable
fun clickable(
action: ActionBuilders.Action = loadAction(),
id: String? = null,
@RequiresSchemaVersion(major = 1, minor = 300) minClickableWidth: @Dimension(unit = 0) Float = Float.NaN,
@RequiresSchemaVersion(major = 1, minor = 300) minClickableHeight: @Dimension(unit = 0) Float = Float.NaN
): ModifiersBuilders.Clickable
Creates a Clickable that allows the modified element to have actions associated with it, which will be executed when the element is tapped.
| Parameters | |
|---|---|
action: ActionBuilders.Action = loadAction() |
is triggered whenever the element is tapped. By default adds an empty |
id: String? = null |
is the associated identifier for this clickable. This will be passed to the action handler. |
@RequiresSchemaVersion(major = 1, minor = 300) minClickableWidth: @Dimension(unit = 0) Float = Float.NaN |
of the clickable area. The default value is 48dp, following the Material design accessibility guideline. Note that this value does not affect the layout, so the minimum clickable width is not guaranteed unless there is enough space around the element within its parent bounds. |
@RequiresSchemaVersion(major = 1, minor = 300) minClickableHeight: @Dimension(unit = 0) Float = Float.NaN |
of the clickable area. The default value is 48dp, following the Material design accessibility guideline. Note that this value does not affect the layout, so the minimum clickable height is not guaranteed unless there is enough space around the element within its parent bounds. |
loadAction
fun loadAction(
@RequiresSchemaVersion(major = 1, minor = 200) requestedStateMap: DynamicDataMap? = null
): ActionBuilders.LoadAction
Creates an action used to load (or reload) the layout contents.
| Parameters | |
|---|---|
@RequiresSchemaVersion(major = 1, minor = 200) requestedStateMap: DynamicDataMap? = null |
is the state associated with this action. This state will be passed to the action handler. |
padding
fun padding(all: @Dimension(unit = 0) Float): ModifiersBuilders.Padding
Creates a Padding that applies all dp of additional space along each edge of the content, left, top, right and bottom.
padding
fun padding(
horizontal: @Dimension(unit = 0) Float,
vertical: @Dimension(unit = 0) Float
): ModifiersBuilders.Padding
Creates a Padding that applies horizontal dp of additional space along the left and right edges of the content and vertical dp of additional space along the top and bottom edges of the content.
padding
fun padding(
start: @Dimension(unit = 0) Float = Float.NaN,
top: @Dimension(unit = 0) Float = Float.NaN,
end: @Dimension(unit = 0) Float = Float.NaN,
bottom: @Dimension(unit = 0) Float = Float.NaN,
rtlAware: Boolean = true
): ModifiersBuilders.Padding
Creates a Padding that applies additional space along each edge of the content in DP: start, top, end and bottom
| Parameters | |
|---|---|
start: @Dimension(unit = 0) Float = Float.NaN |
The padding on the start of the content, depending on the layout direction, in |
top: @Dimension(unit = 0) Float = Float.NaN |
The padding at the top, in |
end: @Dimension(unit = 0) Float = Float.NaN |
The padding on the end of the content, depending on the layout direction, in |
bottom: @Dimension(unit = 0) Float = Float.NaN |
The padding at the bottom, in |
rtlAware: Boolean = true |
specifies whether the |
Extension functions
background
@RequiresSchemaVersion(major = 1, minor = 500)
fun LayoutModifier.background(brush: ColorBuilders.Brush): LayoutModifier
Sets the background brush to brush.
background
fun LayoutModifier.background(color: LayoutColor): LayoutModifier
Sets the background color to color.
border
fun LayoutModifier.border(width: @Dimension(unit = 0) Float, color: LayoutColor): LayoutModifier
Adds a modifier to apply a border around an element.
| Parameters | |
|---|---|
width: @Dimension(unit = 0) Float |
The width of the border, in |
color: LayoutColor |
The color of the border. |
clearSemantics
fun LayoutModifier.clearSemantics(): LayoutModifier
Clears the semantics, including contentDescription and semanticsRole, from the modifier.
clickable
fun LayoutModifier.clickable(clickable: ModifiersBuilders.Clickable): LayoutModifier
Adds the clickable property of the modified element. It allows the modified element to have actions associated with it, which will be executed when the element is tapped.
clickable
fun LayoutModifier.clickable(
action: ActionBuilders.Action = loadAction(),
id: String? = null
): LayoutModifier
Adds the clickable property of the modified element. It allows the modified element to have actions associated with it, which will be executed when the element is tapped.
| Parameters | |
|---|---|
action: ActionBuilders.Action = loadAction() |
is triggered whenever the element is tapped. By default adds an empty |
id: String? = null |
is the associated identifier for this clickable. This will be passed to the action handler. |
clickable
fun ProtoLayoutScope.clickable(
pendingIntent: PendingIntent,
id: String,
fallbackAction: ActionBuilders.Action? = null,
minClickableWidth: @Dimension(unit = 0) Float = Float.NaN,
minClickableHeight: @Dimension(unit = 0) Float = Float.NaN
): ModifiersBuilders.Clickable
Creates a Clickable that allows the modified element to have a PendingIntent associated with it, which will be sent when the element is tapped.
This clickable requires to be created in a ProtoLayoutScope receiver scope which handles internal details of ProtoLayout layout and tiles. In Tiles cases, this scope object can be obtained via androidx.wear.tiles.RequestBuilders#TileRequest.getScope.
| Parameters | |
|---|---|
pendingIntent: PendingIntent |
is sent when the element is tapped. |
id: String |
is the associated identifier for this clickable. This will be used to the identify the pendingIntent to send in the renderer. Within the same tile, this id must be unique among all pendingIntent clickables. |
fallbackAction: ActionBuilders.Action? = null |
The Action to use as a fallback when PendingIntent isn't supported by the ProtoLayout Renderer. |
minClickableWidth: @Dimension(unit = 0) Float = Float.NaN |
of the clickable area. The default value is 48dp, following the Material design accessibility guideline. Note that this value does not affect the layout, so the minimum clickable width is not guaranteed unless there is enough space around the element within its parent bounds. |
minClickableHeight: @Dimension(unit = 0) Float = Float.NaN |
of the clickable area. The default value is 48dp, following the Material design accessibility guideline. Note that this value does not affect the layout, so the minimum clickable height is not guaranteed unless there is enough space around the element within its parent bounds. |
clip
fun LayoutModifier.clip(corner: ModifiersBuilders.Corner): LayoutModifier
Clips the element to a rounded rectangle with corners specified in corner.
clip
fun LayoutModifier.clip(cornerRadius: @Dimension(unit = 0) Float): LayoutModifier
Clips the element to a rounded rectangle with four corners with cornerRadius radius.
clip
@RequiresSchemaVersion(major = 1, minor = 400)
fun LayoutModifier.clip(
x: @Dimension(unit = 0) Float,
y: @Dimension(unit = 0) Float
): LayoutModifier
Clips the element to a rounded shape with x as the radius on the horizontal axis and y as the radius on the vertical axis for the four corners.
clipBottomLeft
@RequiresSchemaVersion(major = 1, minor = 400)
fun LayoutModifier.clipBottomLeft(
x: @Dimension(unit = 0) Float,
y: @Dimension(unit = 0) Float = x
): LayoutModifier
Clips the bottom left corner of the element with x as the radius on the horizontal axis and y as the radius on the vertical axis.
clipBottomRight
@RequiresSchemaVersion(major = 1, minor = 400)
fun LayoutModifier.clipBottomRight(
x: @Dimension(unit = 0) Float,
y: @Dimension(unit = 0) Float = x
): LayoutModifier
Clips the bottom right corner of the element with x as the radius on the horizontal axis and y as the radius on the vertical axis.
clipTopLeft
@RequiresSchemaVersion(major = 1, minor = 400)
fun LayoutModifier.clipTopLeft(
x: @Dimension(unit = 0) Float,
y: @Dimension(unit = 0) Float = x
): LayoutModifier
Clips the top left corner of the element with x as the radius on the horizontal axis and y as the radius on the vertical axis.
clipTopRight
@RequiresSchemaVersion(major = 1, minor = 400)
fun LayoutModifier.clipTopRight(
x: @Dimension(unit = 0) Float,
y: @Dimension(unit = 0) Float = x
): LayoutModifier
Clips the top right corner of the element with x as the radius on the horizontal axis and y as the radius on the vertical axis.
contentDescription
fun LayoutModifier.contentDescription(
staticValue: String,
@RequiresSchemaVersion(major = 1, minor = 200) dynamicValue: DynamicBuilders.DynamicString? = null
): LayoutModifier
Adds content description to be read by accessibility services.
| Parameters | |
|---|---|
staticValue: String |
The static content description. This value will be used if |
@RequiresSchemaVersion(major = 1, minor = 200) dynamicValue: DynamicBuilders.DynamicString? = null |
The dynamic content description. This is useful when content of the element itself is dynamic. |
enterTransition
@RequiresSchemaVersion(major = 1, minor = 200)
@ProtoLayoutExperimental
fun LayoutModifier.enterTransition(
transition: ModifiersBuilders.EnterTransition
): LayoutModifier
Adds a modifier to specify content transition that is triggered when element enters the layout.
Any update to the element or its children will trigger this animation for this element and everything underneath it.
enterTransition
@RequiresSchemaVersion(major = 1, minor = 200)
@ProtoLayoutExperimental
fun LayoutModifier.enterTransition(
fadeIn: ModifiersBuilders.FadeInTransition? = null,
slideIn: ModifiersBuilders.SlideInTransition? = null
): LayoutModifier
Adds a modifier to specify content transition that is triggered when element enters the layout.
Any update to the element or its children will trigger this animation for this element and everything underneath it.
| Parameters | |
|---|---|
fadeIn: ModifiersBuilders.FadeInTransition? = null |
The fading in animation for content transition of an element and its children happening when entering the layout. |
slideIn: ModifiersBuilders.SlideInTransition? = null |
The sliding in animation for content transition of an element and its children happening when entering the layout. |
exitTransition
@RequiresSchemaVersion(major = 1, minor = 200)
@ProtoLayoutExperimental
fun LayoutModifier.exitTransition(
transition: ModifiersBuilders.ExitTransition
): LayoutModifier
Adds a modifier to specify content transition that is triggered when element exits the layout.
Any update to the element or its children will trigger this animation for this element and everything underneath it.
exitTransition
@RequiresSchemaVersion(major = 1, minor = 200)
@ProtoLayoutExperimental
fun LayoutModifier.exitTransition(
fadeOut: ModifiersBuilders.FadeOutTransition? = null,
slideOut: ModifiersBuilders.SlideOutTransition? = null
): LayoutModifier
Adds a modifier to specify content transition that is triggered when element exits the layout.
Any update to the element or its children will trigger this animation for this element and everything underneath it.
| Parameters | |
|---|---|
fadeOut: ModifiersBuilders.FadeOutTransition? = null |
The fading out animation for content transition of an element and its children happening when exiting the layout. |
slideOut: ModifiersBuilders.SlideOutTransition? = null |
The sliding out animation for content transition of an element and its children happening when exiting the layout. |
fadeInOnVisibleModifier
@RequiresSchemaVersion(major = 1, minor = 500)
fun LayoutModifier.fadeInOnVisibleModifier(
animationSpec: AnimationParameterBuilders.AnimationSpec = AnimationParameterBuilders.AnimationSpec.Builder() .setAnimationParameters( AnimationParameterBuilders.AnimationParameters.Builder() .setDurationMillis(150) .build() ) .build()
): LayoutModifier
The recommended opacity modifier for Lottie animation or any other element that should appear as the layout is swiped to.
It is recommended to be used when Lottie animation is infinite, so that Lottie animation first becomes visible with fading in, followed by animation show, to avoid showing static state while user swipes to the layout.
import androidx.wear.protolayout.ResourceBuilders.LottieProperty.colorForSlot import androidx.wear.protolayout.TriggerBuilders.createOnVisibleTrigger import androidx.wear.protolayout.layout.imageResource import androidx.wear.protolayout.layout.lottieResource import androidx.wear.protolayout.material3.backgroundImage import androidx.wear.protolayout.material3.materialScope import androidx.wear.protolayout.material3.materialScopeWithResources import androidx.wear.protolayout.material3.primaryLayout import androidx.wear.protolayout.material3.text import androidx.wear.protolayout.modifiers.LayoutModifier import androidx.wear.protolayout.modifiers.background import androidx.wear.protolayout.modifiers.fadeInOnVisibleModifier materialScopeWithResources( context = context, protoLayoutScope = scope, deviceConfiguration = deviceConfiguration, ) { primaryLayout( mainSlot = { backgroundImage( resource = imageResource( lottie = lottieResource( rawResourceId = 1234, // Lottie Raw Resource ID, startTrigger = createOnVisibleTrigger(), properties = listOf(colorForSlot("slotID", colorScheme.tertiary.prop)), ) ), modifier = LayoutModifier.fadeInOnVisibleModifier(), ) } ) }
minimumTouchTargetSize
@RequiresSchemaVersion(major = 1, minor = 300)
fun LayoutModifier.minimumTouchTargetSize(
minWidth: @Dimension(unit = 0) Float,
minHeight: @Dimension(unit = 0) Float
): LayoutModifier
Sets the minimum width and height of the clickable area. The default value is 48dp, following the Material design accessibility guideline. Note that this value does not affect the layout, so the minimum clickable width/height is not guaranteed unless there is enough space around the element within its parent bounds.
opacity
@RequiresSchemaVersion(major = 1, minor = 400)
fun LayoutModifier.opacity(
staticValue: @FloatRange(from = 0.0, to = 1.0) Float,
dynamicValue: DynamicBuilders.DynamicFloat? = null
): LayoutModifier
Adds a modifier to specify the opacity of the element with a value from 0 to 1, where 0 means the element is completely transparent and 1 means the element is completely opaque.
| Parameters | |
|---|---|
staticValue: @FloatRange(from = 0.0, to = 1.0) Float |
The static value for opacity. This value will be used if |
dynamicValue: DynamicBuilders.DynamicFloat? = null |
The dynamic value for opacity. This can be used to change the opacity of the element dynamically (without changing the layout definition). To create a smooth transition for the dynamic change, you can use one of |
padding
fun LayoutModifier.padding(all: @Dimension(unit = 0) Float): LayoutModifier
Applies all dp of additional space along each edge of the content, left, top, right and bottom.
padding
fun LayoutModifier.padding(padding: ModifiersBuilders.Padding): LayoutModifier
Applies additional space along each edge of the content.
padding
fun LayoutModifier.padding(
horizontal: @Dimension(unit = 0) Float,
vertical: @Dimension(unit = 0) Float
): LayoutModifier
Applies horizontal dp of additional space along the left and right edges of the content and vertical dp of additional space along the top and bottom edges of the content.
padding
fun LayoutModifier.padding(
start: @Dimension(unit = 0) Float = Float.NaN,
top: @Dimension(unit = 0) Float = Float.NaN,
end: @Dimension(unit = 0) Float = Float.NaN,
bottom: @Dimension(unit = 0) Float = Float.NaN,
rtlAware: Boolean = true
): LayoutModifier
Applies additional space along each edge of the content in DP: start, top, end and bottom
| Parameters | |
|---|---|
start: @Dimension(unit = 0) Float = Float.NaN |
The padding on the start of the content, depending on the layout direction, in |
top: @Dimension(unit = 0) Float = Float.NaN |
The padding at the top, in |
end: @Dimension(unit = 0) Float = Float.NaN |
The padding on the end of the content, depending on the layout direction, in |
bottom: @Dimension(unit = 0) Float = Float.NaN |
The padding at the bottom, in |
rtlAware: Boolean = true |
specifies whether the |
semanticsHeading
@RequiresSchemaVersion(major = 1, minor = 600)
fun LayoutModifier.semanticsHeading(heading: Boolean): LayoutModifier
Mark the element as heading for a section of content for accessibility purpose.
semanticsRole
fun LayoutModifier.semanticsRole(semanticsRole: Int): LayoutModifier
Adds the semantic role of user interface element. Accessibility services might use this to describe the element or do customizations.
toProtoLayoutModifiers
fun LayoutModifier.toProtoLayoutModifiers(): ModifiersBuilders.Modifiers
Creates a ModifiersBuilders.Modifiers from a LayoutModifier.
visibility
@RequiresSchemaVersion(major = 1, minor = 300)
@ProtoLayoutExperimental
fun LayoutModifier.visibility(
staticVisibility: Boolean,
dynamicVisibility: DynamicBuilders.DynamicBool? = null
): LayoutModifier
Adds a modifier to specify the visibility of the element. A hidden element still consume space in the layout, but will not render any contents, nor will any of its children render any contents.
Note that hidden elements won't receive input events.
| Parameters | |
|---|---|
staticVisibility: Boolean |
The static value for visibility. This value will be used if |
dynamicVisibility: DynamicBuilders.DynamicBool? = null |
The dynamic value for visibility. This can be used to change the visibility of the element dynamically (without changing the layout definition). |