androidx.wear.compose.material3.onehandedgesture

Interfaces

OneHandedGestureInteraction

An interaction related to one-handed gesture events.

Classes

GestureAction

Defines the distinct actions of one-handed gestures supported by the system.

GestureIndicatorSize

Represents the size of the gesture indicator icon.

GesturePriority

Defines the fixed precedence levels for one-handed gesture interception.

OneHandedGestureInteraction.Indicate

An interaction representing an indication event, used to display a visual indicator for the given gesture action.

Objects

Composables

OneHandedGestureHorizontalPageIndicator

A horizontal page indicator that can temporarily display a gesture indicator to demonstrate how to navigate between pages using one-handed gestures.

OneHandedGestureIndicator

A wrapper that replaces the content to indicate to the user that a gesture action is available.

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.

oneHandedGesture

Registers a gesture handler.

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 LocalOneHandedGestureEnabledProvidableCompositionLocal<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.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.GestureAction
import androidx.wear.compose.material3.onehandedgesture.LocalOneHandedGestureEnabled
import androidx.wear.compose.material3.onehandedgesture.OneHandedGestureIndicator
import androidx.wear.compose.material3.onehandedgesture.oneHandedGesture

var counter by remember { mutableIntStateOf(0) }
var enabled by remember { mutableStateOf(true) }
val interactionSource = remember { MutableInteractionSource() }
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) {
            Button(
                onClick = {},
                interactionSource = interactionSource,
                modifier =
                    Modifier.oneHandedGesture(
                        action = GestureAction.Primary,
                        interactionSource = interactionSource,
                        onGesture = { counter++ },
                    ),
            ) {
                OneHandedGestureIndicator(interactionSource = interactionSource) {
                    Text("Gestured $counter times")
                }
            }
        }
    }
}