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

Function getSwipeConfig

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

Source from the content-addressed store, hash-verified

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