Home / File/ SwipeRecognizer.js — react Source File

SwipeRecognizer.js — react Source File

Architecture documentation for SwipeRecognizer.js, a javascript file in the react codebase. 3 imports, 1 dependents.

File javascript BabelCompiler Optimization 3 imports 1 dependents 1 functions

Entity Profile

Dependency Diagram

graph LR
  4b747fe5_c4c8_5191_f40d_84115cfe4dbd["SwipeRecognizer.js"]
  ac587885_e294_a1e9_b13f_5e7b920fdb42["react"]
  4b747fe5_c4c8_5191_f40d_84115cfe4dbd --> ac587885_e294_a1e9_b13f_5e7b920fdb42
  d5b4134c_fd3b_0af3_5976_2a805928a25d["scroll-timeline"]
  4b747fe5_c4c8_5191_f40d_84115cfe4dbd --> d5b4134c_fd3b_0af3_5976_2a805928a25d
  5d09073b_57f4_913b_2310_da858b4a3bd8["touch-pan-timeline"]
  4b747fe5_c4c8_5191_f40d_84115cfe4dbd --> 5d09073b_57f4_913b_2310_da858b4a3bd8
  ef975ced_d6a7_b295_dbfc_38e701d92f78["Page.js"]
  ef975ced_d6a7_b295_dbfc_38e701d92f78 --> 4b747fe5_c4c8_5191_f40d_84115cfe4dbd
  style 4b747fe5_c4c8_5191_f40d_84115cfe4dbd fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import React, {
  useRef,
  useEffect,
  startTransition,
  unstable_startGestureTransition as startGestureTransition,
} from 'react';

import ScrollTimelinePolyfill from 'animation-timelines/scroll-timeline';
import TouchPanTimeline from 'animation-timelines/touch-pan-timeline';

const ua = typeof navigator === 'undefined' ? '' : navigator.userAgent;
const isSafariMobile =
  ua.indexOf('Safari') !== -1 &&
  (ua.indexOf('iPhone') !== -1 ||
    ua.indexOf('iPad') !== -1 ||
    ua.indexOf('iPod') !== -1);

// Example of a Component that can recognize swipe gestures using a ScrollTimeline
// without scrolling its own content. Allowing it to be used as an inert gesture
// recognizer to drive a View Transition.
export default function SwipeRecognizer({
  action,
  children,
  direction,
  gesture,
}) {
  if (direction == null) {
    direction = 'left';
  }
  const axis = direction === 'left' || direction === 'right' ? 'x' : 'y';

  const scrollRef = useRef(null);
  const activeGesture = useRef(null);
  const touchTimeline = useRef(null);

  function onTouchStart(event) {
    if (!isSafariMobile && typeof ScrollTimeline === 'function') {
      // If not Safari and native ScrollTimeline is supported, then we use that.
      return;
    }
    if (touchTimeline.current) {
      // We can catch the gesture before it settles.
      return;
    }
    const scrollElement = scrollRef.current;
    const bounds =
      axis === 'x' ? scrollElement.clientWidth : scrollElement.clientHeight;
    const range =
      direction === 'left' || direction === 'up' ? [bounds, 0] : [0, -bounds];
    const timeline = new TouchPanTimeline({
      touch: event,
      source: scrollElement,
      axis: axis,
      range: range,
      snap: range,
    });
    touchTimeline.current = timeline;
    timeline.settled.then(() => {
      if (touchTimeline.current !== timeline) {
        return;
// ... (197 more lines)

Domain

Subdomains

Functions

Dependencies

  • react
  • scroll-timeline
  • touch-pan-timeline

Frequently Asked Questions

What does SwipeRecognizer.js do?
SwipeRecognizer.js is a source file in the react codebase, written in javascript. It belongs to the BabelCompiler domain, Optimization subdomain.
What functions are defined in SwipeRecognizer.js?
SwipeRecognizer.js defines 1 function(s): SwipeRecognizer.
What does SwipeRecognizer.js depend on?
SwipeRecognizer.js imports 3 module(s): react, scroll-timeline, touch-pan-timeline.
What files import SwipeRecognizer.js?
SwipeRecognizer.js is imported by 1 file(s): Page.js.
Where is SwipeRecognizer.js in the architecture?
SwipeRecognizer.js is located at fixtures/view-transition/src/components/SwipeRecognizer.js (domain: BabelCompiler, subdomain: Optimization, directory: fixtures/view-transition/src/components).

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free