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() }
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 = GestureAction.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")
}
}
}
}
}
}