oneHandedGesture
@Composable
public fun Modifier.oneHandedGesture(
action: GestureAction,
priority: GesturePriority = GesturePriority.Unspecified,
enabledInAmbient: Boolean = false,
interactionSource: MutableInteractionSource? = null,
onShowIndicator: () -> Unit = {},
onGesture: suspend () -> Unit,
): Modifier
Registers a gesture handler.
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 or custom pressed state) when the one-handed gesture is being interacted with. |
| onShowIndicator | Callback invoked when the system determines a gesture indicator should be displayed for this component. This occurs when the component holds the highest priority for the current gesture. Only GestureAction.Primary gesture indicator callbacks will be called. |
| onGesture | The callback invoked when the gesture is triggered. |
oneHandedGesture
public fun Modifier.oneHandedGesture(
action: GestureAction,
key: String,
priority: GesturePriority = GesturePriority.Unspecified,
enabledInAmbient: Boolean = false,
interactionSource: MutableInteractionSource? = null,
onShowIndicator: () -> Unit = {},
onGesture: suspend () -> Unit,
): Modifier
Registers a gesture handler.
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. |
| key | A unique identifier for this gesture instance. This ID allows the system to track user interactions - for example, to mute gesture indicators that have been frequently shown or successfully performed, in accordance with user preferences. If the same key is reused across multiple gestures, they will share a common interaction history (such as frequency-based gesture indicator display logic). Note that this only affects the presentation of the UI; the underlying logic and handling remain independent for each instance. |
| 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 or custom pressed state) when the one-handed gesture is being interacted with. |
| onShowIndicator | Callback invoked when the system determines a gesture indicator should be displayed for this component. This occurs when the component holds the highest priority for the current gesture. Only GestureAction.Primary gesture indicator callbacks will be called. |
| onGesture | The callback invoked when the gesture is triggered. |