Lazy List, grids, and the async render pipeline - #24
Merged
Conversation
List emits count plus a provider callback rather than inline rows; the provider resolves each row subtree on demand, keyed by element id so row state survives scroll and reorder. refreshable attaches a refresh action through a context sink.
itemNode materializes a lazy row on demand. State changes now coalesce onto a platform main-thread scheduler rather than running inline: a Swift Task driving an async state write is on a native thread with neither the app class loader (needed for JNI object creation) nor the right to touch Compose state.
List renders a LazyColumn fetching each visible row through itemNode, wrapped in a PullToRefreshBox when refreshable; grids render LazyVerticalGrid/ LazyHorizontalGrid with fixed or adaptive tracks.
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.
Final step of the Compose-backed architecture (#18–#23). Adds the lazy container path — the one unbounded-tree case the design deferred — plus the async threading pipeline it exposed.
Lazy List
Listemits a node withcountand an item-provider callback, not inline rows. The provider resolves each row subtree on demand, keyed by element id so row@Statesurvives scroll and reorder. The interpreter renders aLazyColumnfetching each newly-visible row throughSwiftCallbacks.itemNode(id, index)— one JNI call per visible row, re-fetched when the tree (hence the provider id) changes. A 10,000-row list contributes one node plus the handful of rows on screen.itemNodeis the last of the fixed five-plus-one Kotlin→Swift externals; the bridge surface still never grows per-view.Grids
LazyVGrid/LazyHGridwith realGridItemtrack specs (.flexible,.fixed,.adaptive(minimum:)) → ComposeLazyVerticalGrid/LazyHorizontalGridwithGridCells.Fixed/Adaptive. Cells resolve eagerly (bounded in practice) but lay out in a real lazy grid.The async render pipeline
Pull-to-refresh was the first async state path (every prior callback ran synchronously on the main thread), and it surfaced a real bug: a Swift
Taskwriting@Stateruns on a native background thread, and JNI object creation there fails withClassNotFoundException— a background thread has neither the app class loader nor the right to touch Compose state.The fix is the threading pipeline the plan specified: state changes now coalesce onto a platform main-thread scheduler instead of rendering inline.
BridgeRuntimetakes a scheduler; the Android host provides a main-looperHandlerone. A dirty flag collapses multiple same-tick writes into one render, and nothing evaluates synchronously inside a callback (no reentrancy). This is also correct for the synchronous callbacks — they just post to the next frame.Verification
swift test: 30 tests — List emits count + provider (not inline rows), the provider resolves rows on demand, row identity is keyed by element id (survives reorder), refreshable attaches its action, grid track specs (fixed count + adaptive minimum).itemNode; scrolls smoothly.Task(1s sleep, background thread) →@Stateinsert → marshaled to the main looper → re-evaluate → materialize → recompose — prepends "Row 31".Architecture complete
The gallery now runs entirely on the Compose-backed renderer: all 12 screens, real
NavigationStacknavigation, and the full control/modifier/presentation/lazy surface — evaluated in native Swift, materialized as typed nodes, rendered by Jetpack Compose which owns identity, layout, animation, input, and virtualization.