Skip to content

perf: native-scroll Modal swipe gesture, plus Flyout, Carousel and Overlay interaction performance - #721

Merged
blvdmitry merged 12 commits into
mainfrom
claude/serene-feynman-d010gt
Nov 21, 2026
Merged

blvdmitry merged 12 commits into
mainfrom
claude/serene-feynman-d010gt

Conversation

@blvdmitry

@blvdmitry blvdmitry commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Two groups of changes, kept in separate commits:

  1. Modal swipe gesture tuned to behave like the native iOS sheets. This needs a check on a real iPhone (see Notes).
  2. Smaller interaction fixes for Flyout, Carousel, Overlay and touch gestures, each self-contained.

1. Modal: swipe gesture

The gesture stays driven by touch events, the same architecture as before, with the parts that felt non-native reworked.

History, for reviewers reading the commits: an intermediate version moved the sheet with native scrolling and scroll snapping instead of touch events. Testing it on iOS showed that approach can't match native sheets:

  • Touching the sheet while it settled caught its momentum.
  • The release timing came from the browser's snap animation and couldn't be tuned.
  • The bottom sheet re-snapped when Safari resized the viewport.
  • The rubber band had to be disabled.

That version is in the history (16ccc77, a096e35) and is fully replaced by b866204.

Before Now
Tracking Ignored the first 32px, then stayed 32px behind the finger. A 120px drag moved the sheet 88px 1:1 after the 8px direction check. A 120px drag moves it 120px
Updates On the next animation frame after a touch move On every touch move
Release decision Closed after any 32px drag, or a 0.4px/ms flick Closes when the sheet would come to rest past half its size, using iOS's deceleration rate
Past the open position -√distance: a 150px pull moved 12px iOS rubber-band curve: a 150px pull moves about 67px. The bottom sheet's background extends below it
Scrolled content Decided once at touch start; content that could scroll took the whole gesture Content scrolls first, then the sheet follows within the same gesture once the content reaches its edge
Touch during the close animation Started a new drag and cut the close transition Ignored. The closing overlay lets the page receive input
onClose keeps the modal open Sheet stayed where it was released Springs back to its open position
full-screen Closed after a swipe with no visual feedback Moves with the swipe towards the end side
Screen-edge swipes Only the left edge was left to the browser, and only for start Both edges, for all horizontal positions
Sheet animation (touch devices) 150ms slide while fading with the overlay 500ms cubic-bezier(0.32, 0.72, 0, 1), sheet stays opaque, only the backdrop fades

touchcancel returns the sheet to its open position.

Overlay changes:

  • New backdropClassName prop.
  • Transition variables --rs-overlay-duration, --rs-overlay-easing-open and --rs-overlay-easing-close.
  • Pointer events are disabled while closing, so the page receives input right away.
  • One removal path that also covers disabled transitions and overlays closed before their open transition started. That last case became reachable after the Overlay open-timing change below.

Verified in Chromium with real touch input (CDP touch events through the browser input pipeline, phone viewport). Every row in the table above was checked, plus:

  • drawers in LTR and RTL
  • transparentOverlay with the page behind staying interactive
  • containerRef
  • a tap outside the sheet closing it
  • a DropdownMenu inside a sheet
  • a horizontal scroll area inside a drawer handing off at its edge

2. Smaller fixes

Flyout: measure the content once, reuse it while scrolling (@reshaped/utilities). Positioning deep-cloned and laid out the flyout content on every update: twice per open, and once or twice per scroll frame. Measurements are now kept for updates that only follow the trigger. They're dropped when the content is resized, its children change, the window resizes or update() is called.

With a 200-item flyout:

Before After
Clones per open 2 1
Clones over 60 scroll frames 119 0
Scroll handler time per frame 7.0ms 0.2ms

Carousel: don't render on every scroll frame. The scroll position was kept in state only to decide whether the arrow controls show, which re-rendered the carousel and every item on each frame. It's now stored as the reached edges.

Overlay / Modal: start the open animation in the frame it's triggered in. The transition used to start 3 frames (~51ms) after the click; it now starts within one frame.

Gestures: handle touchcancel in Slider and useDrag (Resizable), which stayed in the dragging state when iOS took over a touch.

Related Issue

None

Screenshots / Recordings

None. Measurements come from temporary scripts that aren't part of the PR.

Notes for Reviewers

  • Needs a pass on an iPhone. I couldn't run WebKit here. Things to try:
    • short sheet drag and release, both before and past halfway
    • pulling up past the open position
    • flicking away and immediately scrolling the page
    • a long sheet scrolled partway, then one continuous pull down
    • full-screen swipe
  • Touch moves update the transform directly instead of waiting for the next animation frame. iOS Safari dispatches touch moves once per frame, so this saves a frame of latency. It's a style-only update of a registered, non-inherited custom property.
  • Velocity projection uses UIScrollView's normal deceleration rate (0.998), as in "Designing Fluid Interfaces" (WWDC 2018).
  • Sheet styling is enabled with navigator.maxTouchPoints > 0, independently of disableSwipeGesture. The timing is a design decision made here and is hardcoded in Modal.module.css.
  • Tests follow the layout from test: split component tests into visual stories and vitest browser tests #722. Swipe behavior is covered by browser tests that dispatch touch events. Eight of them fail against the previous implementation.
  • oxfmt --check reports .changeset/pre.json, which this PR doesn't touch.

🤖 Generated with Claude Code

https://claude.ai/code/session_01TKGZMmLMhMQCkWB9YiQX2Y

