Skip to content

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

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

AdamMusa merged 2 commits into
mainfrom
feat/view-refresh

Conversation

@AdamMusa

Copy link
Copy Markdown
Owner

Package A / A4 (view-refresh). Engine counterpart: AdamMusa/ruflet-engine#46.

Depends on #49 (A3) → #45 (A2) → #43 (A1) → #31 (A0). Review only the top commit, feat: add page-level pull-to-refresh to View.

What

ViewControl accepts on_refresh, refresh_bgcolor, refresh_color, refresh_displacement, refresh_timeout, refresh_trigger_distance, on_end_reached and end_reached_threshold. keyboard_dismiss_behavior came with A3. An explicit view is a registered control, so A1's Page#dispatch_event ensure sends end_refresh to the view's wire id after its handler. No page.rb change.

Usage

page.views = [
  view(route: "/", appbar: app_bar(title: text("Inbox")),
       on_refresh: ->(_e) { reload_inbox!; page.update },
       on_end_reached: ->(_e) { load_more!; page.update },
       scroll: "auto",
       controls: inbox_rows)
]

Wire and events

  • Events refresh and end_reached target the View id; invoke end_refresh goes to the View id, not the Page id 1.
  • Material uses RefreshIndicator, Cupertino uses CupertinoSliverRefreshControl; see the engine PR.

Tests: test/view_refresh_compatibility_test.rb, 4 runs, 20 assertions

  • All the keywords serialize.
  • An explicit view's refresh handler runs, then end_refresh is invoked on the view's wire id (not 1).
  • end_reached reaches its handler with no end_refresh.
  • View#end_refresh targets the 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.

View accepts on_refresh, the refresh_* options, on_end_reached and
end_reached_threshold. An explicit view(route:, on_refresh:) is a
registered control, so its refresh is dispatched to the handler and
acknowledged with end_refresh on the view like any scrollable.
@AdamMusa

Copy link
Copy Markdown
Owner Author

Follow-ups approved by the lead for the D-10 findings below: #54 (page scroll_to/drawer methods → View) and #55 (page.on_refresh = and other default page View events). This PR is unchanged.

@AdamMusa
AdamMusa merged commit 113f7c9 into main Oct 29, 2026
12 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