Skip to content

fix: give iOS bottom sheets a native surface and honor their contract - #17

Merged
AdamMusa merged 2 commits into
codex/engine-initializationfrom
fix/cupertino-bottom-sheet-parity
Oct 29, 2026
Merged

AdamMusa merged 2 commits into
codex/engine-initializationfrom
fix/cupertino-bottom-sheet-parity

Conversation

@AdamMusa

@AdamMusa AdamMusa commented Oct 28, 2026 •

Copy link
Copy Markdown
Owner

Ruby counterpart: AdamMusa/ruflet#33

Fixes SPEC bug #2 / item D1 (P0): the iOS BottomSheet ignored most of its contract and showed non-picker content raw, with no surface.

What it renders

Ruby keyword iOS (Cupertino, this PR) Android/web/desktop (Material)
bgcolor sheet surface, default CupertinoColors.systemBackground (elevated) unchanged
show_drag_handle (false) 36x5 grabber, radius 2.5, systemGrey3, 6 px above/below unchanged (M3 handle)
use_safe_area (true) SafeArea(top: false) inside the surface, so the color runs behind the home indicator unchanged
maintain_bottom_view_insets_padding (true) the surface is lifted above the keyboard unchanged
scrollable (false) max height 9/16 of the screen; true = screen minus the top safe inset unchanged
size_constraints extra ConstrainedBox inside the 9/16 cap (same order as Material) unchanged
height, padding fixed surface height; padding around the content n/a
dismissible / modal, barrier_color barrier tap; barrier color is live (ControlBarrier, as in 1f21fca) unchanged
draggable (nil) drag-down-to-dismiss. The default is fullscreen (D-8): page sheets drag, popups do not unchanged (false)
fullscreen (false) native stacked iOS page sheet (CupertinoSheetRoute, enableDrag: draggable ?? true, showDragHandle) unchanged
elevation, shape, clip_behavior, animation_style ignored on iOS (Material-only; documented on the class) unchanged

The surface is ClipRRect(top 12) > ColoredBox(bgcolor) > SafeArea > Column([grabber?, Flexible(Padding(content))]). Drag-to-dismiss is a small private _CupertinoSheetDragDismiss (D-7). The surface follows the finger. On release it dismisses past 25 % of its height or above 700 px/s, and otherwise springs back. With scrollable: true, only the top 44 px start a drag, so inner scrollables keep their gestures. Picker, TimerPicker and DatePicker content keeps the existing fixed-height panel unchanged.

Wire keys: no new keys. Events: dismiss, unchanged.

Lifecycle (respects the existing open / on_dismiss contract)

  • open: true presents the sheet in a post-frame callback, inside the owning navigator (useRootNavigator: false semantics, as in 1f21fca).
  • open: false pops only the route this sheet presented. It uses removeRoute if something is stacked above it, and never pops whatever happens to be on top. It also works while the entrance animation is still running.
  • Each sheet that is opened reports exactly one dismiss and resets open, including a sheet closed before its post-frame presentation ran. Ruby untracks dialogs on dismiss (page.rb).

Deviations from the spec (intentional)

  • fullscreen uses Navigator.of(context).push(CupertinoSheetRoute(...)) instead of showCupertinoSheet. showCupertinoSheet always pushes onto the root navigator. That breaks the owner's rule (1f21fca) that native presentation is scoped to the owning navigator, and the open: false path could not find the route to pop. The route, transition, drag and handle are the same SDK classes.
  • The grabber sits above the padded content, not inside padding. padding insets the content, matching Material, where the handle is outside the content.
  • The page sheet fills the screen (SizedBox.expand, like Material fullscreen). height, size_constraints, barrier_color, dismissible and modal do not apply to it: an iOS page sheet has no barrier.

Tests

test/widgets/ruby_cupertino_bottom_sheet_test.dart: 22 iOS cases and 4 Android cases. Each iOS case also asserts that no Material widget is present.

  • surface present, full width, bottom-anchored, default and custom bgcolor, top radius 12
  • show_drag_handle: grabber rect 36x5, centered, surface.top + 6, systemGrey3
  • safe-area bottom padding (34 px home indicator); use_safe_area: false
  • keyboard inset lifts the surface by 300 px; maintain_bottom_view_insets_padding: false
  • 9/16 cap (337.5), scrollable cap (top inset 47), size_constraints (500x200, centered), height + padding geometry
  • drag 50 px springs back; mid-drag the surface follows; dragging past 25 % dismisses + fires dismiss + open=false; 60 px fling at 1500 px/s dismisses; popup without draggable stays (D-8); scrollable drags only from the top 44 px
  • live barrier color, barrier tap dismisses, modal / dismissible: false keep it open
  • open: false pops only the sheet. Rebuilds during the exit animation do not pop the page beneath, inside a nested navigator. Close while animating in, then reopen.
  • fullscreen: CupertinoSheetTransition + CupertinoSheetRoute, handle, surface color, drag-to-dismiss by default, draggable: false blocks it and open: false still closes
  • picker content keeps the 220 px panel
  • Android: Material BottomSheet color/handle, keyboard padding, draggable drags it away, and it does not drag by default (path untouched)

Before the fix, 16 of the 22 iOS cases failed. After it, all 26 pass.

verify_pr.sh with Flutter 3.41.2 against the Ruby counterpart:

PASS ruby:ruflet_core                   145/145 files, 623 runs
PASS engine:ruflet flutter test         +721: All tests passed!
PASS engine:ruflet analyze              No issues found!
INFO wire-key audit                     NEW vs baseline: 0

The audit's BottomSheet parity gap went from 11 Material-only props to the 4 documented iOS-ignored ones (animation_style clip_behavior elevation shape). The existing modal_presentation_test.dart, the matrix and the architecture tests are unchanged and pass.

Ruby usage

page.show_bottom_sheet(
  bottom_sheet(content: column(controls: [text("Share"), text_field(label: "Note")]),
               show_drag_handle: true, draggable: true)
)
page.show_bottom_sheet(bottom_sheet(content: settings_form, fullscreen: true)) # native iOS page sheet

Non-picker content was shown raw through showCupertinoModalPopup: no
surface, grabber, safe area or keyboard inset, and every sheet keyword
except dismissible/modal/barrier_color was ignored.

The iOS renderer now presents a rounded systemBackground surface with an
optional 36x5 grabber, SafeArea, keyboard lift, 9/16 (or full-height when
scrollable) sizing, size_constraints/height/padding and drag-to-dismiss.
fullscreen pushes the native CupertinoSheetRoute onto the owning
navigator. draggable defaults to fullscreen (D-8): page sheets drag,
popups do not. The picker panel is unchanged.

open: false now pops only the route the sheet presented (also while it
is still animating in), the barrier color stays live, and every opened
sheet reports exactly one dismiss.
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