Skip to content

refactor: move Switch onto the shared control core - #84

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

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

Conversation

@AdamMusa

@AdamMusa AdamMusa commented Oct 29, 2026 •

Copy link
Copy Markdown
Owner

Depends on #81 (control core foundation). Until #81 merges this PR's diff also shows its commit; review the last two commits.

What

Item 1 of the decoupling plan: Switch moves onto the shared core. Exactly two commits:

  1. test: snapshot Switch renderer behaviour: JSON snapshots of the legacy renderers (test/widgets/switch_snapshot_test.dart, test/snapshots/Switch/*.json, 10 fixtures x iOS/Android: defaults, unlabeled, maximal, sized, disabled, child-control label, RTL, nested theme, toggle_inputs tile, disabled in tile).
  2. refactor: move Switch onto the shared control core: the migration. Snapshots change only for the rows of the parity table below.

Design

File Now
controls/switch_core.dart (new) switchSpec (every Ruby keyword of the Switch wire type, single-skin entries with reasons), SwitchProps (one parse per build), SwitchCore (FocusableCore + TileToggleCore): value commits (writeBack then change with the new bool), label tap, tile taps (ignored while disabled), shared states (selected/disabled/focused), labelled() (one ToggleLabel: compact row, merged semantics, click cursor) and the width/height scale-to-fit in decorate.
controls/switch.dart MaterialSwitchSkin: maps the core onto Switch; picks the Material disabled label colour.
controls/cupertino_switch.dart CupertinoSwitchSkin: maps the core onto CupertinoSwitch (state colours resolved with core.states); picks the iOS disabled label colour.
controls/adaptive_switch.dart Same class/file (registry untouched): CoreHost<SwitchCore> under the legacy ValueKey("control_<id>"), PlatformControlRenderer closures build the skins.

width/height are sharedLayoutKeys (#81): LayoutControl still sizes (and animates with animate_size) exactly as before, the core scales the switch + label into that box.

Not edited: ruflet_core_extension.dart, control_type.dart, control_renderer_matrix_test.dart. Manifest: one entry in test/architecture/core_manifest.dart; switch.dart and cupertino_switch.dart leave legacy_renderers.txt. cupertino_control_independence_test.dart now mounts AdaptiveSwitchControl (the old Cupertino class took a Control; its assertions are unchanged and pass).

Parity changes (DC-5: only toward the more complete behaviour)

# Platform Before After Ruby impact Snapshot rows
1 iOS change sent without data change carries the new bool e.data was nil on iOS, now true/false like Android every iOS fixture step that toggles
2 iOS label row Row() (full width; tapping empty space toggled) compact row like Android (MainAxisSize.min) layout: labelled switches no longer stretch; RTL label sits next to the switch size.w, semantics/label rects in defaults, disabled, maximal, label_control, rtl, nested_theme
3 iOS label_text_style ignored honored (disabled colour still applied) styled labels on iOS maximal (label 18 px)
4 iOS a child-control label rendered its map as text ({value: Custom}) the control is rendered label: text(...) works on iOS label_control
5 iOS width/height only sized the box the switch + label scale into it (Android behaviour) same look on both sized
6 Android disabled switch toggled from a toggle_inputs ListTile ignores tile taps (iOS behaviour) no change from disabled switches list_tile_disabled.android
7 both page.invoke(switch, "focus") waited for the invoke timeout (no listener) fails fast: UnsupportedError("Switch(<id>).focus is not supported on <platform>: no handler ...") (#59's text) error returned immediately instead of after the timeout defaults invoke focus
8 Android thumb images and image_error ignored active_thumb_image(_src), inactive_thumb_image(_src) and image_error honored thumb images on Android (not visible in snapshots; ruby_switch_keys_test.dart)
9 both Ruby's active_thumb_image/inactive_thumb_image spellings ignored (only *_src read) both spellings honored (*_src wins) FOLLOWUPS E2 ruby_switch_keys_test.dart
10 iOS mouse_cursor ignored honored desktop iOS/macOS cursor ruby_switch_keys_test.dart
11 Android an empty-string label added an empty tap row; a child-control label had no click cursor empty label = no label (iOS rule); click cursor on any enabled label none visible none

No capability is removed. The audit's 4 baseline Switch findings (on_focus/on_blur not fired, active_thumb_image/inactive_thumb_image not read) are fixed.

Tests

  • Snapshot test (commit 1 against legacy, commit 2 updated per the table): 20 tests.
  • test/widgets/ruby_switch_keys_test.dart (7): thumb images from both spellings on both designs, iOS mouse_cursor + label_text_style, image_error reaches Ruby on both designs.
  • Contract test entry for Switch: C1 skin isolation, C2 core purity, C3 spec == Ruby (65 keywords), C4 skin consumption, C5 lifecycle (one listener, in-place replacement re-binds, unmount unregisters, undeclared method fails fast), C6 every key parsed, C7 identical events/write-backs/semantics on iOS and Android.

team/verify_pr.sh on head 8e228ef (base 81609d0 + #81 @ 02c2d4b) with ruflet origin/main (b5fd1694): PASS: engine flutter test +985 all passed, flutter analyze lib test no issues, ruflet_core 153/153 files. Wire-key audit: the regex audit did not know the core pattern and listed every Switch key as unread; team/audit/wire_key_audit.rb now reads PropSpec/EventSpec literals for migrated types (spec §4; legacy output byte-identical on #81), giving 0 new findings, 4 Switch findings fixed.

Round 2 (rebased onto #81 @ 02c2d4b after QA review)

Still exactly two own commits. The snapshot commit is unchanged in content and still passes against the legacy renderer on the new #81. In the migration commit:

  • (A) The spec now declares label, label_position, width and height as consumer: PropConsumer.core. Every other prop must be referenced by each skin it lists, so the core mentioning a field no longer excuses a skin. C4 passes under the stricter rule.
  • (B) The core passes C2b: no Control token or Control imports, and the constructor only forwards super.control.
  • (D)/(F) The manifest declares the native widgets (Switch/CupertinoSwitch). The parity script starts with tap native, a pointer tap on the native widget, so the skin's own onChanged wiring is compared on both designs, and it ends with unfocus. C7 now proves the script fires every core event: change (native tap and label/semantics taps), focus (tab) and blur (unfocus).
  • QA's twelve mutations, re-run on the rebased Switch tree, all fail (M4 C4, M8 C2b, M12 C7).
  • No parity rows changed; the snapshots are identical to round 1.

Gate

gh pr list --state open file check before starting and before opening: no open PR touches adaptive_switch.dart, switch.dart, cupertino_switch.dart or cupertino_control_independence_test.dart.

Sibling migrations (Checkbox, Radio) are also stacked on #81 and each add one manifest entry and replace adjacent lines of cupertino_control_independence_test.dart; merging them after this one is a keep-both resolution.

Add the shared control kernel every control will migrate onto: a pure-data
ControlSpec, PropReader as the only reader of wire keys, ControlEvents as the
only event dispatcher, ControlCore/FocusableCore for client state and focus,
and CoreHost as the single owner of a control's invoke listener and layout
keywords (re-bound when Ruby replaces the control in place). ToggleLabel,
TileToggleCore, CoreSemantics, RawProp and TextOrWidget are the neutral
pieces the first migrations share.

The control-core contract test checks every migrated control against rules
C1-C8 (skin isolation, core purity, spec equals Ruby KEYWORDS, skin
consumption, lifecycle, completeness, event and semantics parity, and a
report-only legacy ratchet). The manifest starts empty; the runtime rules run
against a test-only probe core and the static rules against adversarial
fixtures. The JSON snapshot harness and the Ruby control surface copy (with
tool/sync_ruby_surface.rb) support the migration PRs.
Record the legacy Switch renderers on iOS and Android as JSON snapshots:
geometry, semantics, what they send to Ruby during scripted taps, label taps,
keyboard focus and ListTile toggling, and invoke outcomes, for the defaults,
unlabeled, maximal, sized, disabled, child-control label, RTL, nested-theme
and toggle_inputs tile fixtures. The migration onto the shared control core
may change them only as listed in its parity table.
SwitchCore now owns everything Ruby sends or receives for a Switch: one parse
of every keyword (switchSpec), value commits, the label, toggle_inputs tile
taps, focus and the width/height scale-to-fit. The Material and Cupertino
skins only map the core's values onto Switch and CupertinoSwitch, and
AdaptiveSwitchControl hosts the core under the legacy key.

Both designs now send the new value with change, lay the label out in the
same compact row, honor label_text_style, child-control labels, thumb images
(either Ruby spelling), image_error, mouse_cursor and scale-to-fit, and a
disabled switch ignores tile taps. Snapshots change only for those rows.
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