Skip to content

Render LazyVGrid and LazyHGrid as Compose lazy grids - #16

Merged
colemancda merged 8 commits into
masterfrom
feature/grid
Jul 22, 2026
Merged

colemancda merged 8 commits into
masterfrom
feature/grid

Conversation

@colemancda

Copy link
Copy Markdown
Member

Neither grid had an Android renderer. Both now render through Jetpack Compose's lazy grids, following the List → ComposeListView interop precedent rather than inventing a new bridging mechanism.

Structure

ComposeGridView hosts a LazyVerticalGrid/LazyHorizontalGrid inside a FrameLayout (as with ComposeListView, ComposeView is final so it is hosted rather than subclassed), sourcing its cells from a Swift-implemented GridViewAdapter.

The adapter differs from ListViewAdapter in one important way: it vends fully realized Android views rather than strings, since grid cells are arbitrary SwiftUI content rather than plain text. Each cell is bridged back into the composition through Compose's AndroidView interop, so cells are real Android views and the view modifiers from the modifier pipeline apply to them normally.

Track sizing

A single GridItem(.adaptive(minimum:)) maps to GridCells.Adaptive, fitting as many tracks as will fit. Any other configuration maps to GridCells.Fixed with one track per item, which covers the common [GridItem(.flexible()), GridItem(.flexible()), ...] usage. Per-item sizing beyond that is not yet honored.

Cell extraction

Cells are recovered by recursively flattening group views and identified views, the same approach the picker uses for its rows — ForEach wraps each element in an identified view, which has to be descended through.

One trap worth calling out: ModifiedContent conforms to GroupView, with its bare content as the only child. A naive "descend into group views" walk therefore passes straight through modifiers and silently discards them — cells rendered as unstyled text with their .padding() and .background() stripped. Modified content is treated as a leaf for this reason.

Verification

On the emulator, via a new Grid gallery screen:

  • Three flexible columns lay out 9 cells as a 3×3 grid.
  • Adaptive columns fit 4 cells per row at the given minimum width.
  • LazyHGrid with two rows fills column-major (1, 2 down, then 3, 4 across), matching SwiftUI.
  • Cell modifiers survive: every cell keeps its padding and background color.

@colemancda
colemancda merged commit d97ec41 into master Jul 22, 2026
6 checks passed
@colemancda
colemancda deleted the feature/grid branch July 22, 2026 18:30
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