GlanceModifier
interface GlanceModifier
CombinedGlanceModifier |
A node in a |
GlanceModifier.Companion |
The companion object |
GlanceModifier.Element |
A single element contained within a |
An ordered, immutable, collection of modifier element for the Glance library.
This plays the same role as androidx.compose.ui.Modifier, but for the Glance composables.
Summary
Nested types |
|---|
object GlanceModifier.Companion : GlanceModifierThe companion object |
interface GlanceModifier.Element : GlanceModifierA single element contained within a |
Public companion functions |
|
|---|---|
open Boolean |
all(predicate: (GlanceModifier.Element) -> Boolean)Returns |
open Boolean |
any(predicate: (GlanceModifier.Element) -> Boolean)Returns |
open R |
<R : Any?> foldIn(initial: R, operation: (GlanceModifier.Element, R) -> R)Accumulates a value starting with |
open R |
<R : Any?> foldOut(initial: R, operation: (GlanceModifier.Element, R) -> R)Accumulates a value starting with |
open infix GlanceModifier |
then(other: GlanceModifier)Concatenates this modifier with another. |
open String |
toString() |
Public functions |
|
|---|---|
Boolean |
all(predicate: (GlanceModifier.Element) -> Boolean)Returns |
Boolean |
any(predicate: (GlanceModifier.Element) -> Boolean)Returns |
R |
<R : Any?> foldIn(initial: R, operation: (GlanceModifier.Element, R) -> R)Accumulates a value starting with |
R |
<R : Any?> foldOut(initial: R, operation: (GlanceModifier.Element, R) -> R)Accumulates a value starting with |
open infix GlanceModifier |
then(other: GlanceModifier)Concatenates this modifier with another. |
Extension functions |
|
|---|---|
GlanceModifier |
@ComposableRun |
GlanceModifier |
GlanceModifier.clickable(onClick: Action)Apply an |
GlanceModifier |
GlanceModifier.clickable(Apply an |
GlanceModifier |
@ComposableRun |
GlanceModifier |
@ComposableRun |
GlanceModifier |
Define the current view as the background of the App Widget. |
GlanceModifier |
GlanceModifier.background(color: Color)Apply a background color to the element this modifier is attached to. |
GlanceModifier |
GlanceModifier.background(color: @ColorRes Int)Apply a background color to the element this modifier is attached to. |
GlanceModifier |
GlanceModifier.background(colorProvider: ColorProvider)Apply a background color to the element this modifier is attached to. |
GlanceModifier |
GlanceModifier.background(day: Color, night: Color)Apply a background color to the element this modifier is attached to. |
GlanceModifier |
GlanceModifier.background(Apply a background image to the element this modifier is attached to. |
GlanceModifier |
GlanceModifier.background(Apply a background image to the element this modifier is attached to. |
GlanceModifier |
GlanceModifier.This function is deprecated. glance-wear-tiles is deprecated and will be removed |
GlanceModifier |
GlanceModifier.This function is deprecated. glance-wear-tiles is deprecated and will be removed |
GlanceModifier |
GlanceModifier.cornerRadius(radius: Dp)Adds rounded corners for the current view. |
GlanceModifier |
GlanceModifier.cornerRadius(radius: @DimenRes Int)Adds rounded corners for the current view, using resources. |
GlanceModifier |
GlanceModifier.absolutePadding(left: Dp, top: Dp, right: Dp, bottom: Dp)Apply additional space along each edge of the content in |
GlanceModifier |
GlanceModifier.absolutePadding(Apply additional space along each edge of the content in |
GlanceModifier |
GlanceModifier.padding(all: Dp)Apply |
GlanceModifier |
GlanceModifier.padding(all: @DimenRes Int)Apply |
GlanceModifier |
GlanceModifier.padding(horizontal: Dp, vertical: Dp)Apply |
GlanceModifier |
Apply |
GlanceModifier |
Apply additional space along each edge of the content in |
GlanceModifier |
GlanceModifier.padding(Apply additional space along each edge of the content in |
GlanceModifier |
Use this modifier to group a list of RadioButtons together for accessibility purposes. |
GlanceModifier |
GlanceModifier.semantics(properties: SemanticsPropertyReceiver.() -> Unit)Add semantics for use in testing, accessibility and similar use cases. |
GlanceModifier |
Specifies that the height of the element should expand to the size of its parent. |
GlanceModifier |
Set both the width and height to the maximum available space. |
GlanceModifier |
Specifies that the width of the element should expand to the size of its parent. |
GlanceModifier |
GlanceModifier.height(height: Dp)Sets the absolute height of an element, in |
GlanceModifier |
GlanceModifier.height(height: @DimenRes Int)Set the height of the view from a resource. |
GlanceModifier |
GlanceModifier.size(size: Dp)Sets both the width and height of an element, in |
GlanceModifier |
GlanceModifier.size(size: @DimenRes Int)Sets both width and height of an element from a resource. |
GlanceModifier |
GlanceModifier.size(width: Dp, height: Dp)Sets both the width and height of an element, in |
GlanceModifier |
Sets both the width and height of an element from resources. |
GlanceModifier |
GlanceModifier.width(width: Dp)Sets the absolute width of an element, in |
GlanceModifier |
GlanceModifier.width(width: @DimenRes Int)Set the width of a view from the value of a resource. |
GlanceModifier |
Specifies that the height of the element should wrap its contents. |
GlanceModifier |
Wrap both the width and height's content. |
GlanceModifier |
Specifies that the width of the element should wrap its contents. |
GlanceModifier |
GlanceModifier.visibility(visibility: Visibility)Change the visibility of the current node. |
Public companion functions
all
open fun all(predicate: (GlanceModifier.Element) -> Boolean): Boolean
Returns true if predicate returns true for all Elements in this GlanceModifier or if this GlanceModifier contains no Elements.
any
open fun any(predicate: (GlanceModifier.Element) -> Boolean): Boolean
Returns true if predicate returns true for any Element in this GlanceModifier.
foldIn
open fun <R : Any?> foldIn(initial: R, operation: (GlanceModifier.Element, R) -> R): R
Accumulates a value starting with initial and applying operation to the current value and each element from outside in.
Elements wrap one another in a chain from left to right; an Element that appears to the left of another in a + expression or in operation's parameter order affects all of the elements that appear after it. foldIn may be used to accumulate a value starting from the parent or head of the modifier chain to the final wrapped child.
foldOut
open fun <R : Any?> foldOut(initial: R, operation: (GlanceModifier.Element, R) -> R): R
Accumulates a value starting with initial and applying operation to the current value and each element from inside out.
Elements wrap one another in a chain from left to right; an Element that appears to the left of another in a + expression or in operation's parameter order affects all of the elements that appear after it. foldOut may be used to accumulate a value starting from the child or tail of the modifier chain up to the parent or head of the chain.
then
open infix fun then(other: GlanceModifier): GlanceModifier
Concatenates this modifier with another.
Returns a GlanceModifier representing this modifier followed by other in sequence.
Public functions
all
fun all(predicate: (GlanceModifier.Element) -> Boolean): Boolean
Returns true if predicate returns true for all Elements in this GlanceModifier or if this GlanceModifier contains no Elements.
any
fun any(predicate: (GlanceModifier.Element) -> Boolean): Boolean
Returns true if predicate returns true for any Element in this GlanceModifier.
foldIn
fun <R : Any?> foldIn(initial: R, operation: (GlanceModifier.Element, R) -> R): R
Accumulates a value starting with initial and applying operation to the current value and each element from outside in.
Elements wrap one another in a chain from left to right; an Element that appears to the left of another in a + expression or in operation's parameter order affects all of the elements that appear after it. foldIn may be used to accumulate a value starting from the parent or head of the modifier chain to the final wrapped child.
foldOut
fun <R : Any?> foldOut(initial: R, operation: (GlanceModifier.Element, R) -> R): R
Accumulates a value starting with initial and applying operation to the current value and each element from inside out.
Elements wrap one another in a chain from left to right; an Element that appears to the left of another in a + expression or in operation's parameter order affects all of the elements that appear after it. foldOut may be used to accumulate a value starting from the child or tail of the modifier chain up to the parent or head of the chain.
then
open infix fun then(other: GlanceModifier): GlanceModifier
Concatenates this modifier with another.
Returns a GlanceModifier representing this modifier followed by other in sequence.
Extension functions
clickable
@Composable
fun GlanceModifier.clickable(block: () -> Unit): GlanceModifier
Run block in response to a user click.
The lambda provided to this function will use the androidx.compose.runtime.currentCompositeKeyHash to set a key for this lambda that will be used to trigger it when the corresponding UI element is clicked. Since that key is based on the location within the composition, it will be identical for lambdas generated in a loop (if not using androidx.compose.runtime.key).
To avoid this, prefer setting explicit keys for your lambdas, by using the overload of clickable that accepts a key parameter.
| Parameters | |
|---|---|
block: () -> Unit |
The action to run. |
clickable
fun GlanceModifier.clickable(onClick: Action): GlanceModifier
Apply an Action, to be executed in response to a user click.
| Parameters | |
|---|---|
onClick: Action |
The action to run. |
clickable
fun GlanceModifier.clickable(
onClick: Action,
rippleOverride: @DrawableRes Int = NoRippleOverride
): GlanceModifier
Apply an Action, to be executed in response to a user click.
| Parameters | |
|---|---|
onClick: Action |
The action to run. |
rippleOverride: @DrawableRes Int = NoRippleOverride |
A drawable resource to use as the onClick ripple. Use |
clickable
@Composable
fun GlanceModifier.clickable(
rippleOverride: @DrawableRes Int = NoRippleOverride,
block: () -> Unit
): GlanceModifier
Run block in response to a user click.
The lambda provided to this function will use the androidx.compose.runtime.currentCompositeKeyHash to set a key for this lambda that will be used to trigger it when the corresponding UI element is clicked. Since that key is based on the location within the composition, it will be identical for lambdas generated in a loop (if not using androidx.compose.runtime.key).
To avoid this, prefer setting explicit keys for your lambdas, by using the overload of clickable that accepts a key parameter.
| Parameters | |
|---|---|
rippleOverride: @DrawableRes Int = NoRippleOverride |
A drawable resource to use as the onClick ripple. Use |
block: () -> Unit |
The action to run. |
clickable
@Composable
fun GlanceModifier.clickable(
key: String? = null,
rippleOverride: @DrawableRes Int = NoRippleOverride,
block: () -> Unit
): GlanceModifier
Run block in response to a user click.
| Parameters | |
|---|---|
key: String? = null |
A stable and unique key that identifies this action. This key is saved in the PendingIntent for the UI element, and used to trigger this action when the element is clicked. If not provided we use |
rippleOverride: @DrawableRes Int = NoRippleOverride |
A drawable resource to use as the onClick ripple. Use |
block: () -> Unit |
The action to run. |
appWidgetBackground
fun GlanceModifier.appWidgetBackground(): GlanceModifier
Define the current view as the background of the App Widget.
By definition, the background of the App Widget is the view with the id @android:id/background.
There can be only one view with this modifier in a given App Widget.
This modifier does not automatically set corner radius. To have these set for you, use the androidx.glance.appwidget.components.Scaffold component.
For more information about widget backgrounds, See the documentation on Enable smoother transitions and Implement rounded corners for details on why it is important to label a view as being the background, and why you will want to set the cornerRadius of the same view.
background
fun GlanceModifier.background(color: Color): GlanceModifier
Apply a background color to the element this modifier is attached to. This will cause the element to paint the specified Color as its background, which will fill the bounds of the element.
| Parameters | |
|---|---|
color: Color |
The color to set as the background. |
background
fun GlanceModifier.background(color: @ColorRes Int): GlanceModifier
Apply a background color to the element this modifier is attached to. This will cause the element to paint the specified color resource as its background, which will fill the bounds of the element.
background
fun GlanceModifier.background(colorProvider: ColorProvider): GlanceModifier
Apply a background color to the element this modifier is attached to. This will cause the element to paint the specified ColorProvider as its background, which will fill the bounds of the element.
| Parameters | |
|---|---|
colorProvider: ColorProvider |
The color to set as the background |
background
fun GlanceModifier.background(day: Color, night: Color): GlanceModifier
Apply a background color to the element this modifier is attached to. This will cause the element to paint the specified Color as its background, choosing day or night depending on the device configuration, which will fill the bounds of the element.
background
fun GlanceModifier.background(
imageProvider: ImageProvider,
contentScale: ContentScale = ContentScale.FillBounds,
colorFilter: ColorFilter? = null
): GlanceModifier
Apply a background image to the element this modifier is attached to.
| Parameters | |
|---|---|
imageProvider: ImageProvider |
The content to set as the background |
contentScale: ContentScale = ContentScale.FillBounds |
scaling to apply to the imageProvider. |
colorFilter: ColorFilter? = null |
Optional color filter to apply to |
background
fun GlanceModifier.background(
imageProvider: ImageProvider,
alpha: @FloatRange(from = 0.0, to = 1.0) Float,
contentScale: ContentScale = ContentScale.FillBounds,
colorFilter: ColorFilter? = null
): GlanceModifier
Apply a background image to the element this modifier is attached to.
| Parameters | |
|---|---|
imageProvider: ImageProvider |
The content to set as the background |
alpha: @FloatRange(from = 0.0, to = 1.0) Float |
Opacity (0f to 1f) to apply to the background image. |
contentScale: ContentScale = ContentScale.FillBounds |
scaling to apply to the imageProvider. |
colorFilter: ColorFilter? = null |
Optional color filter to apply to |
border
fun GlanceModifier.border(width: Dp, color: ColorProvider): GlanceModifier
Apply a border around an element, border width is provided in Dp
| Parameters | |
|---|---|
width: Dp |
The width of the border, in DP |
color: ColorProvider |
The color of the border |
border
fun GlanceModifier.border(width: @DimenRes Int, color: ColorProvider): GlanceModifier
Apply a border around an element, border width is provided with dimension resource
| Parameters | |
|---|---|
width: @DimenRes Int |
The width of the border, value provided by a dimension resource |
color: ColorProvider |
The color of the border |
cornerRadius
fun GlanceModifier.cornerRadius(radius: Dp): GlanceModifier
Adds rounded corners for the current view.
Note: Only works on Android S+.
cornerRadius
fun GlanceModifier.cornerRadius(radius: @DimenRes Int): GlanceModifier
Adds rounded corners for the current view, using resources.
Note: Only works on Android S+.
absolutePadding
fun GlanceModifier.absolutePadding(
left: Dp = 0.dp,
top: Dp = 0.dp,
right: Dp = 0.dp,
bottom: Dp = 0.dp
): GlanceModifier
Apply additional space along each edge of the content in Dp: left, top, right and bottom, ignoring the current locale's layout direction.
absolutePadding
fun GlanceModifier.absolutePadding(
left: @DimenRes Int = 0,
top: @DimenRes Int = 0,
right: @DimenRes Int = 0,
bottom: @DimenRes Int = 0
): GlanceModifier
Apply additional space along each edge of the content in Dp: left, top, right and bottom, ignoring the current locale's layout direction.
padding
fun GlanceModifier.padding(all: Dp): GlanceModifier
Apply all dp of additional space along each edge of the content, left, top, right and bottom.
padding
fun GlanceModifier.padding(all: @DimenRes Int): GlanceModifier
Apply all dp of additional space along each edge of the content, left, top, right and bottom.
padding
fun GlanceModifier.padding(horizontal: Dp = 0.dp, vertical: Dp = 0.dp): GlanceModifier
Apply horizontal dp space along the left and right edges of the content, and vertical dp space along the top and bottom edges.
If any value is not defined, it will be 0.dp or whatever value was defined by an earlier modifier.
padding
fun GlanceModifier.padding(horizontal: @DimenRes Int = 0, vertical: @DimenRes Int = 0): GlanceModifier
Apply horizontal dp space along the left and right edges of the content, and vertical dp space along the top and bottom edges.
If any value is not defined, it will be 0.dp or whatever value was defined by an earlier modifier.
padding
fun GlanceModifier.padding(
start: Dp = 0.dp,
top: Dp = 0.dp,
end: Dp = 0.dp,
bottom: Dp = 0.dp
): GlanceModifier
Apply additional space along each edge of the content in Dp: start, top, end and bottom. The start and end edges will be determined by layout direction of the current locale. Padding is applied before content measurement and takes precedence; content may only be as large as the remaining space.
If any value is not defined, it will be 0.dp or whatever value was defined by an earlier modifier.
padding
fun GlanceModifier.padding(
start: @DimenRes Int = 0,
top: @DimenRes Int = 0,
end: @DimenRes Int = 0,
bottom: @DimenRes Int = 0
): GlanceModifier
Apply additional space along each edge of the content in Dp: start, top, end and bottom. The start and end edges will be determined by layout direction of the current locale. Padding is applied before content measurement and takes precedence; content may only be as large as the remaining space.
If any value is not defined, it will be 0.dp or whatever value was defined by an earlier modifier.
selectableGroup
fun GlanceModifier.selectableGroup(): GlanceModifier
Use this modifier to group a list of RadioButtons together for accessibility purposes.
This modifier can only be used on a Row or Column. This modifier additonally enables the radio group effect, which automatically unselects the currently selected RadioButton when another is selected. When this modifier is used, an error will be thrown if more than one RadioButton has their "checked" value set to true.
semantics
fun GlanceModifier.semantics(properties: SemanticsPropertyReceiver.() -> Unit): GlanceModifier
Add semantics for use in testing, accessibility and similar use cases.
fillMaxHeight
fun GlanceModifier.fillMaxHeight(): GlanceModifier
Specifies that the height of the element should expand to the size of its parent. Note that if multiple elements within a linear container (e.g. Row or Column) have their height as expandHeight, then they will all share the remaining space.
fillMaxSize
fun GlanceModifier.fillMaxSize(): GlanceModifier
Set both the width and height to the maximum available space.
fillMaxWidth
fun GlanceModifier.fillMaxWidth(): GlanceModifier
Specifies that the width of the element should expand to the size of its parent. Note that if multiple elements within a linear container (e.g. Row or Column) have their width as fillMaxWidth, then they will all share the remaining space.
height
fun GlanceModifier.height(height: Dp): GlanceModifier
Sets the absolute height of an element, in Dp.
height
fun GlanceModifier.height(height: @DimenRes Int): GlanceModifier
Set the height of the view from a resource.
size
fun GlanceModifier.size(size: Dp): GlanceModifier
Sets both the width and height of an element, in Dp.
size
fun GlanceModifier.size(size: @DimenRes Int): GlanceModifier
Sets both width and height of an element from a resource.
size
fun GlanceModifier.size(width: Dp, height: Dp): GlanceModifier
Sets both the width and height of an element, in Dp.
size
fun GlanceModifier.size(width: @DimenRes Int, height: @DimenRes Int): GlanceModifier
Sets both the width and height of an element from resources.
width
fun GlanceModifier.width(width: Dp): GlanceModifier
Sets the absolute width of an element, in Dp.
width
fun GlanceModifier.width(width: @DimenRes Int): GlanceModifier
Set the width of a view from the value of a resource.
wrapContentHeight
fun GlanceModifier.wrapContentHeight(): GlanceModifier
Specifies that the height of the element should wrap its contents.
wrapContentSize
fun GlanceModifier.wrapContentSize(): GlanceModifier
Wrap both the width and height's content.
wrapContentWidth
fun GlanceModifier.wrapContentWidth(): GlanceModifier
Specifies that the width of the element should wrap its contents.
visibility
fun GlanceModifier.visibility(visibility: Visibility): GlanceModifier
Change the visibility of the current node.
| Parameters | |
|---|---|
visibility: Visibility |
New visibility of the node. |