Skip to content

feat: add page-level pull-to-refresh to View - #46

Merged
AdamMusa merged 2 commits into
codex/engine-initializationfrom
feat/view-refresh
Oct 29, 2026
Merged

AdamMusa merged 2 commits into
codex/engine-initializationfrom
feat/view-refresh

Conversation

@AdamMusa

@AdamMusa AdamMusa commented Oct 28, 2026 •

Copy link
Copy Markdown
Owner

Package A / A4 (view-refresh). Ruby counterpart: AdamMusa/ruflet#52.

Depends on #36 (A3) → #30 (A2) → #27 (A1). It reuses AdaptiveRefreshScrollView, boxSliver, EndReachedListener and the keyboard parser. Review only the top commit, feat: add page-level pull-to-refresh to View.

What (explicit View)

  • In view.dart, a View with on_refresh swaps the body's ScrollableControl(wrapIntoScrollableView: true, child: column) for ScrollableControl(scrollController: …, child: AdaptiveRefreshScrollView(slivers: [boxSliver(column)])).
  • The body is at least one viewport tall, so vertical_alignment/horizontal_alignment lay out as before. The View padding stays on the outer Container.
  • When a child has expand, the box is exactly one viewport tall so Expanded keeps flexing.
  • The app bar, drawers, FAB and bottom bars are untouched: they still live in PlatformPageScaffold.
  • The refresh path's ScrollableControl gets its own key, so toggling on_refresh at runtime doesn't reuse a state bound to the other controller.
  • Sliver files are split per owner. A1's scroll_slivers.dart now keeps only the shared paddedSliver/sliverItem. List slivers move to list_view_sliver.dart, grid slivers to grid_view_sliver.dart, and boxSliver/hasExpandedChild to box_sliver.dart (Column, View). The wire-key audit attributes every read in a renderer's import closure to that control. Once View imported the old combined file, it flagged a false near-miss aspect_ratio~child_aspect_ratio on View and cross-reads such as runs_count on ListView. With the split, each control's closure only reads its own Ruby keys. There is no behavior change.
  • on_end_reached and keyboard_dismiss_behavior work on the View too. on_end_reached needs a scroll view, so the View must have scroll: or on_refresh.

Ruby usage

page.views = [
  view(route: "/", appbar: app_bar(title: text("Inbox")),
       refresh_color: "#1E88E5",
       on_refresh: ->(_e) { reload_inbox!; page.update },
       controls: inbox_rows)
]

Wire

  • On View: on_refresh, refresh_color, refresh_bgcolor, refresh_displacement, refresh_trigger_distance, refresh_timeout, on_end_reached, end_reached_threshold and keyboard_dismiss_behavior, with the same meaning as A1–A3.
  • Events: refresh and end_reached on the View's id. Invoke end_refresh on the View's id.

Material vs Cupertino

  • Material: RefreshIndicator under the Material app bar.
  • Cupertino: CupertinoSliverRefreshControl under the CupertinoNavigationBar. The test asserts there is no material.Theme/Material widget anywhere on Cupertino.

Tests: test/widgets/ruby_view_refresh_test.dart, 10 tests on both designs, with a real Page → View → PlatformApp fixture

  • Geometry: the app bar rect, first and second child rects and the FAB rect are identical with and without on_refresh.
  • A pull fires refresh (exactly once), the spinner shows, View end_refresh settles it back, and the first child returns to its original position.
  • on_end_reached on a short scrolling View fires once (with scroll: auto and with on_refresh).
  • expand children keep flexing in a refreshable View.

Results (verify_pr.sh, Flutter 3.41.2):

  • engine flutter test +793: All tests passed! (A3 783 + 10)
  • flutter analyze lib test: No issues found!
  • ruflet_core 150/150 files, 646 runs
  • wire-key audit: NEW vs baseline: 0 (stable keys)

D-10 investigation: the implicit page View (page.add + page.on_refresh = …) is NOT implemented here

I checked how page-level View handlers are routed today, and ran it against origin/main + this stack:

  1. page.on_refresh = ->(e) {} (and page.on_scroll = …) goes through Page#method_missing → assign_split_prop → @view_props["on_refresh"] = <Proc>. The Proc itself is then serialized into the implicit View patch. No handler is registered and no on_refresh: true flag is set.
  2. page.on(:refresh) { } stores a handler in @page_event_handlers, but nothing sets on_refresh: true on the implicit View, so the client never fires the event.
  3. The Flutter View fires its events with target = its own id, which is @view_id = 20 for the implicit view. Page#dispatch_event looks that id up in @wire_index. The implicit view is not a registered Control, so the event is silently dropped. The same is true today for on_scroll on the implicit view.
  4. Page#invoke can address page id 1 or a registered control, but not the implicit view id 20, so end_refresh cannot be sent to it. Related pre-existing bug: Page#scroll_to, show_drawer, close_drawer, show_end_drawer and close_end_drawer invoke control 1 (Page). The Flutter page.dart invoke listener only knows take_screenshot, push_route, get_device_info and set_allowed_device_orientations, and throws Unknown Page method for anything else. Those listeners live on the View (id 20), so these page methods currently fail on the Flutter engine.

Supporting page.on_refresh= needs three changes to page.rb's event plumbing, about 20 lines:

  • (a) handler/flag setters, or generic on_* handling in assign_split_prop
  • (b) a new dispatch_event branch that routes implicit-view targets (@views.empty? && target == @view_id) to page handlers, with the same end_refresh ensure
  • (c) invoke addressing @view_id. Fixing (c) properly also changes where page.scroll_to/show_drawer go.

That is more than the "small page.rb change" D-10 allows, so per D-10 I stopped there. The implicit-view part needs a lead decision.

What works in this PR: an explicit view(route:, on_refresh:). It is a registered control, so A1's dispatch_event ensure acknowledges it with zero additional page.rb changes. This covers every app that uses page.views/routing.

A View with on_refresh renders its body as a refreshable CustomScrollView
(RefreshIndicator on Material, CupertinoSliverRefreshControl on
Cupertino) that is at least one viewport tall, so alignment, the app bar,
drawers and the FAB are unchanged and expand children keep flexing.
on_end_reached works on a scrolling View too.
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