LayoutModifier
public interface LayoutModifier
LayoutModifier.Companion |
The companion object |
LayoutModifier.Element |
A single element contained within a |
An ordered, immutable collection of modifier elements that decorate or add behavior to ProtoLayout layout elements. For example, backgrounds, padding and click actions. When a single modifier is applied multiple times, the last one wins.
import androidx.wear.protolayout.material3.button import androidx.wear.protolayout.material3.icon import androidx.wear.protolayout.material3.iconEdgeButton import androidx.wear.protolayout.material3.materialScope import androidx.wear.protolayout.material3.text import androidx.wear.protolayout.modifiers.LayoutModifier import androidx.wear.protolayout.modifiers.clickable import androidx.wear.protolayout.modifiers.contentDescription materialScope(context, deviceConfiguration) { iconEdgeButton( onClick = clickable, modifier = LayoutModifier.contentDescription("Description of a button"), ) { icon(protoLayoutResourceId = "id") } }
Summary
Nested types |
|---|
public static class LayoutModifier.Companion implements LayoutModifierThe companion object |
public interface LayoutModifier.Element extends LayoutModifierA single element contained within a |
Public methods |
|
|---|---|
abstract @NonNull R |
<R extends Object> foldRight(Accumulates a value starting with |
default @NonNull LayoutModifier |
then(@NonNull LayoutModifier other)Concatenates this modifier with another. |
Extension functions |
|
|---|---|
default final @NonNull LayoutModifier |
@RequiresSchemaVersion(major = 1, minor = 500)Sets the background brush to |
default final @NonNull LayoutModifier |
BackgroundKt.background(Sets the background color to |
default final @NonNull LayoutModifier |
BackgroundKt.clip(Clips the element to a rounded rectangle with corners specified in |
default final @NonNull LayoutModifier |
BackgroundKt.clip(Clips the element to a rounded rectangle with four corners with |
default final @NonNull LayoutModifier |
@RequiresSchemaVersion(major = 1, minor = 400)Clips the element to a rounded shape with |
default final @NonNull LayoutModifier |
@RequiresSchemaVersion(major = 1, minor = 400)Clips the bottom left corner of the element with |
default final @NonNull LayoutModifier |
@RequiresSchemaVersion(major = 1, minor = 400)Clips the bottom right corner of the element with |
default final @NonNull LayoutModifier |
@RequiresSchemaVersion(major = 1, minor = 400)Clips the top left corner of the element with |
default final @NonNull LayoutModifier |
@RequiresSchemaVersion(major = 1, minor = 400)Clips the top right corner of the element with |
default final @NonNull LayoutModifier |
BorderKt.border(Adds a modifier to apply a border around an element. |
default final @NonNull LayoutModifier |
ClickableKt.clickable(Adds the clickable property of the modified element. |
default final @NonNull LayoutModifier |
ClickableKt.clickable(Adds the clickable property of the modified element. |
default final @NonNull LayoutModifier |
@RequiresSchemaVersion(major = 1, minor = 300)Sets the minimum width and height of the clickable area. |
default final @NonNull ModifiersBuilders.Modifiers |
Creates a |
default final @NonNull 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. |
default final @NonNull 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. |
default final @NonNull LayoutModifier |
PaddingKt.padding(Applies |
default final @NonNull LayoutModifier |
PaddingKt.padding(Applies additional space along each edge of the content. |
default final @NonNull LayoutModifier |
PaddingKt.padding(Applies |
default final @NonNull LayoutModifier |
PaddingKt.padding(Applies additional space along each edge of the content in |
default final @NonNull LayoutModifier |
SemanticsKt.clearSemantics(@NonNull LayoutModifier receiver)Clears the semantics, including |
default final @NonNull LayoutModifier |
SemanticsKt.contentDescription(Adds content description to be read by accessibility services. |
default final @NonNull LayoutModifier |
@RequiresSchemaVersion(major = 1, minor = 600)Mark the element as heading for a section of content for accessibility purpose. |
default final @NonNull LayoutModifier |
SemanticsKt.semanticsRole(Adds the semantic role of user interface element. |
default final @NonNull LayoutModifier |
@RequiresSchemaVersion(major = 1, minor = 200)Adds a modifier to specify content transition that is triggered when element enters the layout. |
default final @NonNull LayoutModifier |
@RequiresSchemaVersion(major = 1, minor = 200)Adds a modifier to specify content transition that is triggered when element enters the layout. |
default final @NonNull LayoutModifier |
@RequiresSchemaVersion(major = 1, minor = 200)Adds a modifier to specify content transition that is triggered when element exits the layout. |
default final @NonNull LayoutModifier |
@RequiresSchemaVersion(major = 1, minor = 200)Adds a modifier to specify content transition that is triggered when element exits the layout. |
default final @NonNull LayoutModifier |
@RequiresSchemaVersion(major = 1, minor = 300)Adds a modifier to specify the visibility of the element. |
Public methods
foldRight
abstract @NonNull R <R extends Object> foldRight(
@NonNull R initial,
@NonNull Function2<@NonNull R, @NonNull LayoutModifier.Element, @NonNull R> operation
)
Accumulates a value starting with initial and applying operation to the current value and each element from left to right.
foldRight may be used to accumulate a value starting from the head of the modifier chain to the final modifier element.
then
default @NonNull LayoutModifier then(@NonNull LayoutModifier other)
Concatenates this modifier with another.
Returns a LayoutModifier representing this modifier followed by other in sequence.
Extension functions
BackgroundKt.background
@RequiresSchemaVersion(major = 1, minor = 500)
default final @NonNull LayoutModifier BackgroundKt.background(
@NonNull LayoutModifier receiver,
@NonNull ColorBuilders.Brush brush
)
Sets the background brush to brush.
BackgroundKt.background
default final @NonNull LayoutModifier BackgroundKt.background(
@NonNull LayoutModifier receiver,
@NonNull LayoutColor color
)
Sets the background color to color.
BackgroundKt.clip
default final @NonNull LayoutModifier BackgroundKt.clip(
@NonNull LayoutModifier receiver,
@NonNull ModifiersBuilders.Corner corner
)
Clips the element to a rounded rectangle with corners specified in corner.
BackgroundKt.clip
default final @NonNull LayoutModifier BackgroundKt.clip(
@NonNull LayoutModifier receiver,
@Dimension(unit = 0) float cornerRadius
)
Clips the element to a rounded rectangle with four corners with cornerRadius radius.
BackgroundKt.clip
@RequiresSchemaVersion(major = 1, minor = 400)
default final @NonNull LayoutModifier BackgroundKt.clip(
@NonNull LayoutModifier receiver,
@Dimension(unit = 0) float x,
@Dimension(unit = 0) float y
)
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.
BackgroundKt.clipBottomLeft
@RequiresSchemaVersion(major = 1, minor = 400)
default final @NonNull LayoutModifier BackgroundKt.clipBottomLeft(
@NonNull LayoutModifier receiver,
@Dimension(unit = 0) float x,
@Dimension(unit = 0) float y
)
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.
BackgroundKt.clipBottomRight
@RequiresSchemaVersion(major = 1, minor = 400)
default final @NonNull LayoutModifier BackgroundKt.clipBottomRight(
@NonNull LayoutModifier receiver,
@Dimension(unit = 0) float x,
@Dimension(unit = 0) float y
)
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.
BackgroundKt.clipTopLeft
@RequiresSchemaVersion(major = 1, minor = 400)
default final @NonNull LayoutModifier BackgroundKt.clipTopLeft(
@NonNull LayoutModifier receiver,
@Dimension(unit = 0) float x,
@Dimension(unit = 0) float y
)
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.
BackgroundKt.clipTopRight
@RequiresSchemaVersion(major = 1, minor = 400)
default final @NonNull LayoutModifier BackgroundKt.clipTopRight(
@NonNull LayoutModifier receiver,
@Dimension(unit = 0) float x,
@Dimension(unit = 0) float y
)
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.
BorderKt.border
default final @NonNull LayoutModifier BorderKt.border(
@NonNull LayoutModifier receiver,
@Dimension(unit = 0) float width,
@NonNull LayoutColor color
)
Adds a modifier to apply a border around an element.
| Parameters | |
|---|---|
@Dimension(unit = 0) float width |
The width of the border, in |
@NonNull LayoutColor color |
The color of the border. |
ClickableKt.clickable
default final @NonNull LayoutModifier ClickableKt.clickable(
@NonNull LayoutModifier receiver,
@NonNull ModifiersBuilders.Clickable clickable
)
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.
ClickableKt.clickable
default final @NonNull LayoutModifier ClickableKt.clickable(
@NonNull LayoutModifier receiver,
@NonNull ActionBuilders.Action action,
String id
)
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 | |
|---|---|
@NonNull ActionBuilders.Action action |
is triggered whenever the element is tapped. By default adds an empty |
String id |
is the associated identifier for this clickable. This will be passed to the action handler. |
ClickableKt.minimumTouchTargetSize
@RequiresSchemaVersion(major = 1, minor = 300)
default final @NonNull LayoutModifier ClickableKt.minimumTouchTargetSize(
@NonNull LayoutModifier receiver,
@Dimension(unit = 0) float minWidth,
@Dimension(unit = 0) float minHeight
)
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.
ModifierAppliersKt.toProtoLayoutModifiers
default final @NonNull ModifiersBuilders.Modifiers ModifierAppliersKt.toProtoLayoutModifiers(
@NonNull LayoutModifier receiver
)
Creates a ModifiersBuilders.Modifiers from a LayoutModifier.
OpacityKt.fadeInOnVisibleModifier
@RequiresSchemaVersion(major = 1, minor = 500)
default final @NonNull LayoutModifier OpacityKt.fadeInOnVisibleModifier(
@NonNull LayoutModifier receiver,
@NonNull AnimationParameterBuilders.AnimationSpec animationSpec
)
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(), ) } ) }
OpacityKt.opacity
@RequiresSchemaVersion(major = 1, minor = 400)
default final @NonNull LayoutModifier OpacityKt.opacity(
@NonNull LayoutModifier receiver,
@FloatRange(from = 0.0, to = 1.0) float staticValue,
DynamicBuilders.DynamicFloat dynamicValue
)
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 | |
|---|---|
@FloatRange(from = 0.0, to = 1.0) float staticValue |
The static value for opacity. This value will be used if |
DynamicBuilders.DynamicFloat dynamicValue |
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 |
PaddingKt.padding
default final @NonNull LayoutModifier PaddingKt.padding(
@NonNull LayoutModifier receiver,
@Dimension(unit = 0) float all
)
Applies all dp of additional space along each edge of the content, left, top, right and bottom.
PaddingKt.padding
default final @NonNull LayoutModifier PaddingKt.padding(
@NonNull LayoutModifier receiver,
@NonNull ModifiersBuilders.Padding padding
)
Applies additional space along each edge of the content.
PaddingKt.padding
default final @NonNull LayoutModifier PaddingKt.padding(
@NonNull LayoutModifier receiver,
@Dimension(unit = 0) float horizontal,
@Dimension(unit = 0) float vertical
)
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.
PaddingKt.padding
default final @NonNull LayoutModifier PaddingKt.padding(
@NonNull LayoutModifier receiver,
@Dimension(unit = 0) float start,
@Dimension(unit = 0) float top,
@Dimension(unit = 0) float end,
@Dimension(unit = 0) float bottom,
boolean rtlAware
)
Applies additional space along each edge of the content in DP: start, top, end and bottom
| Parameters | |
|---|---|
@Dimension(unit = 0) float start |
The padding on the start of the content, depending on the layout direction, in |
@Dimension(unit = 0) float top |
The padding at the top, in |
@Dimension(unit = 0) float end |
The padding on the end of the content, depending on the layout direction, in |
@Dimension(unit = 0) float bottom |
The padding at the bottom, in |
boolean rtlAware |
specifies whether the |
SemanticsKt.clearSemantics
default final @NonNull LayoutModifier SemanticsKt.clearSemantics(@NonNull LayoutModifier receiver)
Clears the semantics, including contentDescription and semanticsRole, from the modifier.
SemanticsKt.contentDescription
default final @NonNull LayoutModifier SemanticsKt.contentDescription(
@NonNull LayoutModifier receiver,
@NonNull String staticValue,
@RequiresSchemaVersion(major = 1, minor = 200) DynamicBuilders.DynamicString dynamicValue
)
Adds content description to be read by accessibility services.
| Parameters | |
|---|---|
@NonNull String staticValue |
The static content description. This value will be used if |
@RequiresSchemaVersion(major = 1, minor = 200) DynamicBuilders.DynamicString dynamicValue |
The dynamic content description. This is useful when content of the element itself is dynamic. |
SemanticsKt.semanticsHeading
@RequiresSchemaVersion(major = 1, minor = 600)
default final @NonNull LayoutModifier SemanticsKt.semanticsHeading(
@NonNull LayoutModifier receiver,
boolean heading
)
Mark the element as heading for a section of content for accessibility purpose.
SemanticsKt.semanticsRole
default final @NonNull LayoutModifier SemanticsKt.semanticsRole(
@NonNull LayoutModifier receiver,
int semanticsRole
)
Adds the semantic role of user interface element. Accessibility services might use this to describe the element or do customizations.
TransitionKt.enterTransition
@RequiresSchemaVersion(major = 1, minor = 200)
@ProtoLayoutExperimental
default final @NonNull LayoutModifier TransitionKt.enterTransition(
@NonNull LayoutModifier receiver,
@NonNull ModifiersBuilders.EnterTransition transition
)
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.
TransitionKt.enterTransition
@RequiresSchemaVersion(major = 1, minor = 200)
@ProtoLayoutExperimental
default final @NonNull LayoutModifier TransitionKt.enterTransition(
@NonNull LayoutModifier receiver,
ModifiersBuilders.FadeInTransition fadeIn,
ModifiersBuilders.SlideInTransition slideIn
)
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 | |
|---|---|
ModifiersBuilders.FadeInTransition fadeIn |
The fading in animation for content transition of an element and its children happening when entering the layout. |
ModifiersBuilders.SlideInTransition slideIn |
The sliding in animation for content transition of an element and its children happening when entering the layout. |
TransitionKt.exitTransition
@RequiresSchemaVersion(major = 1, minor = 200)
@ProtoLayoutExperimental
default final @NonNull LayoutModifier TransitionKt.exitTransition(
@NonNull LayoutModifier receiver,
@NonNull ModifiersBuilders.ExitTransition transition
)
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.
TransitionKt.exitTransition
@RequiresSchemaVersion(major = 1, minor = 200)
@ProtoLayoutExperimental
default final @NonNull LayoutModifier TransitionKt.exitTransition(
@NonNull LayoutModifier receiver,
ModifiersBuilders.FadeOutTransition fadeOut,
ModifiersBuilders.SlideOutTransition slideOut
)
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 | |
|---|---|
ModifiersBuilders.FadeOutTransition fadeOut |
The fading out animation for content transition of an element and its children happening when exiting the layout. |
ModifiersBuilders.SlideOutTransition slideOut |
The sliding out animation for content transition of an element and its children happening when exiting the layout. |
VisibilityKt.visibility
@RequiresSchemaVersion(major = 1, minor = 300)
@ProtoLayoutExperimental
default final @NonNull LayoutModifier VisibilityKt.visibility(
@NonNull LayoutModifier receiver,
boolean staticVisibility,
DynamicBuilders.DynamicBool dynamicVisibility
)
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 | |
|---|---|
boolean staticVisibility |
The static value for visibility. This value will be used if |
DynamicBuilders.DynamicBool dynamicVisibility |
The dynamic value for visibility. This can be used to change the visibility of the element dynamically (without changing the layout definition). |