MCPcopy
hub / github.com/xiaolin/react-image-gallery / computeSlideTarget

Function computeSlideTarget

src/components/utils/swipe.ts:83–107  ·  view source on GitHub ↗
(
  currentIndex: number,
  swipeDirection: number,
  isSufficient: boolean,
  isFlick: boolean,
  isTransitioning: boolean,
  canSlideLeft: boolean,
  canSlideRight: boolean
)

Source from the content-addressed store, hash-verified

81 * Computes the target slide index after a swipe ends.
82 */
83export function computeSlideTarget(
84 currentIndex: number,
85 swipeDirection: number,
86 isSufficient: boolean,
87 isFlick: boolean,
88 isTransitioning: boolean,
89 canSlideLeft: boolean,
90 canSlideRight: boolean
91): number {
92 let slideTo = currentIndex;
93
94 if ((isSufficient || isFlick) && !isTransitioning) {
95 slideTo += swipeDirection;
96 }
97
98 // Clamp: if we can't slide in the requested direction, stay put
99 if (swipeDirection === -1 && !canSlideLeft) {
100 slideTo = currentIndex;
101 }
102 if (swipeDirection === 1 && !canSlideRight) {
103 slideTo = currentIndex;
104 }
105
106 return slideTo;
107}
108
109/**
110 * Computes the target displayIndex for the CSS transform.

Callers 2

ImageGallery.tsxFile · 0.90
swipe.test.tsFile · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected