OneHandedGestureIndicator

Functions summary

Unit
@Composable
OneHandedGestureIndicator(
    interactionSource: InteractionSource,
    modifier: Modifier,
    gestureIndicatorSize: GestureIndicatorSize,
    gestureIndicatorTint: Color,
    content: @Composable BoxScope.() -> Unit
)

A wrapper that replaces the content to indicate to the user that a gesture action is available.

Functions

OneHandedGestureIndicator

@Composable
fun OneHandedGestureIndicator(
    interactionSource: InteractionSource,
    modifier: Modifier = Modifier,
    gestureIndicatorSize: GestureIndicatorSize = GestureIndicatorSize.Medium,
    gestureIndicatorTint: Color = MaterialTheme.colorScheme.onPrimary,
    content: @Composable BoxScope.() -> Unit
): Unit

A wrapper that replaces the content to indicate to the user that a gesture action is available.

This component listens to the provided interactionSource to handle the visual transition between the standard content and a gesture indicator. When a relevant gesture interaction is received, the content is swapped out for the visual indicator. Once the indicator animation sequence completes, the component automatically restores the original content.

Sample demonstrating a gesture indicator applied to a androidx.wear.compose.material3.Button:

import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.wear.compose.material3.Button
import androidx.wear.compose.material3.Text
import androidx.wear.compose.material3.onehandedgesture.GestureAction
import androidx.wear.compose.material3.onehandedgesture.OneHandedGestureIndicator
import androidx.wear.compose.material3.onehandedgesture.oneHandedGesture

var label by remember { mutableStateOf("Gesturable Button") }
val onClick = remember { { label = "Clicked/Gestured" } }
val interactionSource = remember { MutableInteractionSource() }
Box(modifier = Modifier.fillMaxSize(), contentAlignment = Alignment.Center) {
    Button(
        onClick = onClick,
        interactionSource = interactionSource,
        modifier =
            Modifier.oneHandedGesture(
                action = GestureAction.Primary,
                interactionSource = interactionSource,
                onGesture = onClick,
            ),
    ) {
        OneHandedGestureIndicator(interactionSource = interactionSource) { Text(label) }
    }
}
Parameters
interactionSource: InteractionSource

The InteractionSource stream to observe for incoming gesture indications. This is used to determine when and which gesture indicator should be displayed.

modifier: Modifier = Modifier

The Modifier to be applied to the OneHandedGestureIndicator layout.

gestureIndicatorSize: GestureIndicatorSize = GestureIndicatorSize.Medium

The size constraints for the gesture indicator icon, defaulting to GestureIndicatorSize.Medium.

gestureIndicatorTint: Color = MaterialTheme.colorScheme.onPrimary

The color which will be used for a tint of the gesture animation

content: @Composable BoxScope.() -> Unit

The original component content (e.g., Text or Icon) to be displayed when no indicator is active.