Skip to content

Migrate Compose image optimization and scrollable grid snippets - #1132

Open
edward-williams-stellarelements wants to merge 7 commits into
android:mainfrom
StellarElements:compose-state
Open

edward-williams-stellarelements wants to merge 7 commits into
android:mainfrom
StellarElements:compose-state

Conversation

@edward-williams-stellarelements

@edward-williams-stellarelements edward-williams-stellarelements commented Sep 22, 2026 •

Copy link
Copy Markdown

Snippets for two Compose pages. One region tag goes into a new file, and one goes into a file that already holds tags.

Pages and tags:

The optimization tag renders exactly what the page prints. The scrollable grid tag has one visible change, listed below.

Ivan reviewed these on our fork, StellarElements#23.

List of modifications:

  • Create scrollable grid page, android_compose_layout_scrollable_grid_adaptive: the closing ) is now ) {}. The page prints LazyVerticalGrid(columns = GridCells.Adaptive(minSize = 20.dp)) with no content, which doesn't compile because content is a required parameter. The empty trailing lambda passes it in the visible code, so the snippet compiles exactly as shown. This replaces the silent exclude that hid , content = {} in the earlier revision. The page's prose explains the 20.dp value ("the 20.dp value specifies that every column is at least 20.dp… 88.dp wide, there are 4 columns at 22.dp each"), so 20.dp stays.

Not migrated:

  • The nested-scroll-modifiers page. It was queued twice, and Migrate Compose touch and input snippets #1118 migrates it, so this PR no longer changes touchinput/gestures/GesturesSnippets.kt or adds layout files.
  • The card page's minimal Card snippet, which the extraction also carried. That page is being migrated separately with time-pickers, and two pull requests adding the same tag to the same file would collide.

Rebased on main (4fb8a69). ./gradlew :compose:snippets:spotlessCheck :compose:snippets:compileDebugKotlin passes.

kkuan2011 and others added 5 commits September 30, 2026 15:48
- The adaptive grid snippet published GridCells.Adaptive(minSize = 20.dp)
  with an empty content lambda behind an exclude. The page prints 128.dp
  and a real items body, and its prose names 128.dp explicitly, so both
  are restored and the exclude is no longer needed.
- LinearLayoutManager took RecyclerView.VERTICAL where the page prints a
  bare VERTICAL. Imported the constant so the page's form compiles.
android_compose_components_card_minimal publishes to
develop/ui/compose/components/card, which Ramon is migrating in
#25 along with time-pickers. Two
pull requests adding the same tag to the same file would collide, so
this branch leaves the card page alone.
Ivan's review: GesturesSnippets.kt carried a hand-written object R where
layout ids were plain integers. It compiled and stayed outside the region
tags, so no page published it, but any reader running the snippet would
have inflated nothing.

Adds the four layouts the file actually needs and removes the stand-in, so
R resolves to the generated one. activity_main also declares
emoji_text_view, which EmojiSnippets.kt inflates from the same layout name;
lint could not check that reference until a real layout existed, and flags
it as MissingInflatedId once one does.
- Optimization: one android_compose_graphics_images_optimization region
  around both top-level MyImage overloads, which is the tag the DAC macro
  uses. The overloads take different parameter types and don't collide, so
  the PainterParameterSnippet wrapper and the orphan _url/_painter tags go.
- Adaptive grid: restore the 20.dp form with the required content hidden in
  a silent exclude. The tag is used only by the create-scrollable-grid quick
  guide, whose prose explains 20.dp. The earlier 128.dp "fix" was checked
  against lists.md, which uses android_compose_layouts_lazy_grid_adaptive,
  and duplicated that tag.
- Nested scroll interop: drop the TopAppBar stub that shadowed the Material
  API and call the real Material3 TopAppBar with a visible title = {}. The
  page omits the required title. @OptIn(ExperimentalMaterial3Api::class) is
  on the enclosing private object.
- Replace the hand-written "// ..." plus silent exclude forms: the
  AndroidView elision is a plain comment (the trailing comma compiles), and
  getItemCount() sits in a plain exclude.
- Add full stops to five comments (D29).
@snippet-bot

snippet-bot Bot commented Sep 30, 2026 •

Copy link
Copy Markdown

Here is the summary of changes.

You are about to add 2 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

@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.

Could you update the PR description? If the snippets on those pages are already in the snippets repo, then you can omit the page link in the PR.


@Composable
private fun LazyVerticalGridAdaptiveSample() {
// [START android_compose_layout_scrollable_grid_adaptive]

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.

Because the visible snippet on DAC does not compile, let's change the visible code so that it does compile, so we should omit the exclude tags

// [START android_compose_touchinput_gestures_nested_scroll_interop_compose_parent_android_child]
@Composable
private fun NestedScrollInteropComposeParentWithAndroidChildExample() {
val toolbarHeightPx = with(LocalDensity.current) { ToolbarHeight.roundToPx().toFloat() }

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.

Ah sorry, I realized I put this page in two tasks, so Peng has already migrated this in #1118 Could you revert this file change and remove this page from your PR description and the corresponding CL?

WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->

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.

I think you can remove these new xml files now, if you revert the change to GestureSnippets.kt?

@edward-williams-stellarelements edward-williams-stellarelements changed the title Add snippets for Compose image optimization, lists and nested scroll Add snippets for Compose image optimization and lists Oct 5, 2026
The nested-scroll-modifiers page was queued twice, and it's already
migrated in android#1118. Both pull requests add the same
layout files, so this branch leaves the page to android#1118:

- GesturesSnippets.kt goes back to main. The three new interop region
  tags, their imports, and the @OptIn on NestedScrollInterop are
  removed, and the stand-in object R that backs the existing
  interop_activity region is restored.
- The four layouts that were added only for those snippets are
  removed: activity_main, fragment_bottom_sheet, list_item, and
  view_in_compose_nested_scroll_interop.
Drop the silent exclude around content = {} so the published snippet shows the required empty trailing lambda, ) {}, per review.
@edward-williams-stellarelements edward-williams-stellarelements changed the title Add snippets for Compose image optimization and lists Migrate Compose image optimization and scrollable grid snippets Oct 5, 2026

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