GlanceModifier

interface GlanceModifier

Known direct subclasses
CombinedGlanceModifier

A node in a GlanceModifier chain.

GlanceModifier.Companion

The companion object Modifier is the empty, default, or starter GlanceModifier that contains no elements.

GlanceModifier.Element

A single element contained within a GlanceModifier chain.


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

The companion object Modifier is the empty, default, or starter GlanceModifier that contains no elements.

A single element contained within a GlanceModifier chain.

Public companion functions

open Boolean

Returns true if predicate returns true for all Elements in this GlanceModifier or if this GlanceModifier contains no Elements.

open Boolean

Returns true if predicate returns true for any Element in this GlanceModifier.

open R
<R : Any?> foldIn(initial: R, operation: (GlanceModifier.Element, R) -> R)

Accumulates a value starting with initial and applying operation to the current value and each element from outside in.

open R
<R : Any?> foldOut(initial: R, operation: (GlanceModifier.Element, R) -> R)

Accumulates a value starting with initial and applying operation to the current value and each element from inside out.

open infix GlanceModifier

Concatenates this modifier with another.

open String

Public functions

Boolean

Returns true if predicate returns true for all Elements in this GlanceModifier or if this GlanceModifier contains no Elements.

Boolean

Returns true if predicate returns true for any Element in this GlanceModifier.

R
<R : Any?> foldIn(initial: R, operation: (GlanceModifier.Element, R) -> R)

Accumulates a value starting with initial and applying operation to the current value and each element from outside in.

R
<R : Any?> foldOut(initial: R, operation: (GlanceModifier.Element, R) -> R)

Accumulates a value starting with initial and applying operation to the current value and each element from inside out.

open infix GlanceModifier

Concatenates this modifier with another.

Extension functions

GlanceModifier

Run block in response to a user click.

GlanceModifier

Apply an Action, to be executed in response to a user click.

GlanceModifier
GlanceModifier.clickable(
    onClick: Action,
    rippleOverride: @DrawableRes Int
)

Apply an Action, to be executed in response to a user click.

GlanceModifier
@Composable
GlanceModifier.clickable(
    rippleOverride: @DrawableRes Int,
    block: () -> Unit
)

Run block in response to a user click.

GlanceModifier
@ExperimentalGlanceApi
@Composable
GlanceModifier.clickable(
    key: String?,
    rippleOverride: @DrawableRes Int,
    block: () -> Unit
)

Run block in response to a user click.

GlanceModifier

Define the current view as the background of the App Widget.

GlanceModifier

Apply a background color to the element this modifier is attached to.

GlanceModifier

Apply a background color to the element this modifier is attached to.

GlanceModifier

Apply a background color to the element this modifier is attached to.

GlanceModifier

Apply a background color to the element this modifier is attached to.

GlanceModifier
GlanceModifier.background(
    imageProvider: ImageProvider,
    contentScale: ContentScale,
    colorFilter: ColorFilter?
)

Apply a background image to the element this modifier is attached to.

GlanceModifier

Apply a border around an element, border width is provided in Dp

GlanceModifier

Apply a border around an element, border width is provided with dimension resource

GlanceModifier

Adds rounded corners for the current view.

GlanceModifier

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 Dp: left, top, right and bottom, ignoring the current locale's layout direction.

GlanceModifier
GlanceModifier.absolutePadding(
    left: @DimenRes Int,
    top: @DimenRes Int,
    right: @DimenRes Int,
    bottom: @DimenRes Int
)

Apply additional space along each edge of the content in Dp: left, top, right and bottom, ignoring the current locale's layout direction.

GlanceModifier

Apply all dp of additional space along each edge of the content, left, top, right and bottom.

GlanceModifier

Apply all dp of additional space along each edge of the content, left, top, right and bottom.

GlanceModifier
GlanceModifier.padding(horizontal: Dp, vertical: Dp)

Apply horizontal dp space along the left and right edges of the content, and vertical dp space along the top and bottom edges.

GlanceModifier
GlanceModifier.padding(horizontal: @DimenRes Int, vertical: @DimenRes Int)

