yet-another-react-lightbox 3.21.5 → 3.21.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +18 -6
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -839,7 +839,8 @@ function useWheelSwipe(swipeState, subscribeSensors, isSwipeValid, containerWidt
|
|
|
839
839
|
const intent = React.useRef(0);
|
|
840
840
|
const intentCleanup = React.useRef();
|
|
841
841
|
const resetCleanup = React.useRef();
|
|
842
|
-
const
|
|
842
|
+
const wheelInertia = React.useRef(0);
|
|
843
|
+
const wheelInertiaCleanup = React.useRef();
|
|
843
844
|
const startTime = React.useRef(0);
|
|
844
845
|
const { setTimeout, clearTimeout } = useTimeouts();
|
|
845
846
|
const cancelSwipeIntentCleanup = React.useCallback(() => {
|
|
@@ -876,9 +877,20 @@ function useWheelSwipe(swipeState, subscribeSensors, isSwipeValid, containerWidt
|
|
|
876
877
|
if (Math.abs(event.deltaY) > Math.abs(event.deltaX)) {
|
|
877
878
|
return;
|
|
878
879
|
}
|
|
880
|
+
const setWheelInertia = (inertia) => {
|
|
881
|
+
wheelInertia.current = inertia;
|
|
882
|
+
clearTimeout(wheelInertiaCleanup.current);
|
|
883
|
+
wheelInertiaCleanup.current =
|
|
884
|
+
inertia > 0
|
|
885
|
+
? setTimeout(() => {
|
|
886
|
+
wheelInertia.current = 0;
|
|
887
|
+
wheelInertiaCleanup.current = undefined;
|
|
888
|
+
}, 300)
|
|
889
|
+
: undefined;
|
|
890
|
+
};
|
|
879
891
|
if (swipeState === SwipeState.NONE) {
|
|
880
|
-
if (Math.abs(event.deltaX) <= 1.2 * Math.abs(
|
|
881
|
-
|
|
892
|
+
if (Math.abs(event.deltaX) <= 1.2 * Math.abs(wheelInertia.current)) {
|
|
893
|
+
setWheelInertia(event.deltaX);
|
|
882
894
|
return;
|
|
883
895
|
}
|
|
884
896
|
if (!isSwipeValid(-event.deltaX)) {
|
|
@@ -888,7 +900,7 @@ function useWheelSwipe(swipeState, subscribeSensors, isSwipeValid, containerWidt
|
|
|
888
900
|
cancelSwipeIntentCleanup();
|
|
889
901
|
if (Math.abs(intent.current) > 30) {
|
|
890
902
|
intent.current = 0;
|
|
891
|
-
|
|
903
|
+
setWheelInertia(0);
|
|
892
904
|
startTime.current = Date.now();
|
|
893
905
|
onSwipeStart();
|
|
894
906
|
}
|
|
@@ -909,14 +921,14 @@ function useWheelSwipe(swipeState, subscribeSensors, isSwipeValid, containerWidt
|
|
|
909
921
|
onSwipeProgress(newSwipeOffset);
|
|
910
922
|
cancelSwipeResetCleanup();
|
|
911
923
|
if (Math.abs(newSwipeOffset) > 0.2 * containerWidth) {
|
|
912
|
-
|
|
924
|
+
setWheelInertia(event.deltaX);
|
|
913
925
|
onSwipeFinish(newSwipeOffset, Date.now() - startTime.current);
|
|
914
926
|
return;
|
|
915
927
|
}
|
|
916
928
|
resetCleanup.current = setTimeout(() => handleCancelSwipe(newSwipeOffset), 2 * swipeAnimationDuration);
|
|
917
929
|
}
|
|
918
930
|
else {
|
|
919
|
-
|
|
931
|
+
setWheelInertia(event.deltaX);
|
|
920
932
|
}
|
|
921
933
|
});
|
|
922
934
|
React.useEffect(() => subscribeSensors(EVENT_ON_WHEEL, onWheel), [subscribeSensors, onWheel]);
|