oneHandedGesture
@Composable
public fun Modifier.oneHandedGesture(
action: GestureAction,
priority: GesturePriority = GesturePriority.Unspecified,
enabledInAmbient: Boolean = false,
interactionSource: MutableInteractionSource? = null,
onGesture: suspend () -> Unit,
): Modifier
Registers a gesture handler.
Note: Gesture recognition can be explicitly disabled across a component hierarchy by providing false` to LocalOneHandedGestureEnabled.
Visibility Management: This gesture handler is active as long as the Modifier is part of the composition. On its own, it does not track whether the composable is visible or clipped (e.g., in a Lazy layout).
To prevent accidental triggers from off-screen items, developers should apply this modifier conditionally. For many cases, androidx.compose.ui.layout.onVisibilityChanged Modifier can be used to determine the visibility of a composable.
Example usage in a list:
var isVisible by remember { mutableStateOf(false) }
val gestureModifier = remember(isVisible) { if (isVisible) Modifier.oneHandedGesture() else Modifier
}
Box( modifier = Modifier .onVisibilityChanged { isVisible = it } .then(gestureModifier)
) { ...
}
Haptics: When a gesture is successfully triggered, the system automatically performs haptic feedback to acknowledge the interaction; developers do not need to trigger haptics manually within onGesture.
Example of adding one-handed gesture handler to a androidx.wear.compose.material3.Button:
Example of adding one-handed gesture handler to a androidx.wear.compose.foundation.lazy.TransformingLazyColumn:
Example of adding one-handed gesture handler to a androidx.wear.compose.foundation.pager.HorizontalPager:
Example of adding one-handed gesture handler to a androidx.wear.compose.foundation.pager.VerticalPager:
Parameters
| action | The gesture action to handle. |
| priority | The priority value; higher values take precedence if multiple handlers are registered for the same action. It is not recommended to register multiple gestures for the same action and priority (but if that is the case, all of them will be actioned). |
| enabledInAmbient | Whether the gesture should remain active in ambient mode. |
| interactionSource | MutableInteractionSource that will be used to dispatch androidx.compose.foundation.interaction.Interactions for this gesture. This can be used to visualize the gesture state (e.g., showing a ripple, custom pressed state or gesture indicator) when the one-handed gesture is being interacted with. |
| onGesture | The callback invoked when the gesture is triggered. |