Skip to content

feat(wear): add One-Handed Gestures demo snippet - #1001

Draft
ithinkihaveacat wants to merge 12 commits into
android:mainfrom
ithinkihaveacat:wear-m3-one-handed-gestures
Draft

feat(wear): add One-Handed Gestures demo snippet#1001
ithinkihaveacat wants to merge 12 commits into
android:mainfrom
ithinkihaveacat:wear-m3-one-handed-gestures

Conversation

@ithinkihaveacat

@ithinkihaveacat ithinkihaveacat commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

PR Description

Overview

This PR adds a standalone, self-contained demonstration snippet for Wear OS One-Handed Gestures (Wear OS 7+, API 35+) using Jetpack Compose on Wear OS. It demonstrates both scrollable container gestures and interactive button click gestures (Double Pinch and Wrist Turn).

Note that this PR currently depends on SNAPSHOT versions of androidx.wear.compose:compose-material3. (See below for how this is handled.)

Key Changes

  • New Snippet (OneHandedGestures.kt):
    • Adds OneHandedGestureScreen() under com.example.wear.snippets.m3.gestures.
    • Demonstrates rememberOneHandedGestureConfiguration, Modifier.oneHandedGesture, OneHandedGestureScrollIndicator, and OneHandedGestureClickIndicator.
    • Includes region tags ([START android_wear_one_handed_gesture_screen]) for embedding in official developer documentation on developer.android.com (DAC).
  • Sample Wiring (MainActivity.kt):
    • Wires WearApp() to invoke OneHandedGestureScreen() for local testing.

How to Test

# Build the Wear OS debug APK locally
./gradlew :wear:assembleDebug -PwearComposeOverride=1.7.0-SNAPSHOT --stacktrace

Why is -PwearComposeOverride=1.7.0-SNAPSHOT needed?

To test unreleased One-Handed Gesture APIs without disrupting shared catalog versions across other samples in libs.versions.toml, this PR adopts the exact scoped snapshot-gating pattern established by the xr module in this repository.

By defining an isUsingSnapshot check and a .toSnapshotDependency(...) helper within wear/build.gradle.kts, the SNAPSHOT override is strictly scoped to the :wear module and is only activated when -PwearComposeOverride is explicitly provided. When building standard samples without this flag, :wear continues using the stable library version from libs.versions.toml.

This implementation directly mirrors the canonical approach used in xr/build.gradle.kts:

Add self-contained Wear OS One-Handed Gestures demo snippet to
com.example.wear.snippets.m3.gestures.

Gate SNAPSHOT dependencies (compose-material3 and foundation) on
isUsingSnapshot in wear/build.gradle.kts to avoid modifying shared
catalog versions in libs.versions.toml.

Update CI workflows to pass -PsnapshotVersion=1.7.0-SNAPSHOT during
PR validation builds.
Move the KDoc note about -PsnapshotVersion=1.7.0-SNAPSHOT below the
package declaration so that ktlint does not report multiple header
blocks above package.
Pin third-party GitHub Actions to immutable commit SHAs and define
explicit job-level permissions blocks in build.yml and
apply_spotless.yml to remediate mandatory Zizmor security analysis
findings.
Namespace Wear snapshot gating property to wearSnapshotVersion so
that passing -PwearSnapshotVersion=1.7.0-SNAPSHOT in CI workflows
does not trigger snapshot builds in the xr module.
Rename wearSnapshotVersion to wearComposeOverride to match the
wearCompose prefix convention used in libs.versions.toml.
Add concise 5-6 line snippet examples for scrollable and button
one-handed gestures so they can be included cleanly in developer
documentation without embedding an entire screen.
Include compose.foundation in the isUsingSnapshot override block
so that -PwearComposeOverride=1.7.0-SNAPSHOT also updates Wear
Compose Foundation to 1.7.0-SNAPSHOT during CI builds.
Remove priority setting from ButtonGestureSnippet so the initial
interactive button example in documentation is minimal and simple.
Update ButtonGestureSnippet to show a clean Button composable with
Modifier.oneHandedGesture without unnecessary conditional modifiers or
indicator state boilerplate.
Declare remember { MutableInteractionSource() } inside
ButtonGestureSnippet so the documentation example is self-contained and
runnable, and add an inline comment explaining why interactionSource
is shared.
Make ScrollGestureSnippet self-contained and runnable without priority,
and add highlight region tags around .oneHandedGesture in both snippets.
Remove nested highlight region tags from ButtonGestureSnippet and
ScrollGestureSnippet.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant