Skip to content

refactor: move the Button family onto the shared control core - #90

Merged
AdamMusa merged 3 commits into
codex/engine-initializationfrom
refactor/button-control-core
Nov 2, 2026
Merged

AdamMusa merged 3 commits into
codex/engine-initializationfrom
refactor/button-control-core

Conversation

@AdamMusa

@AdamMusa AdamMusa commented Oct 29, 2026 •

Copy link
Copy Markdown
Owner

Depends on #88 (entry-shape rule, which adds ControlCore.wireType/parentWireType), which depends on #81. Until those merge, this PR's diff also shows their commits; review the last two.

What

Item 4 of the decoupling plan: the five Button wire types (Button, FilledButton, FilledTonalButton, OutlinedButton, TextButton) move onto the shared core. Exactly two own commits:

  1. test: snapshot Button renderer behaviour: JSON snapshots of the legacy renderers (test/widgets/button_snapshot_test.dart, test/snapshots/Button/*.json). There are 10 fixtures × iOS/Android:
    • each wire type's defaults, scripted as semantics tap, label tap, long press, mouse hover in/out, Tab focus, invoke focus, invoke blur;
    • icon, outlined icon, maximal (every key plus a style map), disabled;
    • a Button as an AlertDialog action.
  2. refactor: move the Button family onto the shared control core: the migration. Snapshots change only per the parity table below.

Design

File Now
controls/button_core.dart (new) One const ControlSpec per wire type (shared keys; elevation only where Ruby has it; default/destructive/text_style on Button only). ButtonProps and a single ButtonCore (FocusableCore). The core picks its spec and ButtonVariant from wireType, and inAlertDialog from parentWireType (#88). It owns: click (opens url, then click; non-null while enabled, like the legacy buttons); long press; hover and pressed state (one MouseRegion + Listener in decorate, firing hover for both designs); focus; the focus and blur methods.
controls/button.dart MaterialButtonSkin -> ElevatedButton / FilledButton (+ tonal) / OutlinedButton / TextButton (+ .icon). style goes through the existing pure parseButtonStyle (utils/buttons.dart imported show parseButtonStyle, not edited; #63/#76 touch it).
controls/cupertino_button_skin.dart (new) CupertinoButtonSkin -> CupertinoButton (plain/filled/tinted), the style map resolved against core.states (hovered, pressed, focused, disabled), same rendering as the legacy class.
controls/cupertino_dialog_action.dart CupertinoDialogActionSkin -> CupertinoDialogAction, for a Button inside an AlertDialog (a manifest helper of the Cupertino skin, so C1/C4 cover it).
controls/adaptive_button.dart Same class/file (registry untouched). Canonical entry shape (C1e, #88): create: ButtonCore.new, and skins chosen only on core.inAlertDialog. The key is control_<wire type>_<id>, because a core serves one wire type.

The legacy CupertinoButtonControl (cupertino_button.dart) stays, unchanged, for the IconButton family (next item); it stays in legacy_renderers.txt. button.dart and cupertino_dialog_action.dart leave it. Manifest: five entries sharing the core and skins, each with native widgets (ElevatedButton/FilledButton/OutlinedButton/TextButton and CupertinoButton). Each parity script runs tap native, a label tap, a long press, mouse hover in/out, Tab and unfocus, so it fires every core event (hover, focus, blur) on both designs.

Core-consumed (PropConsumer.core): url. Cupertino-only, with reasons: alignment, border_radius, padding, min_size, mouse_cursor, focus_color, disabled_bgcolor, opacity_on_click and size (Material takes these through style, or has no equivalent); the dialog-action keys default, destructive and text_style.

Parity changes (DC-5)

# Platform Before After Ruby impact Snapshot rows
1 both page.invoke(button, "blur") raised "Unknown Button method: blur" blur unfocuses the button (blur event); focus unchanged blur works defaults_* invoke blur (+ the focus flags that follow)
2 iOS CupertinoButton exposed no enabled state to accessibility hasEnabledState/isEnabled like Material (disabled: not enabled); the semantics node covers the whole bordered button VoiceOver reports disabled buttons as dimmed every iOS fixture's semantics flags; outlined/maximal semantics rects (+1–2 px border)
3 Android OutlinedButton.icon never fired hover (no onHover) hover true/false from the core for every variant on_hover works on outlined icon buttons icon_outlined.android
4 iOS a Button inside an AlertDialog was wrapped in BaseControl (opacity, tooltip, rtl, expand only) LayoutControl like every other button: width/height, margin, badge... layout keys work on iOS dialog actions not visible; ruby_button_keys_test.dart
5 both unknown methods raised Exception("Unknown Button method: x") #59's UnsupportedError("Button(<id>).x is not supported on <platform>: ...") error text only not in the snapshots
6 both the renderers read _internals.style before style style only none: nothing (Ruby or the engine) writes _internals.style none

Unchanged on both designs (identical snapshots): geometry, click/long-press payloads, hover on the other variants, focus, the disabled behaviour, icon composition, the maximal style rendering and the dialog action. Material keeps ignoring top-level color/bgcolor/elevation unless style is set (the legacy parseButtonStyle contract). The audit's 10 baseline Button findings (on_focus/on_blur not fired on any of the five types) are fixed.

Tests

  • Snapshot test: 20 (commit 1 against legacy, commit 2 updated per the table).
  • test/widgets/ruby_button_keys_test.dart (4): the iOS dialog action honors margin (Material unchanged), and blur is a method on both designs.
  • Existing tests that mounted the legacy classes (cupertino_control_independence_test.dart, ruby_button_attributes_test.dart) now mount the entry or find CupertinoButtonSkin; their assertions are unchanged. The pressed-style test's fixture gains on_click: true: its test backend records events without the subscription check the real backend applies, and the core only fires subscribed events.
  • Contract test, 5 entries: C1 (+ the dialog-action helper), C1e, C2/C2b, C3 (59–62 Ruby keywords each), C4, C5 (one listener; focus/blur methods), C6, C7 (native tap, long press, hover, focus/unfocus identical on iOS and Android).

team/verify_pr.sh on head f7a7e8f (on #88 ba72191) with ruflet origin/main 43928509: PASS: engine flutter test +1043 all passed, flutter analyze lib test no issues, ruflet_core 157/157 files, wire-key audit 0 new findings, 10 fixed.

Gate

No open PR touches adaptive_button.dart, button.dart, cupertino_dialog_action.dart, ruby_button_attributes_test.dart or the new files; checked before starting and before opening. utils/buttons.dart (#63, #76) is not edited. core_manifest.dart/legacy_renderers.txt/cupertino_control_independence_test.dart are also edited by #84/#86/#87 (adjacent lines; keep both).

Record the legacy renderers of the five Button wire types (Button,
FilledButton, FilledTonalButton, OutlinedButton, TextButton) on iOS and
Android as JSON snapshots: geometry, semantics, what they send to Ruby during
semantics taps, label taps, long presses, mouse hover and keyboard focus, and
invoke outcomes, plus icon, outlined-icon, maximal, disabled and AlertDialog
action fixtures. The migration onto the shared control core may change them
only as listed in its parity table.
ButtonCore now owns everything Ruby sends or receives for the Button,
FilledButton, FilledTonalButton, OutlinedButton and TextButton wire types:
one spec per wire type (it picks its spec and variant from its wire type),
click with url, long press, hover and pressed state, focus and the
focus/blur methods. The Material skin maps the core onto the five Material
buttons; the Cupertino skins render CupertinoButton (plain, filled, tinted),
or CupertinoDialogAction for a Button inside an AlertDialog. The registry
entry has the canonical shape (create: ButtonCore.new). The legacy
CupertinoButtonControl stays for the IconButton family until it migrates.

Both designs now answer the blur method, iOS buttons report their enabled
state to accessibility, Android OutlinedButton.icon fires hover, and an iOS
alert-dialog action honors the layout keywords. Snapshots change only for
those rows.
Brings in the PRs merged since, so #90 merges; conflicts take the resolution tested on the full merge of the open PRs.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01MqfxcsDiEUZngybe9L72JQ
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.

2 participants