Skip to content

feat: add SliverAppBar for CustomScrollView - #26

Merged
AdamMusa merged 2 commits into
codex/engine-initializationfrom
feat/sliver-app-bar
Oct 29, 2026
Merged

AdamMusa merged 2 commits into
codex/engine-initializationfrom
feat/sliver-app-bar

Conversation

@AdamMusa

@AdamMusa AdamMusa commented Oct 28, 2026 •

Copy link
Copy Markdown
Owner

Depends on #20 (CustomScrollView). This branch is stacked on feat/custom-scroll-view. Until #20 merges, review only the last commit, "feat: add SliverAppBar for CustomScrollView".

What

Adds SliverAppBar, the collapsing app bar sliver for CustomScrollView (SPEC E2). On iOS it is the large title that collapses into the navigation bar on scroll.

Ruby counterpart: AdamMusa/ruflet#42

Material vs Cupertino

Material (material_sliver_app_bar.dart) Cupertino (cupertino_sliver_app_bar.dart, no Material symbols)
variant: "small" (default) SliverAppBar CupertinoNavigationBar in a PinnedHeaderSliver (pinned), a SliverFloatingHeader (floating; snap → FloatingHeaderSnapMode.scroll, otherwise overlay), or a SliverToBoxAdapter (scrolls away)
"medium" / "large" SliverAppBar.medium / .large (expanded 112 / 152, collapsed 64, plus the status bar) CupertinoSliverNavigationBar: the 52pt large title collapses into the always-pinned 44pt bar (plus the status bar)
pinned as given; when nil, true for medium/large and false for small small only (iOS large bars are always pinned)
floating, snap, stretch as named. snap is forced off without floating (the SDK asserts), with a debugPrint warning naming the control id small SliverFloatingHeader; stretch on large
expanded_height, collapsed_height, toolbar_height as named. collapsed_height is clamped to at least toolbar_height (the SDK asserts), with a debugPrint warning naming the control id and the values ignored
flexible_space FlexibleSpaceBar(title:, background:). The title moves into it. Small defaults expanded_height to 200 (+ bottom) No parallax (deferred, D-9): rendered as a plain box sliver right below the bar, which stays pinned past it
bottom + bottom_height (48) bottom: PreferredSize bottom: PreferredSize, bottomMode: automatic
leading, actions leading, actions leading, trailing: Row(actions)
bgcolor backgroundColor backgroundColor
color, elevation, scrolled_under_elevation, shadow_color, center_title as named ignored
automatically_imply_leading as named as named
previous_page_title, border, always_show_middle ignored as named; border defaults to the SDK hairline
transition_between_routes ignored default false, which avoids duplicate nav-bar heroes when a page app bar exists

Implementation notes:

  • Shared keyword reading: both renderers read the Ruby keywords through one neutral SliverAppBarSpec (sliver_app_bar_spec.dart), so names and defaults cannot drift between designs.
  • Wiring: adaptive_sliver_app_bar.dart picks the renderer with PlatformControlRenderer. sliver_children.dart builds the SliverAppBar like the other sliver child types (D-3: not registered in createWidget). It also emits a sibling SliverAppBarFlexibleSpace sliver, which is empty except for iOS flexible_space.
  • Alias: CupertinoSliverNavigationBar is accepted as an alias of SliverAppBar (D-1).
  • Events: the SliverAppBar has no events.

Tests

  • New test/widgets/ruby_sliver_app_bar_test.dart (13 tests on a portrait phone surface):
    • iOS large: the bar is 116 tall (20 inset + 44 + 52). The large title is visible and the inline title hidden. After a 200px scroll, the bar is 64 (20 + 44) and pinned, the large title is hidden, and the inline title is visible inside the bar. Actions render. No Material widget and no FlexibleSpaceBar.
    • iOS medium: 96 → 44.
    • iOS small: scrolls away; pinned stays 44.
    • iOS small floating: hidden after scrolling, reappears on a reverse drag, and snaps to 44 when the gesture ends.
    • iOS flexible_space and bottom: bar 126, hero box directly below, rows after it.
    • iOS alias: CupertinoSliverNavigationBar renders the canonical bar.
    • Android large: 152 → 64 pinned, and actions render.
    • Android medium with a 24 status-bar inset: 136 → 88.
    • Android small: unpinned by default. Pinned with toolbar_height 70 and expanded_height 180 gives 180 → 70.
    • Android small floating with snap: reappears on a reverse drag and snaps to 56.
    • Android flexible_space: uses a FlexibleSpaceBar, 200 + 48 tall, with the title not duplicated.
    • Android invalid SDK combinations (snap without floating, collapsed below toolbar): corrected instead of asserting, and each correction prints Warning: SliverAppBar(<id>) …. A valid configuration prints no warning.
  • control_renderer_matrix_test.dart: the CustomScrollView fixture now starts with a pinned large SliverAppBar, on iOS, Android, macOS, Windows and Linux. This proves that the iOS path builds no Material widget.
  • control_type_test.dart: the new alias.
  • team/verify_pr.sh (engine + Ruby worktrees, stacked on E1): PASS
  • engine flutter test (Flutter 3.41.2): +733, all passed (E1's 720 + 13 new)
  • flutter analyze lib test: No issues found
  • ruflet_core: 147/147 files, 635 runs
  • wire-key audit: NEW vs baseline 0 (keyed comparison). SliverAppBar, CustomScrollView and the Sliver* types have no findings.

Render Ruby's SliverAppBar as a sliver inside CustomScrollView.
Material uses SliverAppBar (small, medium or large) with pinned,
floating, snap, stretch, expanded/collapsed/toolbar heights, bottom and
a FlexibleSpaceBar for flexible_space. Cupertino uses
CupertinoSliverNavigationBar for medium and large, so the large title
collapses into the always pinned navigation bar on scroll, and a
CupertinoNavigationBar in a pinned, floating or plain sliver for small.

iOS has no parallax flexible space: flexible_space scrolls as a box
right below the pinned navigation bar. Both renderers read the Ruby
keywords through one neutral SliverAppBarSpec, and
CupertinoSliverNavigationBar is accepted as an alias.

Material corrects the SDK's asserted combinations (snap without
floating, collapsed_height below toolbar_height) and prints a warning
naming the control id and the correction.
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