Skip to content

Touch and input snippet migration - #1138

Merged
kkuan2011 merged 4 commits into
android:mainfrom
StellarElements:touch-and-input-snippet-migration
Oct 12, 2026
Merged

kkuan2011 merged 4 commits into
android:mainfrom
StellarElements:touch-and-input-snippet-migration

Conversation

@barbaralaw

@barbaralaw barbaralaw commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Migrates hardcoded Kotlin samples from three Compose touch-input guides into :compose:snippets as region-tagged source, so the guides can import them instead of hardcoding them.

Two of those pages already had the samples in this repo (commands.kt, KeyboardShortcutsHelper.kt). This PR adds the page that did not (copy-and-paste) and updates one region tag in KeyboardShortcutsHelper.kt to enclose class MainActivity so the rendered output matches the live documentation.

On the new copy-and-paste page: 8 snippets. 5 publish exactly what the page shows. 3 differ, every one listed below with a reason. Line wrapping is not counted as a difference: spotlessApply runs before submission and rewraps long calls without changing what a reader reads.

Region tags for the new file begin android_compose_touchinput_copyandpaste_; the tables drop that prefix.

How to read the "why" column

Why What a reader of the page would see
hardcoded snippet defect fixed The published Kotlin does not compile, and this is not a sample meant to demonstrate an error. The region publishes the corrected line.
region tag scope restored The existing region tag omitted the enclosing class declaration shown on the live page. Expanding the region tag and moving @RequiresApi above it restores parity with the published guide.

Per page

1. Copy and paste

https://developer.android.com/develop/ui/compose/touch-input/copy-and-paste

Not previously in the repo. 8 snippets, 5 match, 3 differ.

Snippet Page section Difference Why
set_text Copy with ClipboardManager setText("Hello, clipboard") → setText(AnnotatedString("Hello, clipboard")) hardcoded snippet defect fixed
paste_text Paste with ClipboardManager append(text.toString()) → append(annotatedString.text); var textFieldState → val textFieldState hardcoded snippet defect fixed
paste_rich_content Paste a rich content extra ) dropped on hasMediaType(MediaType.Image); by remember { mutableListOf<Uri>() } → remember { mutableStateListOf<Uri>() } hardcoded snippet defect fixed

Matching as published: selection_container, clip_entry, copy_rich_content, has_media_type, sensitive_content.

2. Handle keyboard actions

https://developer.android.com/develop/ui/compose/touch-input/keyboard-input/commands

Already region-tagged in compose/snippets/.../touchinput/keyboardinput/commands.kt. This PR does not change that file.

3. Keyboard Shortcuts Helper

https://developer.android.com/develop/ui/compose/touch-input/keyboard-input/keyboard-shortcuts-helper

Previously region-tagged in compose/snippets/.../touchinput/keyboardinput/KeyboardShortcutsHelper.kt. This PR expands android_compose_keyboard_shortcuts_helper to enclose class MainActivity : ComponentActivity() and moves @RequiresApi(Build.VERSION_CODES.N) above the [START] tag so the rendered snippet matches the live DAC page.

Snippet Page section Difference Why
android_compose_keyboard_shortcuts_helper Provide shortcuts to Keyboard Shortcuts Helper Encloses class MainActivity : ComponentActivity() (and its comment) within the region tag; moves @RequiresApi(Build.VERSION_CODES.N) outside the tag region tag scope restored

Matching as published: android_compose_keyboard_shortcuts_helper_with_groups; android_compose_keyboard_shortcuts_helper_request (pre-existing activity?.requestShowKeyboardShortcuts()).

Not extracted

Kotlin only. No Java twins on the copy-and-paste page.

Live snippet fixes this surfaced

  1. Copy with ClipboardManager: clipboardManager.setText("Hello, clipboard") — ClipboardManager.setText takes AnnotatedString, not String.
  2. Paste with ClipboardManager: append(text.toString()) — text is not in scope in the edit lambda; the pasted value is annotatedString.
  3. Paste a rich content: transferableContent.hasMediaType(MediaType.Image)) — extra ). val imageList by remember { mutableListOf<Uri>() } is not snapshot state, so later imageList.add is not a correct Compose pattern.

Verification

  • ./gradlew :compose:snippets:compileDebugKotlin — passes
  • ./gradlew :compose:snippets:lintDebug — passes
  • ./gradlew spotlessApply — clean

@google-cla

google-cla Bot commented Sep 24, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@barbaralaw
barbaralaw marked this pull request as ready for review September 29, 2026 14:56
@barbaralaw
barbaralaw requested a review from a team as a code owner September 29, 2026 14:56
@snippet-bot

snippet-bot Bot commented Sep 29, 2026 •

Copy link
Copy Markdown

Here is the summary of changes.

You are about to add 9 region tags.
You are about to delete 1 region tag.

This comment is generated by snippet-bot.
If you find problems with this result, please file an issue at:
https://github.com/googleapis/repo-automation-bots/issues.
To update this comment, add snippet-bot:force-run label or use the checkbox below:

  • Refresh this comment

@barbaralaw
barbaralaw marked this pull request as draft September 29, 2026 14:59
@barbaralaw
barbaralaw force-pushed the touch-and-input-snippet-migration branch from 3399bc0 to 342a8ec Compare September 29, 2026 15:09
@barbaralaw
barbaralaw marked this pull request as ready for review September 29, 2026 15:09

@kkuan2011 kkuan2011 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catches! Thanks for the fixes and clean migration! Can you rebase again? (There's no option for me to click to rebase.)

@kkuan2011
kkuan2011 requested a review from chikoski September 30, 2026 00:51
@barbaralaw
barbaralaw force-pushed the touch-and-input-snippet-migration branch from 342a8ec to f2e2552 Compare September 30, 2026 16:38
@kkuan2011
kkuan2011 merged commit a6c85d7 into android:main Oct 12, 2026
10 checks passed
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.

4 participants