Skip to content

feat: add scroll_to to scrollable controls - #31

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

AdamMusa merged 2 commits into
mainfrom
feat/scroll-methods

Conversation

@AdamMusa

Copy link
Copy Markdown
Owner

Package A / A0 (scroll-methods). Engine counterpart: AdamMusa/ruflet-engine#15 (Cupertino ReorderableListView answers scroll_to).

What

New Ruflet::UI::Controls::ScrollableMethods mixin (controls/shared/scrollable_methods.rb). It is included in ListViewControl, GridViewControl, ColumnControl, RowControl, ViewControl and ReorderableListViewControl. Before this, only Page#scroll_to existed, and it targets the page rather than a given list. A1 (pull-to-refresh) adds end_refresh to the same module.

def scroll_to(offset: nil, delta: nil, scroll_key: nil, duration: nil, curve: nil, timeout: 10, on_result: nil)

Only the arguments you pass are sent. On a control that isn't mounted yet (no runtime page) it returns nil without raising.

Usage

chat = list_view(expand: true, controls: messages)
page.add(chat)

send_button.on(:click) do
  chat.children << message_bubble(text)
  page.update
  chat.scroll_to(offset: -1, duration: 250, curve: "easeOut") # -1 = the very end
end

form.scroll_to(scroll_key: "email-field")   # bring a keyed child into view
grid.scroll_to(delta: 300)

A Column or Row has a scroll view only when scroll: is set, so scroll_to is a no-op otherwise. A refreshable Column (A1) always scrolls.

Wire

Invoke scroll_to on the control's own id. Args are offset, delta, scroll_key, duration (ms) and curve, the same names Page#scroll_to and the Dart ScrollableControl already use. No new props or events.

Material vs Cupertino

Both renderers answer through ScrollableControl. The engine PR fixes the one renderer that didn't: the Cupertino ReorderableListView.

Tests

New test/scrollable_methods_compatibility_test.rb (6 runs, 29 assertions), using a page with a sender: lambda:

  • payload name, control_id == wire_id, args and timeout
  • only the given args are sent
  • all six classes include the mixin and invoke on their own id
  • View#scroll_to targets the view, not page id 1
  • an unmounted control returns nil
  • on_result receives the client result

verify_pr.sh:

  • ruflet_core 146/146 files, 624 runs PASS (baseline 145/618)
  • engine +705 PASS, analyze clean
  • wire-key audit: NEW vs baseline: 0

The new file follows the mruby rules: no defined? and no Regexp. Each including file does its own require_relative, so load order between materials/ and shared/ doesn't matter.

ListView, GridView, Column, Row, View and ReorderableListView now share a
ScrollableMethods mixin whose scroll_to invokes the renderer's existing
scroll_to method (offset, delta, scroll_key, duration, curve) on that
control instead of only on the page.
@AdamMusa
AdamMusa merged commit a5936d2 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