Positioning cloned and laid out the whole flyout content on every update:
twice when opening (activation + the initial ResizeObserver report) and
once or twice on every scroll frame. Content size doesn't depend on its
position, so measurements are now kept for the updates that only follow
the trigger and dropped when the content is resized from the outside,
its children change or the position is updated manually.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TKGZMmLMhMQCkWB9YiQX2Y
Scroll position was stored in the state only to resolve the visibility
of the navigation controls, which re-rendered the carousel and all of
its items on every frame of a swipe. It's now stored as the reached
edges, which only change at the start and the end of the scroll.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TKGZMmLMhMQCkWB9YiQX2Y
Overlay waited for two animation frames after rendering before showing
itself, on top of a deferred state update, so Modal stayed hidden for
~3 frames after a tap. Rendering and showing now happen in layout
effects with the hidden styles resolved in between, so the transition
starts right away. The frame delay is only kept while transitions are
paused by a color mode change.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TKGZMmLMhMQCkWB9YiQX2Y
Touches interrupted by the system end with touchcancel instead of
touchend, which wasn't handled by the Modal swipe gesture, Slider and
useDrag. Modal stayed at the dragged offset with its transitions
disabled, Slider and Resizable stayed in the dragging state.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TKGZMmLMhMQCkWB9YiQX2Y
@github-actions

github-actions Bot commented Nov 21, 2026 •

Copy link
Copy Markdown

size-limit report 📦

Path Size Loading time (3g) Running time (snapdragon) Total time
Library / JS 54.11 KB (+1.37% 🔺) 1.1 s (+1.37% 🔺) 0 ms (+100% 🔺) 1.1 s
Library / CSS 24.89 KB (+0.61% 🔺) 498 ms (+0.61% 🔺) 0 ms (+100% 🔺) 498 ms
Theming / JS 7.8 KB (0%) 156 ms (0%) 50 ms (-41.55% 🔽) 206 ms
Theming with a default theme definition / JS 8.68 KB (0%) 174 ms (0%) 316 ms (+259.27% 🔺) 489 ms

…thout a transition

Overlay waited for transitionend to get removed, which never arrives when
it's deactivated before its open transition has started. It's now removed
right away when no transition is running after it's hidden.

Its transition duration and easings can be set with css variables and the
backdrop accepts its own classname, so the components rendering their
content in the overlay can align it with the animation of that content.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TKGZMmLMhMQCkWB9YiQX2Y
Modal was moved with touch event handlers: transform updates were applied
from the main thread once per frame, ignored the first 32px of the gesture
and relied on heuristics for the content scrolling, text selection and the
browser gestures.

On touch devices, modals with bottom, start, end and full-screen positions
are now rendered next to a spacer inside a scroll container with snap
points at the open and closed positions. Swiping the modal scrolls that
container, so tracking, momentum, snapping, rubber banding and the gesture
arbitration with the modal content are handled by the browser. Scripts only
resolve the swiped away state and dim the backdrop.

Sheet positions use a longer decelerating animation and stay opaque while
they move. Devices without touch support and disableSwipeGesture keep the
previous positioning and animation.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TKGZMmLMhMQCkWB9YiQX2Y
@blvdmitry blvdmitry changed the title perf: mobile interaction performance for Flyout, Carousel, Overlay and touch gestures perf: native-scroll Modal swipe gesture, plus Flyout, Carousel and Overlay interaction performance Nov 21, 2026
…-d010gt

Tests added on this branch are moved from the story play functions
to the browser test files introduced on main.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TKGZMmLMhMQCkWB9YiQX2Y
… tests

- useModalScroll uses rafThrottle instead of its own frame handling and
  resets the gesture state in one place
- Overlay removes itself through a single path once there is no close
  transition to wait for, which also covers disabled transitions
- Modal swipe tests stub the touch support in beforeEach/afterEach and
  share the setup, following the browser test conventions

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TKGZMmLMhMQCkWB9YiQX2Y
The swipe container had pointer-events: none so that the area around the
modal kept belonging to the overlay. WebKit disables touch interaction for
scroll containers that are not visible to hit testing, even when the touch
starts on their children, so on iOS the modal couldn't be swiped at all.

The container now receives pointer events and is clipped to the area of
the open modal instead, which keeps the clicks and touches outside of it
going to the overlay. Overscroll is disabled for the container, since it
would move the modal into the clipped area, so its background no longer
has to be extended past the screen edge.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TKGZMmLMhMQCkWB9YiQX2Y
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TKGZMmLMhMQCkWB9YiQX2Y
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TKGZMmLMhMQCkWB9YiQX2Y
Testing the native scrolling version on iOS showed limits of the approach:
touching the modal while it was settling caught its momentum, the release
timing came from the scroll snapping and couldn't be tuned, the bottom
modal re-snapped when Safari resized the viewport, and the rubber band had
to be disabled since the container was clipped.

The swipe gesture is driven by touch events again, with the issues of the
previous implementation fixed:

- Modal follows the finger 1:1, without the 32px dead zone and lag, and
  updates on every touch move instead of the next animation frame
- Release closes the modal when it would stop past half of its size with
  the release velocity, projected with the iOS deceleration rate
- Rubber band past the open position uses the iOS resistance curve, and
  the bottom modal background is extended below it while it's pulled up
- Content scrolling on the swipe axis hands off to the modal within the
  same gesture once it reaches its edge
- Closing modals can't be caught again and the overlay lets the page
  receive input while it's closing
- Modal kept open in onClose returns to its open position
- Full-screen modals move with the swipe, horizontal swipes starting at
  either screen edge are left to the browser navigation gestures

Sheet animation timing, touchcancel handling and the Overlay changes from
the previous approach are kept.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TKGZMmLMhMQCkWB9YiQX2Y
@blvdmitry
blvdmitry merged commit 979424d into main Nov 21, 2026
11 checks passed
@blvdmitry
blvdmitry deleted the claude/serene-feynman-d010gt branch November 21, 2026 15:25
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