Apply horizontal dp space along the left and right edges of the content, and vertical dp space along the top and bottom edges.

GlanceModifier
GlanceModifier.padding(start: Dp, top: Dp, end: Dp, bottom: Dp)

Apply additional space along each edge of the content in Dp: start, top, end and bottom.

GlanceModifier
GlanceModifier.padding(
    start: @DimenRes Int,
    top: @DimenRes Int,
    end: @DimenRes Int,
    bottom: @DimenRes Int
)

Apply additional space along each edge of the content in Dp: start, top, end and bottom.

GlanceModifier

Use this modifier to group a list of RadioButtons together for accessibility purposes.

GlanceModifier

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

Sets the absolute height of an element, in Dp.

GlanceModifier

Set the height of the view from a resource.

GlanceModifier

Sets both the width and height of an element, in Dp.

GlanceModifier

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

GlanceModifier
GlanceModifier.size(width: @DimenRes Int, height: @DimenRes Int)

Sets both the width and height of an element from resources.

GlanceModifier

Sets the absolute width of an element, in Dp.

GlanceModifier

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

Change the visibility of the current node.

Public companion functions

all

Added in 1.1.1
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

Added in 1.1.1
open fun any(predicate: (GlanceModifier.Element) -> Boolean): Boolean

Returns true if predicate returns true for any Element in this GlanceModifier.

foldIn

Added in 1.1.1
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

Added in 1.1.1
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.

toString

open fun toString(): String

Public functions

all

Added in 1.0.0
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

Added in 1.0.0
fun any(predicate: (GlanceModifier.Element) -> Boolean): Boolean

Returns true if predicate returns true for any Element in this GlanceModifier.

foldIn

Added in 1.0.0
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

Added in 1.0.0
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

Added in 1.0.0
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.

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 NoRippleOverride if no custom behavior is needed.

clickable

@Composable
fun GlanceModifier.clickable(
    rippleOverride: @DrawableRes Int = NoRippleOverride,
    block: () -> Unit
): GlanceModifier

Run block in response to a user click.

Parameters
rippleOverride: @DrawableRes Int = NoRippleOverride

A drawable resource to use as the onClick ripple. Use NoRippleOverride if no custom behavior is needed.

block: () -> Unit

The action to run.

clickable

@ExperimentalGlanceApi
@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 the action for this element. This ensures that the correct action is triggered, especially in cases of items that change order. If not provided we use the key that is automatically generated by the Compose runtime, which is unique for every exact code location in the composition tree.

rippleOverride: @DrawableRes Int = NoRippleOverride

A drawable resource to use as the onClick ripple. Use NoRippleOverride if no custom behavior is needed.

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.

Parameters
color: @ColorRes Int

The color resource to set as the background.

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

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 imageProvider, such as tint.

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

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

fun GlanceModifier.cornerRadius(radius: Dp): GlanceModifier

Adds rounded corners for the current view.

Note: Only works on Android S+.

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.

fun GlanceModifier.padding(all: Dp): GlanceModifier

Apply all dp of additional space along each edge of the content, left, top, right and bottom.

fun GlanceModifier.padding(all: @DimenRes Int): GlanceModifier

Apply all dp of additional space along each edge of the content, left, top, right and bottom.

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.

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.

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.

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.

fun GlanceModifier.height(height: Dp): GlanceModifier

Sets the absolute height of an element, in Dp.

fun GlanceModifier.height(height: @DimenRes Int): GlanceModifier

Set the height of the view from a resource.

fun GlanceModifier.size(size: Dp): GlanceModifier

Sets both the width and height of an element, in Dp.

fun GlanceModifier.size(size: @DimenRes Int): GlanceModifier

Sets both width and height of an element from a resource.

fun GlanceModifier.size(width: Dp, height: Dp): GlanceModifier

Sets both the width and height of an element, in Dp.

fun GlanceModifier.size(width: @DimenRes Int, height: @DimenRes Int): GlanceModifier

Sets both the width and height of an element from resources.

fun GlanceModifier.width(width: Dp): GlanceModifier

Sets the absolute width of an element, in Dp.

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.