Repository navigation
perf: native-scroll Modal swipe gesture, plus Flyout, Carousel and Overlay interaction performance - #721
Merged
Conversation
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
size-limit report 📦
|
…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
…-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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Two groups of changes, kept in separate commits:
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:
That version is in the history (
16ccc77,a096e35) and is fully replaced byb866204.-√distance: a 150px pull moved 12pxonClosekeeps the modal openfull-screenstartcubic-bezier(0.32, 0.72, 0, 1), sheet stays opaque, only the backdrop fadestouchcancelreturns the sheet to its open position.Overlay changes:
backdropClassNameprop.--rs-overlay-duration,--rs-overlay-easing-openand--rs-overlay-easing-close.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:
transparentOverlaywith the page behind staying interactivecontainerRef2. 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 orupdate()is called.With a 200-item flyout:
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
touchcancelinSlideranduseDrag(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
full-screenswipenavigator.maxTouchPoints > 0, independently ofdisableSwipeGesture. The timing is a design decision made here and is hardcoded inModal.module.css.oxfmt --checkreports.changeset/pre.json, which this PR doesn't touch.🤖 Generated with Claude Code
https://claude.ai/code/session_01TKGZMmLMhMQCkWB9YiQX2Y