MCPcopy Create free account
hub / github.com/adobe/react-spectrum / getSwipeConfig

Function getSwipeConfig

packages/react-aria-components/src/Sheet.tsx:555–604  ·  view source on GitHub ↗
(swipeDirection: SheetSwipeDirection)

Source from the content-addressed store, hash-verified

553// (the actual browser viewport) looks onto it. The stage always sits 1 viewport into the content,
554// and snap markers at the content extremes define the entered/exited resting positions.
555function getSwipeConfig(swipeDirection: SheetSwipeDirection): SwipeConfig {
556 let axis: Axis =
557 swipeDirection === 'top' || swipeDirection === 'bottom' || swipeDirection === 'vertical'
558 ? 'y'
559 : 'x';
560 let before =
561 swipeDirection === 'top' ||
562 swipeDirection === 'left' ||
563 swipeDirection === 'vertical' ||
564 swipeDirection === 'horizontal';
565 let after =
566 swipeDirection === 'bottom' ||
567 swipeDirection === 'right' ||
568 swipeDirection === 'vertical' ||
569 swipeDirection === 'horizontal';
570 // Each exitable side adds a viewport of scroll travel.
571 let maxScroll = (Number(before) + Number(after)) * 100;
572 // When the sheet can only exit toward the start edge (top/left), it rests at scroll 0 and is
573 // swiped toward maxScroll to dismiss. Otherwise it rests 1 viewport in.
574 let enteredScroll = before && !after ? 0 : 100;
575 // Position the container so the rest position lands in the real viewport.
576 let containerOffset = before && !after ? -100 : 0;
577
578 // The sheet crosses a single viewport edge (the swipe edge), so map the animation to just that
579 // crossing. In view-timeline terms `entry` is the scrollport's end edge (bottom/right, where the
580 // sheet appears from) and `exit` is the start edge (top/left). Direction is chosen so progress 0
581 // is the exited state and 1 is entered, matching keyframes authored from exited -> entered:
582 // `entry` already runs gone -> entered, while `exit` runs entered -> gone and is reversed.
583 //
584 // Dual directions cross both edges, so run the same keyframe over the full `cover` range twice
585 // (iteration count 2) with `alternate`: the view timeline splits its progress across the two
586 // iterations, so it plays exited -> entered -> exited around the centered rest position. This
587 // reuses a single exited -> entered keyframe rather than requiring an author to also write a
588 // symmetric (0%/50%/100%) variant.
589 const viewRange = before && after ? 'cover' : before ? 'exit' : 'entry';
590 const viewDirection = before && after ? 'alternate' : before ? 'reverse' : 'normal';
591 const viewIterations = before && after ? 2 : 1;
592
593 return {
594 axis,
595 before,
596 after,
597 maxScroll,
598 enteredScroll,
599 containerOffset,
600 viewRange,
601 viewDirection,
602 viewIterations
603 };
604}
605
606// The resting [x, y] flex alignment for each sheet position, independent of the swipe direction.
607const POSITION_ALIGNMENT: Record<SheetPosition, [string, string]> = {

Callers 2

Sheet.tsxFile · 0.85
useSwipeAnimationFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected