Compose Unstyled 2.0 is out! Check the official announcement blog ->
Composable Function

oneHandedGesture

Registers a gesture handler.

oneHandedGesture

Source set: Android
@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.

Last updated: