Start native apps faster with the Composables CLI ->
Compose Component

OneHandedGestureClickIndicator

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

OneHandedGestureButtonSample

@Composable
fun OneHandedGestureButtonSample() {
    var label by remember { mutableStateOf("Gesturable Button") }
    val onClick = { label = "Clicked/Gestured" }
    val interactionSource = remember { MutableInteractionSource() }
    val gestureConfig = rememberOneHandedGestureConfiguration(action = GestureAction.Primary)
    val indicatorState = remember { OneHandedGestureClickIndicatorState() }
    val coroutineScope = rememberCoroutineScope()
    Box(modifier = Modifier.fillMaxSize(), contentAlignment = Alignment.Center) {
        Button(
            onClick = onClick,
            interactionSource = interactionSource,
            modifier =
                Modifier.fillMaxWidth()
                    .oneHandedGesture(
                        gestureConfiguration = gestureConfig,
                        interactionSource = interactionSource,
                        onGestureLabel = "activate the button",
                        onGestureAvailable = {
                            coroutineScope.launch { indicatorState.showIndicator() }
                        },
                        onGesture = onClick,
                    ),
        ) {
            OneHandedGestureClickIndicator(gestureConfig, indicatorState) {
                Text(label, modifier = Modifier.fillMaxWidth())
            }
        }
    }
}

Last updated: