androidx.wear.compose.material3.onehandedgesture
This package offers APIs providing one-handed gesture support, consisting of gesture handlers for primary action (e.g. double pinch) and dismiss action (e.g. wrist turn). A gesture configuration should be created for each component that supports a gesture, such as a button, card or scrollable container. Animated indicators are provided that show when the gestures are available on clickable UI elements (like buttons and cards), scrollable lists or pagers.
Classes
OneHandedGestureAction |
Defines the distinct actions of one-handed gestures supported by the system. |
OneHandedGestureClickIndicatorState |
A state object used to coordinate visual feedback between a |
OneHandedGestureConfiguration |
Represents the persistent specification for a one-handed gesture. |
OneHandedGestureIndicatorSize |
Represents the size of the gesture indicator icon. |
OneHandedGesturePageIndicatorState |
State object for |
OneHandedGesturePriority |
Defines the fixed precedence levels for one-handed gesture interception. |
OneHandedGestureScrollIndicatorState |
State object for |
Objects
Composables
OneHandedGestureClickIndicator |
A wrapper that replaces the |
OneHandedGestureHorizontalPageIndicator |
A horizontal page indicator that can temporarily display a gesture indicator to demonstrate how to navigate between pages using one-handed gestures. |
OneHandedGestureScrollIndicator |
A scroll indicator that transitions to indicate that a scroll gesture is available to the user. |
OneHandedGestureVerticalPageIndicator |
A vertical page indicator that can temporarily display a gesture indicator to demonstrate how to navigate between pages using one-handed gestures. |
rememberOneHandedGestureConfiguration |
A |
Modifiers
oneHandedGesture |
Registers a gesture handler. |
Top-level properties summary
ProvidableCompositionLocal<Boolean> |
CompositionLocal that controls whether one-handed gestures are enabled within the provided composition tree. |
Top-level properties
LocalOneHandedGestureEnabled
val LocalOneHandedGestureEnabled: ProvidableCompositionLocal<Boolean>
CompositionLocal that controls whether one-handed gestures are enabled within the provided composition tree.
When set to true (the default), any Modifier.oneHandedGesture applied within this composition scope will actively track and process one-handed gestures. When provided with false, those modifiers will gracefully ignore relevant touch events without being removed from the composition tree. Example usage:
CompositionLocalProvider(LocalOneHandedGestureEnabled provides false) {
// Any oneHandedGesture modifiers inside this component will be disabled
MyEncapsulatedScreenContent()
}
Sample demonstrating how to disable gesture:
import androidx.compose.foundation.interaction.MutableInteractionSource import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.height import androidx.compose.runtime.CompositionLocalProvider import androidx.compose.runtime.mutableIntStateOf import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember import androidx.compose.runtime.rememberCoroutineScope import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.unit.dp import androidx.wear.compose.material3.Button import androidx.wear.compose.material3.SwitchButton import androidx.wear.compose.material3.Text import androidx.wear.compose.material3.onehandedgesture.LocalOneHandedGestureEnabled import androidx.wear.compose.material3.onehandedgesture.OneHandedGestureAction import androidx.wear.compose.material3.onehandedgesture.OneHandedGestureClickIndicator import androidx.wear.compose.material3.onehandedgesture.OneHandedGestureClickIndicatorState import androidx.wear.compose.material3.onehandedgesture.oneHandedGesture import androidx.wear.compose.material3.onehandedgesture.rememberOneHandedGestureConfiguration 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") } } } } }