clickable

Composable Function

Android
@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

blockThe action to run.
Android
@Composable
fun GlanceModifier.clickable(
    @DrawableRes rippleOverride: 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

rippleOverrideA drawable resource to use as the onClick ripple. Use NoRippleOverride if no custom behavior is needed.
blockThe action to run.
Android
@Composable
fun GlanceModifier.clickable(
    key: String? = null,
    @DrawableRes rippleOverride: Int = NoRippleOverride,
    block: () -> Unit
): GlanceModifier

Run block in response to a user click.

Parameters

blockThe action to run.
rippleOverrideA drawable resource to use as the onClick ripple. Use NoRippleOverride if no custom behavior is needed.
keyA 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 androidx.compose.runtime.currentCompositeKeyHash as the key. 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, e.g. "incrementCount", "openNewYorkWeather", etc.