Skip to content

Render lazy-stack on Android with a LazyColumn - #216

Open
simonhamp wants to merge 1 commit into
feat/lazy-stackfrom
feat/lazy-stack-android
Open

simonhamp wants to merge 1 commit into
feat/lazy-stackfrom
feat/lazy-stack-android

Conversation

@simonhamp

Copy link
Copy Markdown
Member

The Android renderer for <native:lazy-stack>, as a Compose LazyColumn. Stacked on the iOS PR, so merge that first.

  • Children are keyed by node id.
  • gap-* sets the spacing between rows, content-padding becomes contentPadding, and p-* and bg-* work as on any element.
  • shows-indicators does nothing, since LazyColumn has no scrollbar.
  • When you're scrolled down, rows added above keep your place. When you're at the very top, LazyColumn would also hold its place and the new rows would land out of sight, so the renderer scrolls back to the top when you were there.
  • Inside a scroll view it falls back to a plain column, like lazy_grid.
  • The manifest now points Android at this renderer instead of ScrollViewRenderer.

Numbers

Heimdall firehose on an API 35 emulator, 60 rows a second for 60 seconds:

  • At the top: 59 to 60 updates a second for the first 40 s, 56 to 58 after. Frame time p50 17 ms.
  • Scrolled down: 58 to 59 updates a second, frame time p50 17 ms, p99 22 ms. The visible rows stayed put.

Worth checking

  • Not run on a real Android phone.
  • The slower last 20 s at the top lined up with slower parsing, which points at emulator load, but that isn't confirmed.

Tests: 4 new Robolectric tests. The existing list tests and the 501 PHP tests pass.

🤖 Generated with Claude Code

Android pointed lazy_stack at the scroll view renderer as a stopgap, which
ignored content-padding. LazyStackRenderer replaces it and matches iOS:

- children are keyed by node id
- gap-* becomes the column's spacing
- p-* and bg-* come in on the modifier like any element
- content_padding_* becomes the LazyColumn's contentPadding
- shows-indicators is accepted but does nothing, since a LazyColumn has
  no scroll indicator

A LazyColumn keeps the first visible child in place by key when children
are added above it, which is right for a reader scrolled down. It does that
at the very top too, so new rows would land above the screen. The renderer
checks during composition, before the new children are measured, whether the
reader was at the top, and if so asks for the top again with
requestScrollToItem(0).

Inside a scroll view the height is unbounded and a LazyColumn would throw,
so it falls back to a plain column, like the lazy grid does.

On an API 35 emulator with the heimdall firehose (60 rows a second, capped
at 1,000), the main thread applied 56 to 60 updates a second for the whole
minute, before and after the cap, with new rows showing at the top. Scrolled
down, the rows on screen stayed put until they were trimmed off the end.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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