Repository navigation
Touch and input snippet migration - #1138
Merged
kkuan2011 merged 4 commits intoOct 12, 2026
Merged
Conversation
|
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
marked this pull request as draft
September 29, 2026 14:59
barbaralaw
force-pushed
the
touch-and-input-snippet-migration
branch
from
September 29, 2026 15:09
3399bc0 to
342a8ec
Compare
barbaralaw
marked this pull request as ready for review
September 29, 2026 15:09
kkuan2011
approved these changes
Sep 30, 2026
kkuan2011
left a comment
Contributor
There was a problem hiding this comment.
Good catches! Thanks for the fixes and clean migration! Can you rebase again? (There's no option for me to click to rebase.)
chikoski
approved these changes
Sep 30, 2026
barbaralaw
force-pushed
the
touch-and-input-snippet-migration
branch
from
September 30, 2026 16:38
342a8ec to
f2e2552
Compare
riggaroo
approved these changes
Oct 12, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Migrates hardcoded Kotlin samples from three Compose touch-input guides into
:compose:snippetsas 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 inKeyboardShortcutsHelper.ktto encloseclass MainActivityso 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:
spotlessApplyruns 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
@RequiresApiabove 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.
set_textsetText("Hello, clipboard")→setText(AnnotatedString("Hello, clipboard"))paste_textappend(text.toString())→append(annotatedString.text);var textFieldState→val textFieldStatepaste_rich_content)dropped onhasMediaType(MediaType.Image);by remember { mutableListOf<Uri>() }→remember { mutableStateListOf<Uri>() }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 expandsandroid_compose_keyboard_shortcuts_helperto encloseclass MainActivity : ComponentActivity()and moves@RequiresApi(Build.VERSION_CODES.N)above the[START]tag so the rendered snippet matches the live DAC page.android_compose_keyboard_shortcuts_helperclass MainActivity : ComponentActivity()(and its comment) within the region tag; moves@RequiresApi(Build.VERSION_CODES.N)outside the tagMatching as published:
android_compose_keyboard_shortcuts_helper_with_groups;android_compose_keyboard_shortcuts_helper_request(pre-existingactivity?.requestShowKeyboardShortcuts()).Not extracted
Kotlin only. No Java twins on the copy-and-paste page.
Live snippet fixes this surfaced
clipboardManager.setText("Hello, clipboard")—ClipboardManager.setTexttakesAnnotatedString, notString.append(text.toString())—textis not in scope in theeditlambda; the pasted value isannotatedString.transferableContent.hasMediaType(MediaType.Image))— extra).val imageList by remember { mutableListOf<Uri>() }is not snapshot state, so laterimageList.addis not a correct Compose pattern.Verification
./gradlew :compose:snippets:compileDebugKotlin— passes./gradlew :compose:snippets:lintDebug— passes./gradlew spotlessApply— clean