CompositionLocal that controls whether one-handed gestures are enabled within the provided composition tree.
@Composable
fun OneHandedGestureDisableButtonSample() {
var counter by remember { mutableIntStateOf(0) }
var enabled by remember { mutableStateOf(true) }
val interactionSource = remember { MutableInteractionSource() }
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) {
Button(
onClick = {},
interactionSource = interactionSource,
modifier =
Modifier.oneHandedGesture(
action = GestureAction.Primary,
interactionSource = interactionSource,
onGesture = { counter++ },
),
) {
OneHandedGestureIndicator(interactionSource = interactionSource) {
Text("Gestured $counter times")
}
}
}
}
}
}