Skip to content

Migrate Compose touch and input snippets - #1118

Open
pengzhi-cb wants to merge 6 commits into
android:mainfrom
pengzhi-cb:pengzhi-cb/compose-migrate-swipeable
Open

pengzhi-cb wants to merge 6 commits into
android:mainfrom
pengzhi-cb:pengzhi-cb/compose-migrate-swipeable

Conversation

@pengzhi-cb

@pengzhi-cb pengzhi-cb commented Sep 18, 2026 •

Copy link
Copy Markdown
Contributor

Code snippets are for:

  1. (8 snippets) https://developer.android.com/develop/ui/compose/touch-input/pointer-input/migrate-swipeable
  2. (3 snippets) https://developer.android.com/develop/ui/compose/touch-input/scroll/nested-scroll-modifiers

Total: 11 code snippets (11 Kotlin and 0 XML) across 2 pages.

Resource migration notes
  1. Three untagged supporting XML layout files (view_in_compose_nested_scroll_interop.xml, list_item.xml, and fragment_bottom_sheet.xml) were added to compose/snippets/src/main/res/layout/ because the tagged Kotlin snippets in NestedScrollModifiers.kt reference their resource symbols (R.layout.view_in_compose_nested_scroll_interop, R.id.main_list, R.layout.list_item, R.layout.fragment_bottom_sheet, and R.id.compose_view) and will not compile without them.
  2. All three layout file names and view IDs were forced directly by the inflate(...) and findViewById(...) calls in the guide page code blocks.
List of modifications
  1. Migrate-swipeable page: Added type argument and constructor parameter <DragValue>(initialValue = DragValue.Start) to SwipeableState in MySwitchState (android_compose_touchinput_pointerinput_migrate_swipeable_state_legacy) so the class compiles.
  2. Migrate-swipeable page: Replaced placeholder ... inside AnchoredDraggableState(...) and DraggableAnchors { ... } with // [START_EXCLUDE] ... // [END_EXCLUDE] blocks supplying required constructor parameters and anchor definitions in android_compose_touchinput_pointerinput_migrate_swipeable_state_anchored, android_compose_touchinput_pointerinput_migrate_swipeable_access_offset, android_compose_touchinput_pointerinput_migrate_swipeable_anchors_update, android_compose_touchinput_pointerinput_migrate_swipeable_positional_threshold_fraction, android_compose_touchinput_pointerinput_migrate_swipeable_positional_threshold_dp, and android_compose_touchinput_pointerinput_migrate_swipeable_velocity_threshold.
  3. Migrate-swipeable page: Added .toInt() to state.requireOffset() inside IntOffset(...) in android_compose_touchinput_pointerinput_migrate_swipeable_access_offset, android_compose_touchinput_pointerinput_migrate_swipeable_anchors_constructor, and android_compose_touchinput_pointerinput_migrate_swipeable_anchors_update because IntOffset requires Int coordinates while requireOffset() returns Float, and fixed the mismatched closing brace } to ) on Box(...) in android_compose_touchinput_pointerinput_migrate_swipeable_access_offset.
  4. Migrate-swipeable page: Added val density = LocalDensity.current and wrapped DraggableAnchors { ... } in with(density) { ... } in android_compose_touchinput_pointerinput_migrate_swipeable_anchors_constructor so Dp.toPx() compiles, and hid required AnchoredDraggableState constructor parameters inside // [START_EXCLUDE silent] ... // [END_EXCLUDE] in android_compose_touchinput_pointerinput_migrate_swipeable_anchors_constructor.
  5. Nested-scroll-modifiers page: Added // [START_EXCLUDE silent] title = {}, // [END_EXCLUDE] inside TopAppBar(...) and replaced the trailing // ... comment in NestedScrollInteropAdapter with // [START_EXCLUDE] override fun getItemCount(): Int = items.size // [END_EXCLUDE] in android_compose_touchinput_scroll_nested_scroll_interop_compose_parent so the required TopAppBar parameter and RecyclerView.Adapter.getItemCount() implementation compile.
  6. Nested-scroll-modifiers page: Replaced non-existent android.R.layout.list_item with R.layout.list_item in ViewInComposeNestedScrollInteropExample (android_compose_touchinput_scroll_view_in_compose_interop) (Required for the Kotlin snippet to compile) and formatted scrollable(...) arguments across lines.
  7. Nested-scroll-modifiers page: Added untagged supporting XML layout resources view_in_compose_nested_scroll_interop.xml, list_item.xml, and fragment_bottom_sheet.xml under compose/snippets/src/main/res/layout/ (Required for the Kotlin snippet to compile).
Snippets not migrated
  1. Migrate-swipeable page:
    1. None (all 8 hardcoded code blocks on the guide page were migrated).
  2. Nested-scroll-modifiers page:
    1. None (all 3 remaining hardcoded code blocks on the guide page were migrated; lines 295–301 already reference touchinput_gestures_nested_scroll_interop.xml on GitHub via {% includecode %}).

@pengzhi-cb pengzhi-cb changed the title Migrate Migrate from Swipeable to AnchoredDraggable snippets Migrate Compose touch and input snippets Sep 18, 2026
@pengzhi-cb
pengzhi-cb force-pushed the pengzhi-cb/compose-migrate-swipeable branch from a0a6981 to aa14dc4 Compare September 29, 2026 21:56
@pengzhi-cb pengzhi-cb changed the title Migrate Compose touch and input snippets Migrate Snippet: Compose touch and input Sep 29, 2026
@pengzhi-cb
pengzhi-cb marked this pull request as ready for review September 29, 2026 22:08
@pengzhi-cb
pengzhi-cb requested a review from a team as a code owner September 29, 2026 22:08
@snippet-bot

snippet-bot Bot commented Sep 29, 2026 •

Copy link
Copy Markdown

Here is the summary of changes.

You are about to add 11 region tags.

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

@pengzhi-cb pengzhi-cb changed the title Migrate Snippet: Compose touch and input Migrate Compose touch and input snippets Sep 30, 2026
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.offset
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.material.Text

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.

can you import the m3 versions of Text and TopAppBar?

import com.example.compose.snippets.touchinput.pointerinput.DragValue.Center
import com.example.compose.snippets.touchinput.pointerinput.DragValue.End
import com.example.compose.snippets.touchinput.pointerinput.DragValue.Start

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.

Looks like we're using deprecated APIs in this file, so not sure if we should migrate those snippets

This branch has not been deployed

No deployments
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.

2 participants