Property

LocalOneHandedGestureEnabled

CompositionLocal that controls whether one-handed gestures are enabled within the provided composition tree.

OneHandedGestureDisableButtonSample

@Sampled
@Composable
fun OneHandedGestureDisableButtonSample() {
    var counter by remember { mutableIntStateOf(0) }
    var enabled by remember { mutableStateOf(true) }
    val interactionSource = remember { MutableInteractionSource() }
    val coroutineScope = rememberCoroutineScope()

    Box(modifier = Modifier.fillMaxSize(), contentAlignment = Alignment.Center) {
        Column(horizontalAlignment = Alignment.CenterHorizontally) {
            SwitchButton(checked = enabled, onCheckedChange = { enabled = it }) {
                Text("Gestures enabled")
            }
            Spacer(modifier = Modifier.height(6.dp))
            CompositionLocalProvider(LocalOneHandedGestureEnabled provides enabled) {
                val gestureConfig =
                    rememberOneHandedGestureConfiguration(action = OneHandedGestureAction.Primary)
                val indicatorState = remember { OneHandedGestureClickIndicatorState() }
                Button(
                    onClick = {},
                    interactionSource = interactionSource,
                    modifier =
                        Modifier.oneHandedGesture(
                            gestureConfiguration = gestureConfig,
                            interactionSource = interactionSource,
                            onGestureLabel = "increase the counter",
                            onGestureAvailable = {
                                coroutineScope.launch { indicatorState.showIndicator() }
                            },
                            onGesture = { counter++ },
                        ),
                ) {
                    OneHandedGestureClickIndicator(gestureConfig, indicatorState) {
                        Text("Gestured $counter times")
                    }
                }
            }
        }
    }
}
Jetpack Compose beyond MaterialFree components, screens and templates for apps that don’t look like Google’s. Copy them into your app, or let your coding agent add them.Browse for free

Content updated: