@@ -16,7 +16,6 @@ import {
1616 DEFAULT_SLIDE_DURATION ,
1717 DEFAULT_SLIDE_INTERVAL ,
1818 DEFAULT_SWIPE_THRESHOLD ,
19- DEFAULT_SWIPING_TRANSITION_DURATION ,
2019} from "src/components/constants" ;
2120import BottomNav from "src/components/controls/BottomNav" ;
2221import Fullscreen from "src/components/controls/Fullscreen" ;
@@ -154,7 +153,6 @@ const ImageGallery = forwardRef<ImageGalleryRef, ImageGalleryProps>(
154153 startIndex = 0 ,
155154 stopPropagation = false ,
156155 swipeThreshold = DEFAULT_SWIPE_THRESHOLD ,
157- swipingTransitionDuration = DEFAULT_SWIPING_TRANSITION_DURATION ,
158156 thumbnailPosition = "bottom" ,
159157 useBrowserFullscreen = true ,
160158 useTranslate3D = true ,
@@ -329,7 +327,7 @@ const ImageGallery = forwardRef<ImageGalleryRef, ImageGalleryProps>(
329327 }
330328
331329 const swipingTransition : CSSProperties = {
332- transition : `transform ${ swipingTransitionDuration } ms ease-out` ,
330+ transition : "none" ,
333331 } ;
334332
335333 setCurrentSlideOffset ( side * slideOffset ) ;
@@ -345,7 +343,6 @@ const ImageGallery = forwardRef<ImageGalleryRef, ImageGalleryProps>(
345343 galleryWidth ,
346344 galleryHeight ,
347345 slideVertically ,
348- swipingTransitionDuration ,
349346 swipingUpDown ,
350347 swipingLeftRight ,
351348 setCurrentSlideOffset ,
@@ -354,7 +351,7 @@ const ImageGallery = forwardRef<ImageGalleryRef, ImageGalleryProps>(
354351 ) ;
355352
356353 const handleOnSwipedTo = useCallback (
357- ( swipeDirection : number , isFlick : boolean ) => {
354+ ( swipeDirection : number , isFlick : boolean , velocity : number ) => {
358355 let slideTo = currentIndex ;
359356
360357 if ( ( sufficientSwipe ( ) || isFlick ) && ! isTransitioning ) {
@@ -368,11 +365,35 @@ const ImageGallery = forwardRef<ImageGalleryRef, ImageGalleryProps>(
368365 slideTo = currentIndex ;
369366 }
370367
371- slideToIndexCore ( slideTo ) ;
368+ // Compute duration from swipe velocity so the animation continues
369+ // at the same speed the user's finger was moving.
370+ // velocity is in px/ms from the swipe library.
371+ const swipedPercent = Math . abs ( currentSlideOffset ) ;
372+ const remainingPercent =
373+ slideTo !== currentIndex
374+ ? 100 - swipedPercent // traveling to next/prev slide
375+ : swipedPercent ; // snapping back to current slide
376+ const dimension = slideVertically ? galleryHeight : galleryWidth ;
377+ const remainingPx = ( remainingPercent / 100 ) * dimension ;
378+ // Clamp: at least 80ms (not jarring), at most slideDuration
379+ const velocityDuration =
380+ velocity > 0
381+ ? Math . min (
382+ slideDuration ,
383+ Math . max ( 80 , Math . round ( remainingPx / velocity ) )
384+ )
385+ : slideDuration ;
386+
387+ slideToIndexCore ( slideTo , undefined , false , velocityDuration ) ;
372388 } ,
373389 [
374390 currentIndex ,
391+ currentSlideOffset ,
375392 isTransitioning ,
393+ slideDuration ,
394+ slideVertically ,
395+ galleryWidth ,
396+ galleryHeight ,
376397 sufficientSwipe ,
377398 canSlideLeft ,
378399 canSlideRight ,
@@ -399,7 +420,7 @@ const ImageGallery = forwardRef<ImageGalleryRef, ImageGalleryProps>(
399420
400421 const isFlick = slideVertically ? isTopDownFlick : isLeftRightFlick ;
401422
402- handleOnSwipedTo ( swipeDirection , isFlick ) ;
423+ handleOnSwipedTo ( swipeDirection , isFlick , velocity ) ;
403424 } ,
404425 [
405426 disableSwipe ,
0 commit comments