Skip to content

feat: add custom_scroll_view and sliver children - #35

Merged
AdamMusa merged 2 commits into
mainfrom
feat/custom-scroll-view
Oct 29, 2026
Merged

AdamMusa merged 2 commits into
mainfrom
feat/custom-scroll-view

Conversation

@AdamMusa

Copy link
Copy Markdown
Owner

What

Adds custom_scroll_view and its sliver children: sliver_list, sliver_grid, sliver_to_box_adapter and sliver_fill_remaining (SPEC E1). A page can now mix lists, grids, boxes and sticky section headers in one scroll view.

Engine counterpart (renderer): AdamMusa/ruflet-engine#20

Usage

page.padding = 0
page.add(custom_scroll_view(expand: true, slivers: [
  sliver_to_box_adapter(container(height: 160, bgcolor: "#1e88e5", content: text("Hero"))),
  sliver_list(header: section_header("Today"), sticky_header: true,
              controls: today.map { |m| mail_tile(m) }),
  sliver_grid(header: section_header("Photos"), runs_count: 3, spacing: 4, run_spacing: 4,
              controls: photos.map { |p| image(src: p.url, fit: "cover") }),
  sliver_list(header: section_header("Earlier"), sticky_header: true, spacing: 8,
              controls: earlier.map { |m| mail_tile(m) }),
  sliver_fill_remaining(center { text("No more messages") })
]))

Block form (children land in controls, which the renderer reads when slivers is absent):

custom_scroll_view(expand: true) do
  sliver_list(spacing: 8) { messages.each { |m| list_tile(title: m.subject) } }
  sliver_grid(runs_count: 3) { photos.each { |p| image(src: p.url, fit: "cover") } }
end

Any non-sliver control placed in slivers scrolls as a single box. To add items, mutate a sliver's children and call page.update. The patch targets that sliver only.

Wire keys

CustomScrollView (custom_scroll_view, customscrollview; shared/customscrollview_control.rb):

  • slivers
  • controls (block children)
  • horizontal (default false)
  • reverse (default false)
  • anchor
  • cache_extent
  • clip_behavior
  • semantic_child_count
  • keyboard_dismiss_behavior ("manual" | "onDrag")
  • scroll, auto_scroll, scroll_interval
  • the common layout keywords
  • event: on_scroll

Sliver children carry only key data visible plus their own keys. Box layout keywords such as width, expand and margin raise ArgumentError:

DSL (both spellings) Wire Keywords (defaults)
sliver_list(children = nil, **, &block) SliverList controls, spacing (0), divider_thickness (0), item_extent, padding, build_controls_on_demand (true), header, sticky_header (false), bgcolor
sliver_grid(children = nil, **, &block) SliverGrid controls, runs_count (1), max_extent, spacing (10), run_spacing (10), child_aspect_ratio (1.0), padding, header, sticky_header (false), bgcolor
sliver_to_box_adapter(content = nil, **) SliverToBoxAdapter content
sliver_fill_remaining(content = nil, **) SliverFillRemaining content, has_scroll_body (false: Ruflet content is box content, not a nested scrollable), fill_overscroll (false)

All are registered in both CLASS_MAP files, the material control methods, the shared forwarders and Ruflet::DSL.

Material vs Cupertino

The scroll view and its slivers are design-neutral. iOS gets bouncing physics. Sticky headers use widgets-layer PinnedHeaderSliver inside SliverMainAxisGroup on both designs, and no Material widget is built on iOS. See the engine PR for the rendering details.

Gotchas

  • Full-bleed layouts need page.padding = 0. The view needs a bounded height, for example expand: true in the page column.
  • sliver_* controls outside a custom_scroll_view show the generic unknown-control error. This is intended (D-3).
  • sliver_fill_remaining with a ListView or GridView inside needs has_scroll_body: true.
  • Inside a DSL block, every helper call becomes a child. Pass item lists with controls: or nested blocks.

Not in this PR

  • Pull-to-refresh and end-reached: on_refresh / refresh_* / on_end_reached / end_reached_threshold are a follow-up once Package A's feat/pull-to-refresh and feat/end-reached merge. Those PRs are not open yet; only A0 (feat/scroll-methods: ruflet feat: add scroll_to to scrollable controls #31, ruflet-engine Dev #15) is.
  • scroll_to method: include ScrollableMethods for a Ruby custom_scroll_view.scroll_to(...) waits for A0 (ruflet feat: add scroll_to to scrollable controls #31, feat/scroll-methods). Until then, use page.invoke(view, "scroll_to", args: { "offset" => -1 }). The renderer already handles it.

Tests

test/custom_scroll_view_compatibility_test.rb (11 tests) covers:

  • wire types and key serialization
  • defaults (matching ListView and GridView)
  • block children landing in controls
  • compact aliases and control(:sliver_list)
  • headers
  • ArgumentError for box keywords on slivers and for unknown keywords or events
  • nested slivers getting their own wire ids, so page.update patches only the changed sliver_list
  • scroll event dispatch

team/verify_pr.sh (engine + Ruby worktrees): PASS

  • engine flutter test (Flutter 3.41.2): +720, all passed (baseline 695 + 20 focused + 5 matrix)
  • flutter analyze lib test: No issues found
  • ruflet_core: 146/146 files, 629 runs
  • wire-key audit: no findings for CustomScrollView or the Sliver* types. The audit's "NEW vs baseline: 2" are two pre-existing ReorderableListView findings whose hint text now also names custom_scroll_view.dart and sliver_children.dart. They are not new findings.

Add CustomScrollView (custom_scroll_view) with the sliver child types
sliver_list, sliver_grid, sliver_to_box_adapter and
sliver_fill_remaining. Lists and grids accept a header that can stay
pinned (sticky_header), slivers come from slivers: or from block
children, and sliver children only accept key, data, visible and their
own keywords. Registered in both CLASS_MAP files and the three DSL
helper files with both spellings.
@AdamMusa
AdamMusa merged commit 058959d into main Oct 29, 2026
5 checks passed
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