Skip to content

feat: add pull-to-refresh to scrollable controls - #43

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

AdamMusa merged 2 commits into
mainfrom
feat/pull-to-refresh

Conversation

@AdamMusa

Copy link
Copy Markdown
Owner

Package A / A1 (pull-to-refresh, P0). Engine counterpart: AdamMusa/ruflet-engine#27. Implements lead decision D-2 as approved.

Depends on #31 (A0 scroll-methods): this branch is stacked on it, because end_refresh lives in ScrollableMethods. Review only the top commit, feat: add pull-to-refresh to scrollable controls.

What

  • ListView, GridView and Column gain on_refresh plus refresh_bgcolor, refresh_color, refresh_displacement, refresh_timeout and refresh_trigger_distance. KEYWORDS stay sorted with events last.
  • Page#dispatch_event: the smallest diff D-2 allows. Only control.emit is wrapped:
    begin
      control.emit(name, event)
    ensure
      invoke(control, "end_refresh") if name.to_s == "refresh"
    end
    Ruby handlers are synchronous, so the handler's page.update patches go out first on the same socket, followed by end_refresh. That also happens when the handler raises; the exception still propagates. No other event is touched.
  • ScrollableMethods#end_refresh(timeout: 10, on_result: nil) is public, for refreshes that finish later.
  • GestureEventFactory::EVENT_CLASS_MAP gets "refresh" => GenericEvent.

Usage

feed = list_view(expand: true, spacing: 8, padding: 16,
  controls: posts.map { |p| post_tile(p) },
  refresh_color: "#1E88E5",
  on_refresh: ->(_e) do
    feed.children.replace(Post.latest.map { |p| post_tile(p) })
    page.update
  end)
page.add(feed)

# A Column is refreshable too (it always scrolls when on_refresh is set):
column(controls: cards, alignment: "center", on_refresh: ->(_e) { reload!; page.update })

Wire and events

  • Props: on_refresh: true, refresh_* as above.
  • Event: refresh (payload nil).
  • Invoke end_refresh (no args) is sent to the same control id.
  • Material uses a RefreshIndicator (color, bgcolor, displacement). Cupertino uses a CupertinoSliverRefreshControl (color, trigger distance). See the engine PR for the full table.

Tests: test/pull_to_refresh_compatibility_test.rb, 9 runs, 74 assertions

  • Keywords serialize for all three controls, colors are normalized, has_handler?(:refresh) holds, and everything is off by default. Row and misspelled keywords are rejected.
  • Order: the handler runs, its patch_control is sent, and then the last message is invoke end_refresh on that wire id. The handler sees GenericEvent.
  • A raising handler still sends end_refresh, and the error propagates.
  • A refresh that arrives for a control without a handler is still acknowledged, which stops a stray spinner.
  • Other events are unaffected: scroll and size_change with handlers send nothing, and a raising scroll handler sends nothing either.
  • The end_refresh method sends the invoke payload; on an unmounted control it returns nil.

verify_pr.sh:

  • ruflet_core 147/147 files, 633 runs PASS
  • engine +728 PASS, analyze clean
  • wire-key audit: no new findings (2 textual diffs are hint-list changes on pre-existing ReorderableListView lines)

ListView, GridView and Column accept on_refresh plus refresh_color,
refresh_bgcolor, refresh_displacement, refresh_trigger_distance and
refresh_timeout. Page#dispatch_event invokes end_refresh on the control
once a refresh handler returns, also when it raises, so the native spinner
stops right after the handler's patches. ScrollableMethods gains a public
end_refresh for refreshes that finish later.
@AdamMusa
AdamMusa merged commit 0bb09bc 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