etudes 7.0.0 → 7.0.1
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/components/Carousel.js +12 -1
- package/package.json +1 -1
package/components/Carousel.js
CHANGED
|
@@ -30,11 +30,20 @@ export const Carousel = forwardRef(({ autoAdvanceInterval = 0, index = 0, isDrag
|
|
|
30
30
|
pointerDownPositionRef.current = undefined;
|
|
31
31
|
pointerUpPositionRef.current = undefined;
|
|
32
32
|
};
|
|
33
|
-
const normalizeScrollPosition = () =>
|
|
33
|
+
const normalizeScrollPosition = () => {
|
|
34
|
+
scrollToIndex(viewportRef, index, orientation);
|
|
35
|
+
clearTimeout(autoScrollTimeoutRef.current);
|
|
36
|
+
autoScrollTimeoutRef.current = setTimeout(() => {
|
|
37
|
+
clearTimeout(autoScrollTimeoutRef.current);
|
|
38
|
+
autoScrollTimeoutRef.current = undefined;
|
|
39
|
+
}, autoScrollTimeoutMs);
|
|
40
|
+
};
|
|
34
41
|
const prevIndexRef = useRef(undefined);
|
|
35
42
|
const viewportRef = useRef(null);
|
|
36
43
|
const pointerDownPositionRef = useRef(undefined);
|
|
37
44
|
const pointerUpPositionRef = useRef(undefined);
|
|
45
|
+
const autoScrollTimeoutRef = useRef(undefined);
|
|
46
|
+
const autoScrollTimeoutMs = 1000;
|
|
38
47
|
const [exposures, setExposures] = useState(getItemExposures(viewportRef, orientation));
|
|
39
48
|
const [isPointerDown, setIsPointerDown] = useState(false);
|
|
40
49
|
const fixedStyles = getFixedStyles({ scrollSnapEnabled: !isPointerDown, orientation });
|
|
@@ -49,6 +58,8 @@ export const Carousel = forwardRef(({ autoAdvanceInterval = 0, index = 0, isDrag
|
|
|
49
58
|
if (tracksItemExposure) {
|
|
50
59
|
setExposures(getItemExposures(viewportRef, orientation));
|
|
51
60
|
}
|
|
61
|
+
if (autoScrollTimeoutRef.current !== undefined)
|
|
62
|
+
return;
|
|
52
63
|
const newIndex = orientation === 'horizontal'
|
|
53
64
|
? Math.round(viewport.scrollLeft / viewport.clientWidth)
|
|
54
65
|
: Math.round(viewport.scrollTop / viewport.clientHeight);
|