@fountain-ui/lab 2.0.0-beta.11 → 2.0.0-beta.12
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/build/commonjs/Carousel/Carousel.js +137 -0
- package/build/commonjs/Carousel/Carousel.js.map +1 -0
- package/build/commonjs/Carousel/CarouselProps.js.map +1 -1
- package/build/commonjs/Carousel/animation/animationUtils.js +9 -0
- package/build/commonjs/Carousel/animation/animationUtils.js.map +1 -0
- package/build/commonjs/Carousel/animation/createDefaultItemStyle.js +15 -0
- package/build/commonjs/Carousel/animation/createDefaultItemStyle.js.map +1 -0
- package/build/commonjs/Carousel/animation/createDefaultScrollAnimation.js +20 -0
- package/build/commonjs/Carousel/animation/createDefaultScrollAnimation.js.map +1 -0
- package/build/commonjs/Carousel/animation/index.js +40 -0
- package/build/commonjs/Carousel/animation/index.js.map +1 -0
- package/build/commonjs/Carousel/animation/normalItemStyleFactory.js +27 -0
- package/build/commonjs/Carousel/animation/normalItemStyleFactory.js.map +1 -0
- package/build/commonjs/Carousel/animation/parallaxItemStyleFactory.js +65 -0
- package/build/commonjs/Carousel/animation/parallaxItemStyleFactory.js.map +1 -0
- package/build/commonjs/Carousel/components/InternalContext.js +29 -0
- package/build/commonjs/Carousel/components/InternalContext.js.map +1 -0
- package/build/commonjs/Carousel/components/ItemView.js +64 -0
- package/build/commonjs/Carousel/components/ItemView.js.map +1 -0
- package/build/commonjs/Carousel/components/RootView.js +68 -0
- package/build/commonjs/Carousel/components/RootView.js.map +1 -0
- package/build/commonjs/Carousel/components/ScrollViewGesture.js +76 -0
- package/build/commonjs/Carousel/components/ScrollViewGesture.js.map +1 -0
- package/build/commonjs/Carousel/components/index.js +40 -0
- package/build/commonjs/Carousel/components/index.js.map +1 -0
- package/build/commonjs/Carousel/hooks/index.js +64 -0
- package/build/commonjs/Carousel/hooks/index.js.map +1 -0
- package/build/commonjs/Carousel/hooks/useAutoplayController.js +55 -0
- package/build/commonjs/Carousel/hooks/useAutoplayController.js.map +1 -0
- package/build/commonjs/Carousel/hooks/useDimensionChangeReaction.js +23 -0
- package/build/commonjs/Carousel/hooks/useDimensionChangeReaction.js.map +1 -0
- package/build/commonjs/Carousel/hooks/useIndexController.js +70 -0
- package/build/commonjs/Carousel/hooks/useIndexController.js.map +1 -0
- package/build/commonjs/Carousel/hooks/useItemInterpolation.js +63 -0
- package/build/commonjs/Carousel/hooks/useItemInterpolation.js.map +1 -0
- package/build/commonjs/Carousel/hooks/useItemVisibilityStore.js +95 -0
- package/build/commonjs/Carousel/hooks/useItemVisibilityStore.js.map +1 -0
- package/build/commonjs/Carousel/hooks/useLoopedData.js +33 -0
- package/build/commonjs/Carousel/hooks/useLoopedData.js.map +1 -0
- package/build/commonjs/Carousel/hooks/usePagingAnimation.js +124 -0
- package/build/commonjs/Carousel/hooks/usePagingAnimation.js.map +1 -0
- package/build/commonjs/Carousel/index.js +16 -2
- package/build/commonjs/Carousel/index.js.map +1 -1
- package/build/commonjs/Carousel/types.js +7 -0
- package/build/commonjs/Carousel/types.js.map +1 -0
- package/build/commonjs/ViewPager/ChildrenMemoizedPage.js +44 -47
- package/build/commonjs/ViewPager/ChildrenMemoizedPage.js.map +1 -1
- package/build/commonjs/ViewPager/PageStateContext.js +22 -0
- package/build/commonjs/ViewPager/PageStateContext.js.map +1 -0
- package/build/commonjs/ViewPager/ViewPagerNative.js +23 -10
- package/build/commonjs/ViewPager/ViewPagerNative.js.map +1 -1
- package/build/commonjs/ViewPager/ViewPagerProps.js.map +1 -1
- package/build/commonjs/ViewPager/ViewPagerWeb.js +9 -7
- package/build/commonjs/ViewPager/ViewPagerWeb.js.map +1 -1
- package/build/commonjs/ViewPager/index.js +8 -0
- package/build/commonjs/ViewPager/index.js.map +1 -1
- package/build/commonjs/ViewPager/index.native.js +8 -0
- package/build/commonjs/ViewPager/index.native.js.map +1 -1
- package/build/commonjs/ViewPager/utils.js +3 -1
- package/build/commonjs/ViewPager/utils.js.map +1 -1
- package/build/commonjs/ViewabilityTrackerView/Viewability.js +2 -0
- package/build/commonjs/ViewabilityTrackerView/Viewability.js.map +1 -0
- package/build/commonjs/ViewabilityTrackerView/ViewabilityTrackerView.js +45 -0
- package/build/commonjs/ViewabilityTrackerView/ViewabilityTrackerView.js.map +1 -0
- package/build/commonjs/ViewabilityTrackerView/ViewabilityTrackerViewProps.js +2 -0
- package/build/commonjs/ViewabilityTrackerView/ViewabilityTrackerViewProps.js.map +1 -0
- package/build/commonjs/{Carousel/index.native.js → ViewabilityTrackerView/index.js} +3 -3
- package/build/commonjs/ViewabilityTrackerView/index.js.map +1 -0
- package/build/commonjs/ViewabilityTrackerView/measureViewability.js +42 -0
- package/build/commonjs/ViewabilityTrackerView/measureViewability.js.map +1 -0
- package/build/commonjs/ViewabilityTrackerView/useViewabilityTracker.js +88 -0
- package/build/commonjs/ViewabilityTrackerView/useViewabilityTracker.js.map +1 -0
- package/build/commonjs/hooks/index.js +16 -0
- package/build/commonjs/hooks/index.js.map +1 -1
- package/build/commonjs/hooks/useDeferredExecutor.js +45 -0
- package/build/commonjs/hooks/useDeferredExecutor.js.map +1 -0
- package/build/commonjs/hooks/useIsMounted.js +22 -0
- package/build/commonjs/hooks/useIsMounted.js.map +1 -0
- package/build/commonjs/index.js +22 -1
- package/build/commonjs/index.js.map +1 -1
- package/build/module/Carousel/Carousel.js +115 -0
- package/build/module/Carousel/Carousel.js.map +1 -0
- package/build/module/Carousel/CarouselProps.js.map +1 -1
- package/build/module/Carousel/animation/animationUtils.js +2 -0
- package/build/module/Carousel/animation/animationUtils.js.map +1 -0
- package/build/module/Carousel/animation/createDefaultItemStyle.js +3 -0
- package/build/module/Carousel/animation/createDefaultItemStyle.js.map +1 -0
- package/build/module/Carousel/animation/createDefaultScrollAnimation.js +11 -0
- package/build/module/Carousel/animation/createDefaultScrollAnimation.js.map +1 -0
- package/build/module/Carousel/animation/index.js +5 -0
- package/build/module/Carousel/animation/index.js.map +1 -0
- package/build/module/Carousel/animation/normalItemStyleFactory.js +18 -0
- package/build/module/Carousel/animation/normalItemStyleFactory.js.map +1 -0
- package/build/module/Carousel/animation/parallaxItemStyleFactory.js +55 -0
- package/build/module/Carousel/animation/parallaxItemStyleFactory.js.map +1 -0
- package/build/module/Carousel/components/InternalContext.js +19 -0
- package/build/module/Carousel/components/InternalContext.js.map +1 -0
- package/build/module/Carousel/components/ItemView.js +44 -0
- package/build/module/Carousel/components/ItemView.js.map +1 -0
- package/build/module/Carousel/components/RootView.js +47 -0
- package/build/module/Carousel/components/RootView.js.map +1 -0
- package/build/module/Carousel/components/ScrollViewGesture.js +62 -0
- package/build/module/Carousel/components/ScrollViewGesture.js.map +1 -0
- package/build/module/Carousel/components/index.js +5 -0
- package/build/module/Carousel/components/index.js.map +1 -0
- package/build/module/Carousel/hooks/index.js +8 -0
- package/build/module/Carousel/hooks/index.js.map +1 -0
- package/build/module/Carousel/hooks/useAutoplayController.js +45 -0
- package/build/module/Carousel/hooks/useAutoplayController.js.map +1 -0
- package/build/module/Carousel/hooks/useDimensionChangeReaction.js +14 -0
- package/build/module/Carousel/hooks/useDimensionChangeReaction.js.map +1 -0
- package/build/module/Carousel/hooks/useIndexController.js +54 -0
- package/build/module/Carousel/hooks/useIndexController.js.map +1 -0
- package/build/module/Carousel/hooks/useItemInterpolation.js +51 -0
- package/build/module/Carousel/hooks/useItemInterpolation.js.map +1 -0
- package/build/module/Carousel/hooks/useItemVisibilityStore.js +87 -0
- package/build/module/Carousel/hooks/useItemVisibilityStore.js.map +1 -0
- package/build/module/Carousel/hooks/useLoopedData.js +24 -0
- package/build/module/Carousel/hooks/useLoopedData.js.map +1 -0
- package/build/module/Carousel/hooks/usePagingAnimation.js +115 -0
- package/build/module/Carousel/hooks/usePagingAnimation.js.map +1 -0
- package/build/module/Carousel/index.js +2 -1
- package/build/module/Carousel/index.js.map +1 -1
- package/build/module/Carousel/types.js +3 -0
- package/build/module/Carousel/types.js.map +1 -0
- package/build/module/ViewPager/ChildrenMemoizedPage.js +40 -45
- package/build/module/ViewPager/ChildrenMemoizedPage.js.map +1 -1
- package/build/module/ViewPager/PageStateContext.js +10 -0
- package/build/module/ViewPager/PageStateContext.js.map +1 -0
- package/build/module/ViewPager/ViewPagerNative.js +26 -13
- package/build/module/ViewPager/ViewPagerNative.js.map +1 -1
- package/build/module/ViewPager/ViewPagerProps.js.map +1 -1
- package/build/module/ViewPager/ViewPagerWeb.js +10 -8
- package/build/module/ViewPager/ViewPagerWeb.js.map +1 -1
- package/build/module/ViewPager/index.js +1 -0
- package/build/module/ViewPager/index.js.map +1 -1
- package/build/module/ViewPager/index.native.js +1 -0
- package/build/module/ViewPager/index.native.js.map +1 -1
- package/build/module/ViewPager/utils.js +1 -0
- package/build/module/ViewPager/utils.js.map +1 -1
- package/build/module/ViewabilityTrackerView/Viewability.js +2 -0
- package/build/module/ViewabilityTrackerView/Viewability.js.map +1 -0
- package/build/module/ViewabilityTrackerView/ViewabilityTrackerView.js +28 -0
- package/build/module/ViewabilityTrackerView/ViewabilityTrackerView.js.map +1 -0
- package/build/module/ViewabilityTrackerView/ViewabilityTrackerViewProps.js +2 -0
- package/build/module/ViewabilityTrackerView/ViewabilityTrackerViewProps.js.map +1 -0
- package/build/module/ViewabilityTrackerView/index.js +2 -0
- package/build/module/ViewabilityTrackerView/index.js.map +1 -0
- package/build/module/ViewabilityTrackerView/measureViewability.js +34 -0
- package/build/module/ViewabilityTrackerView/measureViewability.js.map +1 -0
- package/build/module/ViewabilityTrackerView/useViewabilityTracker.js +73 -0
- package/build/module/ViewabilityTrackerView/useViewabilityTracker.js.map +1 -0
- package/build/module/hooks/index.js +2 -0
- package/build/module/hooks/index.js.map +1 -1
- package/build/module/hooks/useDeferredExecutor.js +33 -0
- package/build/module/hooks/useDeferredExecutor.js.map +1 -0
- package/build/module/hooks/useIsMounted.js +13 -0
- package/build/module/hooks/useIsMounted.js.map +1 -0
- package/build/module/index.js +2 -0
- package/build/module/index.js.map +1 -1
- package/build/typescript/Carousel/Carousel.d.ts +5 -0
- package/build/typescript/Carousel/CarouselProps.d.ts +32 -48
- package/build/typescript/Carousel/animation/animationUtils.d.ts +1 -0
- package/build/typescript/Carousel/animation/createDefaultItemStyle.d.ts +2 -0
- package/build/typescript/Carousel/animation/createDefaultScrollAnimation.d.ts +2 -0
- package/build/typescript/Carousel/animation/index.d.ts +4 -0
- package/build/typescript/Carousel/animation/normalItemStyleFactory.d.ts +2 -0
- package/build/typescript/Carousel/animation/parallaxItemStyleFactory.d.ts +9 -0
- package/build/typescript/Carousel/components/InternalContext.d.ts +14 -0
- package/build/typescript/Carousel/components/ItemView.d.ts +7 -0
- package/build/typescript/Carousel/components/RootView.d.ts +16 -0
- package/build/typescript/Carousel/components/ScrollViewGesture.d.ts +12 -0
- package/build/typescript/Carousel/components/index.d.ts +4 -0
- package/build/typescript/Carousel/hooks/index.d.ts +7 -0
- package/build/typescript/Carousel/hooks/useAutoplayController.d.ts +7 -0
- package/build/typescript/Carousel/hooks/useDimensionChangeReaction.d.ts +7 -0
- package/build/typescript/Carousel/hooks/useIndexController.d.ts +10 -0
- package/build/typescript/Carousel/hooks/useItemInterpolation.d.ts +2 -0
- package/build/typescript/Carousel/hooks/useItemVisibilityStore.d.ts +7 -0
- package/build/typescript/Carousel/hooks/useLoopedData.d.ts +1 -0
- package/build/typescript/Carousel/hooks/usePagingAnimation.d.ts +18 -0
- package/build/typescript/Carousel/index.d.ts +3 -1
- package/build/typescript/Carousel/types.d.ts +57 -0
- package/build/typescript/ViewPager/PageStateContext.d.ts +7 -0
- package/build/typescript/ViewPager/ViewPagerNative.d.ts +1 -1
- package/build/typescript/ViewPager/ViewPagerProps.d.ts +11 -0
- package/build/typescript/ViewPager/ViewPagerWeb.d.ts +1 -1
- package/build/typescript/ViewPager/index.d.ts +1 -0
- package/build/typescript/ViewPager/index.native.d.ts +1 -0
- package/build/typescript/ViewPager/utils.d.ts +1 -0
- package/build/typescript/ViewabilityTrackerView/Viewability.d.ts +3 -0
- package/build/typescript/ViewabilityTrackerView/ViewabilityTrackerView.d.ts +2 -0
- package/build/typescript/ViewabilityTrackerView/ViewabilityTrackerViewProps.d.ts +22 -0
- package/build/typescript/ViewabilityTrackerView/index.d.ts +2 -0
- package/build/typescript/ViewabilityTrackerView/measureViewability.d.ts +11 -0
- package/build/typescript/ViewabilityTrackerView/useViewabilityTracker.d.ts +11 -0
- package/build/typescript/hooks/index.d.ts +2 -0
- package/build/typescript/hooks/useDeferredExecutor.d.ts +11 -0
- package/build/typescript/hooks/useIsMounted.d.ts +4 -0
- package/build/typescript/index.d.ts +2 -0
- package/package.json +4 -19
- package/src/Carousel/Carousel.tsx +151 -0
- package/src/Carousel/CarouselProps.ts +34 -53
- package/src/Carousel/animation/animationUtils.ts +1 -0
- package/src/Carousel/animation/createDefaultItemStyle.ts +3 -0
- package/src/Carousel/animation/createDefaultScrollAnimation.ts +13 -0
- package/src/Carousel/animation/index.ts +4 -0
- package/src/Carousel/animation/normalItemStyleFactory.ts +19 -0
- package/src/Carousel/animation/parallaxItemStyleFactory.ts +79 -0
- package/src/Carousel/components/InternalContext.ts +33 -0
- package/src/Carousel/components/ItemView.tsx +56 -0
- package/src/Carousel/components/RootView.tsx +66 -0
- package/src/Carousel/components/ScrollViewGesture.tsx +80 -0
- package/src/Carousel/components/index.ts +4 -0
- package/src/Carousel/hooks/index.ts +7 -0
- package/src/Carousel/hooks/useAutoplayController.ts +54 -0
- package/src/Carousel/hooks/useDimensionChangeReaction.ts +25 -0
- package/src/Carousel/hooks/useIndexController.tsx +76 -0
- package/src/Carousel/hooks/useItemInterpolation.ts +107 -0
- package/src/Carousel/hooks/useItemVisibilityStore.ts +107 -0
- package/src/Carousel/hooks/useLoopedData.ts +26 -0
- package/src/Carousel/hooks/usePagingAnimation.ts +148 -0
- package/src/Carousel/index.ts +4 -2
- package/src/Carousel/types.ts +67 -0
- package/src/ViewPager/ChildrenMemoizedPage.tsx +48 -43
- package/src/ViewPager/PageStateContext.ts +15 -0
- package/src/ViewPager/ViewPagerNative.tsx +35 -11
- package/src/ViewPager/ViewPagerProps.ts +13 -0
- package/src/ViewPager/ViewPagerWeb.tsx +9 -5
- package/src/ViewPager/index.native.ts +1 -0
- package/src/ViewPager/index.ts +1 -0
- package/src/ViewPager/utils.tsx +2 -1
- package/src/ViewabilityTrackerView/Viewability.ts +3 -0
- package/src/ViewabilityTrackerView/ViewabilityTrackerView.tsx +33 -0
- package/src/ViewabilityTrackerView/ViewabilityTrackerViewProps.ts +25 -0
- package/src/ViewabilityTrackerView/index.ts +2 -0
- package/src/ViewabilityTrackerView/measureViewability.ts +56 -0
- package/src/ViewabilityTrackerView/useViewabilityTracker.ts +85 -0
- package/src/hooks/index.ts +2 -0
- package/src/hooks/useDeferredExecutor.ts +46 -0
- package/src/hooks/useIsMounted.ts +19 -0
- package/src/index.ts +3 -0
- package/build/commonjs/Carousel/CarouselNative.js +0 -72
- package/build/commonjs/Carousel/CarouselNative.js.map +0 -1
- package/build/commonjs/Carousel/CarouselWeb.js +0 -237
- package/build/commonjs/Carousel/CarouselWeb.js.map +0 -1
- package/build/commonjs/Carousel/index.native.js.map +0 -1
- package/build/commonjs/Carousel/utils.js +0 -19
- package/build/commonjs/Carousel/utils.js.map +0 -1
- package/build/module/Carousel/CarouselNative.js +0 -54
- package/build/module/Carousel/CarouselNative.js.map +0 -1
- package/build/module/Carousel/CarouselWeb.js +0 -215
- package/build/module/Carousel/CarouselWeb.js.map +0 -1
- package/build/module/Carousel/index.native.js +0 -2
- package/build/module/Carousel/index.native.js.map +0 -1
- package/build/module/Carousel/utils.js +0 -7
- package/build/module/Carousel/utils.js.map +0 -1
- package/build/typescript/Carousel/CarouselNative.d.ts +0 -2
- package/build/typescript/Carousel/CarouselWeb.d.ts +0 -4
- package/build/typescript/Carousel/index.native.d.ts +0 -1
- package/build/typescript/Carousel/utils.d.ts +0 -6
- package/src/Carousel/CarouselNative.tsx +0 -67
- package/src/Carousel/CarouselWeb.tsx +0 -222
- package/src/Carousel/index.native.ts +0 -1
- package/src/Carousel/utils.ts +0 -11
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = usePagingAnimation;
|
|
7
|
+
|
|
8
|
+
var _react = require("react");
|
|
9
|
+
|
|
10
|
+
var _reactNative = require("react-native");
|
|
11
|
+
|
|
12
|
+
function directionToValue(itemWidth) {
|
|
13
|
+
return function (direction) {
|
|
14
|
+
switch (direction) {
|
|
15
|
+
case 'next':
|
|
16
|
+
return -itemWidth;
|
|
17
|
+
|
|
18
|
+
case 'prev':
|
|
19
|
+
return itemWidth;
|
|
20
|
+
|
|
21
|
+
case 'stay':
|
|
22
|
+
return 0;
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function usePagingAnimation(config) {
|
|
28
|
+
const {
|
|
29
|
+
controlledTx,
|
|
30
|
+
createScrollAnimation,
|
|
31
|
+
getCurrentIndex,
|
|
32
|
+
itemWidth,
|
|
33
|
+
lastIndex,
|
|
34
|
+
loop,
|
|
35
|
+
numberOfData,
|
|
36
|
+
offsetTx
|
|
37
|
+
} = config;
|
|
38
|
+
const animationRef = (0, _react.useRef)(null);
|
|
39
|
+
const toValueRef = (0, _react.useRef)(0);
|
|
40
|
+
const globalInterpolation = (0, _react.useMemo)(() => _reactNative.Animated.add(controlledTx, offsetTx), [controlledTx, offsetTx]);
|
|
41
|
+
(0, _react.useEffect)(() => {
|
|
42
|
+
const subscriptionId = controlledTx.addListener(value => {
|
|
43
|
+
const currentTx = value.value; // Prevent infinite loop
|
|
44
|
+
|
|
45
|
+
if (currentTx !== 0) {
|
|
46
|
+
const maxWidth = numberOfData * itemWidth;
|
|
47
|
+
|
|
48
|
+
if (Math.abs(Math.round(currentTx)) === Math.round(maxWidth)) {
|
|
49
|
+
// reset position
|
|
50
|
+
controlledTx.setValue(0);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
return () => {
|
|
55
|
+
controlledTx.removeListener(subscriptionId);
|
|
56
|
+
};
|
|
57
|
+
}, [numberOfData, itemWidth]);
|
|
58
|
+
const finalizeAnimation = (0, _react.useCallback)(() => {
|
|
59
|
+
const stopUnfinishedSnapAnimation = () => {
|
|
60
|
+
if (animationRef.current) {
|
|
61
|
+
var _animationRef$current;
|
|
62
|
+
|
|
63
|
+
(_animationRef$current = animationRef.current) === null || _animationRef$current === void 0 ? void 0 : _animationRef$current.stop();
|
|
64
|
+
animationRef.current = null;
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
const resetBoundary = () => {
|
|
69
|
+
controlledTx.setOffset(toValueRef.current);
|
|
70
|
+
controlledTx.flattenOffset(); // FIXME: react-native-web bug maybe?
|
|
71
|
+
// `AnimatedValue.flattenOffset()` does not trigger any event listener.
|
|
72
|
+
// Accessing value directly via `_value` is dangerous but working on web (`useNativeDriver` always false).
|
|
73
|
+
// So setting same value with `value.setValue(value._value)` will trigger event listener.
|
|
74
|
+
|
|
75
|
+
if (_reactNative.Platform.OS === 'web') {
|
|
76
|
+
// @ts-ignore
|
|
77
|
+
controlledTx.setValue(controlledTx._value);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
offsetTx.setValue(0);
|
|
81
|
+
toValueRef.current = 0;
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
stopUnfinishedSnapAnimation();
|
|
85
|
+
resetBoundary();
|
|
86
|
+
}, [controlledTx]);
|
|
87
|
+
const startAnimation = (0, _react.useCallback)(function (direction) {
|
|
88
|
+
let isGesture = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
89
|
+
const getToValueByDirection = directionToValue(itemWidth);
|
|
90
|
+
const currentIndex = getCurrentIndex();
|
|
91
|
+
|
|
92
|
+
const computeToValueOnNoLoop = () => {
|
|
93
|
+
if (currentIndex === 0 && direction === 'prev') {
|
|
94
|
+
return isGesture ? getToValueByDirection('stay') : -lastIndex * itemWidth; // last position
|
|
95
|
+
} else if (currentIndex === lastIndex && direction === 'next') {
|
|
96
|
+
return isGesture ? getToValueByDirection('stay') : lastIndex * itemWidth; // first position
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
return getToValueByDirection(direction);
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
const toValue = loop ? getToValueByDirection(direction) : computeToValueOnNoLoop();
|
|
103
|
+
const animation = createScrollAnimation(offsetTx, toValue);
|
|
104
|
+
animationRef.current = animation;
|
|
105
|
+
toValueRef.current = toValue;
|
|
106
|
+
animation.start(_ref => {
|
|
107
|
+
let {
|
|
108
|
+
finished
|
|
109
|
+
} = _ref;
|
|
110
|
+
|
|
111
|
+
if (finished) {
|
|
112
|
+
finalizeAnimation();
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
}, [createScrollAnimation, getCurrentIndex, finalizeAnimation, itemWidth, lastIndex, loop]);
|
|
116
|
+
return {
|
|
117
|
+
globalInterpolation,
|
|
118
|
+
finalizeAnimation,
|
|
119
|
+
startAnimation
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
;
|
|
124
|
+
//# sourceMappingURL=usePagingAnimation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["directionToValue","itemWidth","direction","usePagingAnimation","config","controlledTx","createScrollAnimation","getCurrentIndex","lastIndex","loop","numberOfData","offsetTx","animationRef","useRef","toValueRef","globalInterpolation","useMemo","Animated","add","useEffect","subscriptionId","addListener","value","currentTx","maxWidth","Math","abs","round","setValue","removeListener","finalizeAnimation","useCallback","stopUnfinishedSnapAnimation","current","stop","resetBoundary","setOffset","flattenOffset","Platform","OS","_value","startAnimation","isGesture","getToValueByDirection","currentIndex","computeToValueOnNoLoop","toValue","animation","start","finished"],"sources":["usePagingAnimation.ts"],"sourcesContent":["import { useCallback, useEffect, useMemo, useRef } from 'react';\nimport { Animated, Platform } from 'react-native';\nimport type { CreateScrollAnimation, GetCurrentIndex, PagingDirection, StartPagingAnimation } from '../types';\n\nexport interface PagingAnimationConfig {\n controlledTx: Animated.Value;\n createScrollAnimation: CreateScrollAnimation;\n getCurrentIndex: GetCurrentIndex;\n itemWidth: number;\n lastIndex: number;\n loop: boolean;\n numberOfData: number;\n offsetTx: Animated.Value;\n}\n\nexport interface UsePagingAnimation {\n finalizeAnimation: () => void;\n globalInterpolation: Animated.AnimatedInterpolation;\n startAnimation: StartPagingAnimation;\n}\n\nfunction directionToValue(itemWidth: number) {\n return function (direction: PagingDirection): number {\n switch (direction) {\n case 'next':\n return -itemWidth;\n case 'prev':\n return itemWidth;\n case 'stay':\n return 0;\n }\n };\n}\n\nexport default function usePagingAnimation(config: PagingAnimationConfig): UsePagingAnimation {\n const {\n controlledTx,\n createScrollAnimation,\n getCurrentIndex,\n itemWidth,\n lastIndex,\n loop,\n numberOfData,\n offsetTx,\n } = config;\n\n const animationRef = useRef<Animated.CompositeAnimation | null>(null);\n const toValueRef = useRef<number>(0);\n\n const globalInterpolation = useMemo(\n () => Animated.add(controlledTx, offsetTx),\n [controlledTx, offsetTx],\n );\n\n useEffect(() => {\n const subscriptionId = controlledTx.addListener((value) => {\n const currentTx = value.value;\n\n // Prevent infinite loop\n if (currentTx !== 0) {\n const maxWidth = numberOfData * itemWidth;\n\n if (Math.abs(Math.round(currentTx)) === Math.round(maxWidth)) {\n // reset position\n controlledTx.setValue(0);\n }\n }\n });\n\n return () => {\n controlledTx.removeListener(subscriptionId);\n };\n }, [numberOfData, itemWidth]);\n\n const finalizeAnimation = useCallback(() => {\n const stopUnfinishedSnapAnimation = () => {\n if (animationRef.current) {\n animationRef.current?.stop();\n animationRef.current = null;\n }\n };\n\n const resetBoundary = () => {\n controlledTx.setOffset(toValueRef.current);\n controlledTx.flattenOffset();\n\n // FIXME: react-native-web bug maybe?\n // `AnimatedValue.flattenOffset()` does not trigger any event listener.\n // Accessing value directly via `_value` is dangerous but working on web (`useNativeDriver` always false).\n // So setting same value with `value.setValue(value._value)` will trigger event listener.\n if (Platform.OS === 'web') {\n // @ts-ignore\n controlledTx.setValue(controlledTx._value);\n }\n\n offsetTx.setValue(0);\n toValueRef.current = 0;\n };\n\n stopUnfinishedSnapAnimation();\n\n resetBoundary();\n }, [controlledTx]);\n\n const startAnimation = useCallback((direction: PagingDirection, isGesture: boolean = false) => {\n const getToValueByDirection = directionToValue(itemWidth);\n\n const currentIndex = getCurrentIndex();\n\n const computeToValueOnNoLoop = (): number => {\n if (currentIndex === 0 && direction === 'prev') {\n return isGesture\n ? getToValueByDirection('stay')\n : -lastIndex * itemWidth; // last position\n } else if (currentIndex === lastIndex && direction === 'next') {\n return isGesture\n ? getToValueByDirection('stay')\n : lastIndex * itemWidth; // first position\n }\n return getToValueByDirection(direction);\n };\n\n const toValue = loop ? getToValueByDirection(direction) : computeToValueOnNoLoop();\n const animation = createScrollAnimation(offsetTx, toValue);\n\n animationRef.current = animation;\n toValueRef.current = toValue;\n\n animation.start(({ finished }) => {\n if (finished) {\n finalizeAnimation();\n }\n });\n }, [\n createScrollAnimation,\n getCurrentIndex,\n finalizeAnimation,\n itemWidth,\n lastIndex,\n loop,\n ]);\n\n return {\n globalInterpolation,\n finalizeAnimation,\n startAnimation,\n };\n};\n"],"mappings":";;;;;;;AAAA;;AACA;;AAoBA,SAASA,gBAAT,CAA0BC,SAA1B,EAA6C;EACzC,OAAO,UAAUC,SAAV,EAA8C;IACjD,QAAQA,SAAR;MACI,KAAK,MAAL;QACI,OAAO,CAACD,SAAR;;MACJ,KAAK,MAAL;QACI,OAAOA,SAAP;;MACJ,KAAK,MAAL;QACI,OAAO,CAAP;IANR;EAQH,CATD;AAUH;;AAEc,SAASE,kBAAT,CAA4BC,MAA5B,EAA+E;EAC1F,MAAM;IACFC,YADE;IAEFC,qBAFE;IAGFC,eAHE;IAIFN,SAJE;IAKFO,SALE;IAMFC,IANE;IAOFC,YAPE;IAQFC;EARE,IASFP,MATJ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V,CAAgB,QAAkB;MAAA,IAAjB;QAAEC;MAAF,CAAiB;;MAC9B,IAAIA,QAAJ,EAAc;QACVnB,iBAAiB;MACpB;IACJ,CAJD;EAKH,CA7BsB,EA6BpB,CACCxB,qBADD,EAECC,eAFD,EAGCuB,iBAHD,EAIC7B,SAJD,EAKCO,SALD,EAMCC,IAND,CA7BoB,CAAvB;EAsCA,OAAO;IACHM,mBADG;IAEHe,iBAFG;IAGHW;EAHG,CAAP;AAKH;;AAAA"}
|
|
@@ -6,11 +6,25 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
Object.defineProperty(exports, "default", {
|
|
7
7
|
enumerable: true,
|
|
8
8
|
get: function () {
|
|
9
|
-
return
|
|
9
|
+
return _Carousel.default;
|
|
10
10
|
}
|
|
11
11
|
});
|
|
12
|
+
Object.defineProperty(exports, "normalItemStyleFactory", {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function () {
|
|
15
|
+
return _animation.normalItemStyleFactory;
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
Object.defineProperty(exports, "parallaxItemStyleFactory", {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
get: function () {
|
|
21
|
+
return _animation.parallaxItemStyleFactory;
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
var _Carousel = _interopRequireDefault(require("./Carousel"));
|
|
12
26
|
|
|
13
|
-
var
|
|
27
|
+
var _animation = require("./animation");
|
|
14
28
|
|
|
15
29
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
16
30
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export { default } from './
|
|
1
|
+
{"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export { default } from './Carousel';\nexport type { default as CarouselProps } from './CarouselProps';\nexport type { CarouselInstance } from './types';\nexport { normalItemStyleFactory, parallaxItemStyleFactory } from './animation';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAAA;;AAGA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["directions"],"sources":["types.ts"],"sourcesContent":["import type { ReactElement } from 'react';\nimport type { Animated, ViewProps } from 'react-native';\n\nconst directions = ['next', 'prev', 'stay'] as const;\n\nexport type PagingDirection = (typeof directions)[number];\n\nexport interface RenderItem<T> {\n (info: { item: T, index: number, interpolation: Animated.AnimatedInterpolation }): ReactElement | null;\n}\n\nexport interface CreateScrollAnimation {\n (aValue: Animated.AnimatedValue, toValue: number): Animated.CompositeAnimation;\n}\n\nexport interface CreateItemStyle {\n (itemInterpolation: Animated.AnimatedInterpolation, itemWidth: number): Animated.AnimatedProps<ViewProps['style']>;\n}\n\nexport interface GetCurrentIndex {\n (): number;\n}\n\nexport interface IndexController {\n currentIndex: number;\n getCurrentIndex: GetCurrentIndex;\n lastIndex: number;\n monitorElement: ReactElement;\n}\n\nexport interface StartPagingAnimation {\n (direction: PagingDirection, isGesture?: boolean): void;\n}\n\nexport type VisibleIndexRanges = Array<[number, number]>;\n\nexport interface StoreSubscription {\n (): void;\n}\n\nexport interface ItemVisibilityStore {\n dispatch: (ranges: VisibleIndexRanges) => void;\n subscribe: (listener: (ranges: VisibleIndexRanges) => void) => StoreSubscription;\n removeAllListeners: () => void;\n}\n\nexport interface AutoplayController {\n pause: () => void;\n resume: () => void;\n}\n\nexport interface CarouselInstance {\n /**\n * Scroll to next visible item.\n */\n next: () => void;\n\n /**\n * Scroll to previous visible item.\n */\n prev: () => void;\n\n /**\n * Get current visible item index.\n */\n getCurrentIndex: GetCurrentIndex;\n}\n"],"mappings":";;;;;AAGA,MAAMA,UAAU,GAAG,CAAC,MAAD,EAAS,MAAT,EAAiB,MAAjB,CAAnB"}
|
|
@@ -13,13 +13,19 @@ var _reactNativeReanimated = require("react-native-reanimated");
|
|
|
13
13
|
|
|
14
14
|
var _core = require("@fountain-ui/core");
|
|
15
15
|
|
|
16
|
+
var _PageStateContext = _interopRequireDefault(require("./PageStateContext"));
|
|
17
|
+
|
|
18
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
19
|
+
|
|
16
20
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
17
21
|
|
|
18
22
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
19
23
|
|
|
20
|
-
const OFFSCREEN_RERENDER_LIMIT = 1;
|
|
21
|
-
|
|
22
24
|
const styles = _core.StyleSheet.create({
|
|
25
|
+
fill: {
|
|
26
|
+
width: '100%',
|
|
27
|
+
height: '100%'
|
|
28
|
+
},
|
|
23
29
|
none: {
|
|
24
30
|
display: 'none'
|
|
25
31
|
}
|
|
@@ -30,79 +36,70 @@ function Page(props) {
|
|
|
30
36
|
index,
|
|
31
37
|
children,
|
|
32
38
|
loading,
|
|
39
|
+
offscreenPageRerenderLimit,
|
|
33
40
|
sharedIndex
|
|
34
41
|
} = props;
|
|
35
42
|
|
|
36
43
|
const assumeInitialPageState = () => {
|
|
37
44
|
const activeIndex = sharedIndex.value;
|
|
38
|
-
const
|
|
39
|
-
|
|
40
|
-
if (_reactNative.Platform.OS === 'web') {
|
|
41
|
-
return {
|
|
42
|
-
active,
|
|
43
|
-
visited: active
|
|
44
|
-
};
|
|
45
|
-
}
|
|
45
|
+
const isActive = index === activeIndex;
|
|
46
46
|
|
|
47
47
|
if (loading === 'eager') {
|
|
48
48
|
return {
|
|
49
|
-
|
|
50
|
-
|
|
49
|
+
isActive,
|
|
50
|
+
isLoaded: true
|
|
51
51
|
};
|
|
52
52
|
}
|
|
53
53
|
|
|
54
|
-
const
|
|
54
|
+
const isLoaded = index >= activeIndex - offscreenPageRerenderLimit && index <= activeIndex + offscreenPageRerenderLimit;
|
|
55
55
|
return {
|
|
56
|
-
|
|
57
|
-
|
|
56
|
+
isActive,
|
|
57
|
+
isLoaded
|
|
58
58
|
};
|
|
59
59
|
};
|
|
60
60
|
|
|
61
61
|
const [pageState, setPageState] = (0, _react.useState)(assumeInitialPageState);
|
|
62
|
-
const content = pageState.
|
|
63
|
-
|
|
64
|
-
const
|
|
65
|
-
setPageState(prevState => {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
visited: true
|
|
76
|
-
};
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
return prevState;
|
|
80
|
-
});
|
|
62
|
+
const content = pageState.isLoaded ? children : null;
|
|
63
|
+
|
|
64
|
+
const onActiveStateChange = isActive => {
|
|
65
|
+
setPageState(prevState => ({ ...prevState,
|
|
66
|
+
isActive,
|
|
67
|
+
isLoaded: isActive || prevState.isLoaded
|
|
68
|
+
}));
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
const onBecomeNeighbor = () => {
|
|
72
|
+
setPageState(prevState => ({ ...prevState,
|
|
73
|
+
isLoaded: true
|
|
74
|
+
}));
|
|
81
75
|
};
|
|
82
76
|
|
|
83
77
|
(0, _reactNativeReanimated.useAnimatedReaction)(() => {
|
|
84
78
|
const activeIndex = sharedIndex.value;
|
|
85
|
-
const
|
|
86
|
-
const
|
|
87
|
-
const
|
|
79
|
+
const isActive = index === activeIndex;
|
|
80
|
+
const shouldRerender = index >= activeIndex - offscreenPageRerenderLimit && index <= activeIndex + offscreenPageRerenderLimit;
|
|
81
|
+
const becomeNeighbor = shouldRerender && !isActive;
|
|
88
82
|
return {
|
|
89
|
-
|
|
90
|
-
|
|
83
|
+
isActive,
|
|
84
|
+
becomeNeighbor
|
|
91
85
|
};
|
|
92
86
|
}, (nextState, prevState) => {
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
(0, _reactNativeReanimated.runOnJS)(updatePageState)(nextState.willActive, nextState.willNeighbor);
|
|
87
|
+
if (nextState.isActive !== (prevState === null || prevState === void 0 ? void 0 : prevState.isActive)) {
|
|
88
|
+
(0, _reactNativeReanimated.runOnJS)(onActiveStateChange)(nextState.isActive);
|
|
89
|
+
} else if (nextState.becomeNeighbor) {
|
|
90
|
+
(0, _reactNativeReanimated.runOnJS)(onBecomeNeighbor)();
|
|
98
91
|
}
|
|
99
92
|
}, [index]);
|
|
100
|
-
const
|
|
93
|
+
const contextValue = (0, _react.useMemo)(() => ({
|
|
94
|
+
isActive: pageState.isActive
|
|
95
|
+
}), [pageState.isActive]);
|
|
96
|
+
const style = _reactNative.Platform.OS === 'web' ? pageState.isActive ? _core.StyleSheet.absoluteFill : styles.none : styles.fill;
|
|
101
97
|
return /*#__PURE__*/_react.default.createElement(_reactNative.View, {
|
|
102
|
-
children: content,
|
|
103
98
|
collapsable: false,
|
|
104
99
|
style: style
|
|
105
|
-
}
|
|
100
|
+
}, /*#__PURE__*/_react.default.createElement(_PageStateContext.default.Provider, {
|
|
101
|
+
value: contextValue
|
|
102
|
+
}, content));
|
|
106
103
|
}
|
|
107
104
|
|
|
108
105
|
var _default = /*#__PURE__*/(0, _react.memo)(Page, (prevProps, nextProps) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["styles","StyleSheet","create","fill","width","height","none","display","Page","props","index","children","loading","offscreenPageRerenderLimit","sharedIndex","assumeInitialPageState","activeIndex","value","isActive","isLoaded","pageState","setPageState","useState","content","onActiveStateChange","prevState","onBecomeNeighbor","useAnimatedReaction","shouldRerender","becomeNeighbor","nextState","runOnJS","contextValue","useMemo","style","Platform","OS","absoluteFill","memo","prevProps","nextProps","rerenderKey"],"sources":["ChildrenMemoizedPage.tsx"],"sourcesContent":["import React, { memo, useMemo, useState } from 'react';\nimport { Platform, View } from 'react-native';\nimport { runOnJS, useAnimatedReaction } from 'react-native-reanimated';\nimport { StyleSheet } from '@fountain-ui/core';\nimport type { PageProps } from './ViewPagerProps';\nimport PageStateContext from './PageStateContext';\n\nconst styles = StyleSheet.create({\n fill: { width: '100%', height: '100%' },\n none: { display: 'none' },\n});\n\ninterface InternalPageState {\n isActive: boolean;\n isLoaded: boolean;\n}\n\nfunction Page(props: PageProps) {\n const {\n index,\n children,\n loading,\n offscreenPageRerenderLimit,\n sharedIndex,\n } = props;\n\n const assumeInitialPageState = (): InternalPageState => {\n const activeIndex = sharedIndex.value;\n\n const isActive = index === activeIndex;\n\n if (loading === 'eager') {\n return { isActive, isLoaded: true };\n }\n\n const isLoaded = index >= activeIndex - offscreenPageRerenderLimit\n && index <= activeIndex + offscreenPageRerenderLimit;\n\n return { isActive, isLoaded };\n };\n\n const [pageState, setPageState] = useState<InternalPageState>(assumeInitialPageState);\n\n const content = pageState.isLoaded ? children : null;\n\n const onActiveStateChange = (isActive: boolean) => {\n setPageState(prevState => ({\n ...prevState,\n isActive,\n isLoaded: isActive || prevState.isLoaded,\n }));\n };\n\n const onBecomeNeighbor = () => {\n setPageState(prevState => ({\n ...prevState,\n isLoaded: true,\n }));\n };\n\n useAnimatedReaction(\n () => {\n const activeIndex = sharedIndex.value;\n\n const isActive = index === activeIndex;\n\n const shouldRerender = index >= activeIndex - offscreenPageRerenderLimit\n && index <= activeIndex + offscreenPageRerenderLimit;\n\n const becomeNeighbor = shouldRerender && !isActive;\n\n return { isActive, becomeNeighbor };\n },\n (nextState, prevState) => {\n if (nextState.isActive !== prevState?.isActive) {\n runOnJS(onActiveStateChange)(nextState.isActive);\n } else if (nextState.becomeNeighbor) {\n runOnJS(onBecomeNeighbor)();\n }\n },\n [index],\n );\n\n const contextValue = useMemo(() => ({\n isActive: pageState.isActive,\n }), [pageState.isActive]);\n\n const style = Platform.OS === 'web'\n ? (pageState.isActive ? StyleSheet.absoluteFill : styles.none)\n : styles.fill;\n\n return (\n <View\n collapsable={false}\n style={style}\n >\n <PageStateContext.Provider value={contextValue}>\n {content}\n </PageStateContext.Provider>\n </View>\n );\n}\n\nexport default memo(Page, (prevProps, nextProps) => {\n if (prevProps.rerenderKey !== nextProps.rerenderKey) {\n return false;\n }\n\n return prevProps.index !== nextProps.index;\n});\n"],"mappings":";;;;;;;AAAA;;AACA;;AACA;;AACA;;AAEA;;;;;;;;AAEA,MAAMA,MAAM,GAAGC,gBAAA,CAAWC,MAAX,CAAkB;EAC7BC,IAAI,EAAE;IAAEC,KAAK,EAAE,MAAT;IAAiBC,MAAM,EAAE;EAAzB,CADuB;EAE7BC,IAAI,EAAE;IAAEC,OAAO,EAAE;EAAX;AAFuB,CAAlB,CAAf;;AAUA,SAASC,IAAT,CAAcC,KAAd,EAAgC;EAC5B,MAAM;IACFC,KADE;IAEFC,QAFE;IAGFC,OAHE;IAIFC,0BAJE;IAKFC;EALE,IAMFL,KANJ;;EAQA,MAAMM,sBAAsB,GAAG,MAAyB;IACpD,MAAMC,WAAW,GAAGF,WAAW,CAACG,KAAhC;IAEA,MAAMC,QAAQ,GAAGR,KAAK,KAAKM,WAA3B;;IAEA,IAAIJ,OAAO,KAAK,OAAhB,EAAyB;MACrB,OAAO;QAAEM,QAAF;QAAYC,QAAQ,EAAE;MAAtB,CAAP;IACH;;IAED,MAAMA,QAAQ,GAAGT,KAAK,IAA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AAE,8BAAA,EAAQL,gBAAR;IACH;EACJ,CAnBL,EAoBI,CAAChB,KAAD,CApBJ;EAuBA,MAAMsB,YAAY,GAAG,IAAAC,cAAA,EAAQ,OAAO;IAChCf,QAAQ,EAAEE,SAAS,CAACF;EADY,CAAP,CAAR,EAEjB,CAACE,SAAS,CAACF,QAAX,CAFiB,CAArB;EAIA,MAAMgB,KAAK,GAAGC,qBAAA,CAASC,EAAT,KAAgB,KAAhB,GACPhB,SAAS,CAACF,QAAV,GAAqBjB,gBAAA,CAAWoC,YAAhC,GAA+CrC,MAAM,CAACM,IAD/C,GAERN,MAAM,CAACG,IAFb;EAIA,oBACI,6BAAC,iBAAD;IACI,WAAW,EAAE,KADjB;IAEI,KAAK,EAAE+B;EAFX,gBAII,6BAAC,yBAAD,CAAkB,QAAlB;IAA2B,KAAK,EAAEF;EAAlC,GACKT,OADL,CAJJ,CADJ;AAUH;;4BAEc,IAAAe,WAAA,EAAK9B,IAAL,EAAW,CAAC+B,SAAD,EAAYC,SAAZ,KAA0B;EAChD,IAAID,SAAS,CAACE,WAAV,KAA0BD,SAAS,CAACC,WAAxC,EAAqD;IACjD,OAAO,KAAP;EACH;;EAED,OAAOF,SAAS,CAAC7B,KAAV,KAAoB8B,SAAS,CAAC9B,KAArC;AACH,CANc,C"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.useViewPagerPageState = exports.default = void 0;
|
|
7
|
+
|
|
8
|
+
var _react = require("react");
|
|
9
|
+
|
|
10
|
+
const initialPageState = {
|
|
11
|
+
isActive: false
|
|
12
|
+
};
|
|
13
|
+
const PageStateContext = /*#__PURE__*/(0, _react.createContext)(initialPageState);
|
|
14
|
+
|
|
15
|
+
const useViewPagerPageState = () => {
|
|
16
|
+
return (0, _react.useContext)(PageStateContext);
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
exports.useViewPagerPageState = useViewPagerPageState;
|
|
20
|
+
var _default = PageStateContext;
|
|
21
|
+
exports.default = _default;
|
|
22
|
+
//# sourceMappingURL=PageStateContext.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["initialPageState","isActive","PageStateContext","createContext","useViewPagerPageState","useContext"],"sources":["PageStateContext.ts"],"sourcesContent":["import { createContext, useContext } from 'react';\n\ninterface PageState {\n isActive: boolean;\n}\n\nconst initialPageState: Readonly<PageState> = { isActive: false };\n\nconst PageStateContext = createContext<PageState>(initialPageState);\n\nexport const useViewPagerPageState = () => {\n return useContext(PageStateContext);\n};\n\nexport default PageStateContext;\n"],"mappings":";;;;;;;AAAA;;AAMA,MAAMA,gBAAqC,GAAG;EAAEC,QAAQ,EAAE;AAAZ,CAA9C;AAEA,MAAMC,gBAAgB,gBAAG,IAAAC,oBAAA,EAAyBH,gBAAzB,CAAzB;;AAEO,MAAMI,qBAAqB,GAAG,MAAM;EACvC,OAAO,IAAAC,iBAAA,EAAWH,gBAAX,CAAP;AACH,CAFM;;;eAIQA,gB"}
|
|
@@ -25,26 +25,35 @@ const ViewPager = /*#__PURE__*/(0, _react.forwardRef)(function ViewPager(props,
|
|
|
25
25
|
initialPage = _utils.defaultInitialPage,
|
|
26
26
|
keyboardDismissMode = 'on-drag',
|
|
27
27
|
loading = _utils.defaultLoading,
|
|
28
|
+
offscreenPageRerenderLimit = _utils.defaultOffscreenPageRerenderLimit,
|
|
28
29
|
onChange,
|
|
29
30
|
pageComponent = _utils.defaultPageComponent,
|
|
30
31
|
pageForceRerenderKey,
|
|
31
32
|
scrollEnabled = true,
|
|
32
|
-
style
|
|
33
|
+
style,
|
|
34
|
+
UNSTABLE_sharedIndex
|
|
33
35
|
} = props;
|
|
34
|
-
const
|
|
36
|
+
const fallbackSharedIndex = (0, _reactNativeReanimated.useSharedValue)(initialPage);
|
|
37
|
+
const sharedIndex = UNSTABLE_sharedIndex ?? fallbackSharedIndex;
|
|
35
38
|
const pagerRef = (0, _react.useRef)(null);
|
|
36
|
-
|
|
37
|
-
const setPage = newIndex => {
|
|
38
|
-
requestAnimationFrame(() => {
|
|
39
|
+
const animationFrameRef = (0, _react.useRef)(NaN);
|
|
40
|
+
const setPage = (0, _react.useCallback)(newIndex => {
|
|
41
|
+
animationFrameRef.current = requestAnimationFrame(() => {
|
|
39
42
|
var _pagerRef$current;
|
|
40
43
|
|
|
41
44
|
(_pagerRef$current = pagerRef.current) === null || _pagerRef$current === void 0 ? void 0 : _pagerRef$current.setPage(newIndex);
|
|
42
45
|
});
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
46
|
+
}, []);
|
|
47
|
+
(0, _react.useEffect)(() => {
|
|
48
|
+
return () => {
|
|
49
|
+
if (animationFrameRef.current) {
|
|
50
|
+
cancelAnimationFrame(animationFrameRef.current);
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
}, []);
|
|
54
|
+
(0, _reactNativeReanimated.useAnimatedReaction)(() => sharedIndex.value, result => {
|
|
55
|
+
(0, _reactNativeReanimated.runOnJS)(setPage)(result);
|
|
56
|
+
}, [setPage]);
|
|
48
57
|
const handlePageSelected = (0, _react.useCallback)(e => {
|
|
49
58
|
const currentIndex = sharedIndex.value;
|
|
50
59
|
const nextIndex = e.nativeEvent.position;
|
|
@@ -59,6 +68,9 @@ const ViewPager = /*#__PURE__*/(0, _react.forwardRef)(function ViewPager(props,
|
|
|
59
68
|
onChange(nextIndex);
|
|
60
69
|
}
|
|
61
70
|
}, [onChange]);
|
|
71
|
+
(0, _react.useImperativeHandle)(ref, () => ({
|
|
72
|
+
setPage
|
|
73
|
+
}), [setPage]);
|
|
62
74
|
const PageComponent = pageComponent;
|
|
63
75
|
return /*#__PURE__*/_react.default.createElement(_reactNativePagerView.default, {
|
|
64
76
|
ref: pagerRef,
|
|
@@ -73,6 +85,7 @@ const ViewPager = /*#__PURE__*/(0, _react.forwardRef)(function ViewPager(props,
|
|
|
73
85
|
children: child,
|
|
74
86
|
index: index,
|
|
75
87
|
loading: loading,
|
|
88
|
+
offscreenPageRerenderLimit: offscreenPageRerenderLimit,
|
|
76
89
|
rerenderKey: pageForceRerenderKey,
|
|
77
90
|
sharedIndex: sharedIndex
|
|
78
91
|
})));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["ViewPager","forwardRef","props","ref","children","initialPage","defaultInitialPage","keyboardDismissMode","loading","defaultLoading","onChange","pageComponent","defaultPageComponent","pageForceRerenderKey","scrollEnabled","style","
|
|
1
|
+
{"version":3,"names":["ViewPager","forwardRef","props","ref","children","initialPage","defaultInitialPage","keyboardDismissMode","loading","defaultLoading","offscreenPageRerenderLimit","defaultOffscreenPageRerenderLimit","onChange","pageComponent","defaultPageComponent","pageForceRerenderKey","scrollEnabled","style","UNSTABLE_sharedIndex","fallbackSharedIndex","useSharedValue","sharedIndex","pagerRef","useRef","animationFrameRef","NaN","setPage","useCallback","newIndex","current","requestAnimationFrame","useEffect","cancelAnimationFrame","useAnimatedReaction","value","result","runOnJS","handlePageSelected","e","currentIndex","nextIndex","nativeEvent","position","useImperativeHandle","PageComponent","Children","map","child","index"],"sources":["ViewPagerNative.tsx"],"sourcesContent":["import React, { Children, forwardRef, useCallback, useEffect, useImperativeHandle, useRef } from 'react';\nimport type { ViewPagerOnPageSelectedEvent } from 'react-native-pager-view';\nimport RNViewPager from 'react-native-pager-view';\nimport { runOnJS, useAnimatedReaction, useSharedValue } from 'react-native-reanimated';\nimport type ViewPagerProps from './ViewPagerProps';\nimport type { ViewPagerInstance } from './ViewPagerProps';\nimport { defaultInitialPage, defaultLoading, defaultOffscreenPageRerenderLimit, defaultPageComponent } from './utils';\n\nconst ViewPager = forwardRef<ViewPagerInstance, ViewPagerProps>(function ViewPager(props, ref) {\n const {\n children,\n initialPage = defaultInitialPage,\n keyboardDismissMode = 'on-drag',\n loading = defaultLoading,\n offscreenPageRerenderLimit = defaultOffscreenPageRerenderLimit,\n onChange,\n pageComponent = defaultPageComponent,\n pageForceRerenderKey,\n scrollEnabled = true,\n style,\n UNSTABLE_sharedIndex,\n } = props;\n\n const fallbackSharedIndex = useSharedValue<number>(initialPage);\n\n const sharedIndex = UNSTABLE_sharedIndex ?? fallbackSharedIndex;\n\n const pagerRef = useRef<RNViewPager | null>(null);\n\n const animationFrameRef = useRef<number>(NaN);\n\n const setPage = useCallback((newIndex: number) => {\n animationFrameRef.current = requestAnimationFrame(() => {\n pagerRef.current?.setPage(newIndex);\n });\n }, []);\n\n useEffect(() => {\n return () => {\n if (animationFrameRef.current) {\n cancelAnimationFrame(animationFrameRef.current);\n }\n };\n }, []);\n\n useAnimatedReaction(\n () => sharedIndex.value,\n (result) => {\n runOnJS(setPage)(result);\n },\n [setPage],\n );\n\n const handlePageSelected = useCallback((e: ViewPagerOnPageSelectedEvent) => {\n const currentIndex = sharedIndex.value;\n const nextIndex = e.nativeEvent.position;\n\n if (currentIndex === nextIndex) {\n return;\n }\n\n sharedIndex.value = nextIndex;\n\n if (onChange) {\n onChange(nextIndex);\n }\n }, [onChange]);\n\n useImperativeHandle(\n ref,\n () => ({ setPage }),\n [setPage],\n );\n\n const PageComponent = pageComponent;\n\n return (\n <RNViewPager\n ref={pagerRef}\n initialPage={initialPage}\n keyboardDismissMode={keyboardDismissMode}\n onPageSelected={handlePageSelected}\n pageMargin={8}\n scrollEnabled={scrollEnabled}\n style={style}\n >\n {Children.map(children, (child, index) => (\n <PageComponent\n key={index}\n children={child}\n index={index}\n loading={loading}\n offscreenPageRerenderLimit={offscreenPageRerenderLimit}\n rerenderKey={pageForceRerenderKey}\n sharedIndex={sharedIndex}\n />\n ))}\n </RNViewPager>\n );\n});\n\nexport default ViewPager;\n"],"mappings":";;;;;;;AAAA;;AAEA;;AACA;;AAGA;;;;;;;;AAEA,MAAMA,SAAS,gBAAG,IAAAC,iBAAA,EAA8C,SAASD,SAAT,CAAmBE,KAAnB,EAA0BC,GAA1B,E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AAF,CAAcC,QAAhC;;IAEA,IAAIH,YAAY,KAAKC,SAArB,EAAgC;MAC5B;IACH;;IAEDnB,WAAW,CAACa,KAAZ,GAAoBM,SAApB;;IAEA,IAAI5B,QAAJ,EAAc;MACVA,QAAQ,CAAC4B,SAAD,CAAR;IACH;EACJ,CAb0B,EAaxB,CAAC5B,QAAD,CAbwB,CAA3B;EAeA,IAAA+B,0BAAA,EACIxC,GADJ,EAEI,OAAO;IAAEuB;EAAF,CAAP,CAFJ,EAGI,CAACA,OAAD,CAHJ;EAMA,MAAMkB,aAAa,GAAG/B,aAAtB;EAEA,oBACI,6BAAC,6BAAD;IACI,GAAG,EAAES,QADT;IAEI,WAAW,EAAEjB,WAFjB;IAGI,mBAAmB,EAAEE,mBAHzB;IAII,cAAc,EAAE8B,kBAJpB;IAKI,UAAU,EAAE,CALhB;IAMI,aAAa,EAAErB,aANnB;IAOI,KAAK,EAAEC;EAPX,GASK4B,eAAA,CAASC,GAAT,CAAa1C,QAAb,EAAuB,CAAC2C,KAAD,EAAQC,KAAR,kBACpB,6BAAC,aAAD;IACI,GAAG,EAAEA,KADT;IAEI,QAAQ,EAAED,KAFd;IAGI,KAAK,EAAEC,KAHX;IAII,OAAO,EAAExC,OAJb;IAKI,0BAA0B,EAAEE,0BALhC;IAMI,WAAW,EAAEK,oBANjB;IAOI,WAAW,EAAEM;EAPjB,EADH,CATL,CADJ;AAuBH,CA3FiB,CAAlB;eA6FerB,S"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["ViewPagerProps.ts"],"sourcesContent":["import type { ComponentType, PropsWithChildren, ReactNode, Ref } from 'react';\nimport type { ViewProps } from 'react-native';\nimport type { SharedValue } from 'react-native-reanimated';\nimport type { ComponentProps } from '@fountain-ui/core';\n\nexport type KeyboardDismissMode = 'none' | 'on-drag';\n\nexport type PageProps = PropsWithChildren<ViewProps> & {\n index: number;\n loading: ViewPagerProps['loading'];\n sharedIndex: SharedValue<number>;\n rerenderKey?: ViewPagerProps['pageForceRerenderKey'];\n};\n\nexport type PageComponent = ComponentType<PageProps>;\n\nexport type Loading = 'lazy' | 'eager';\n\nexport interface ViewPagerInstance {\n /**\n * Function to scroll to a specific page in the ViewPager. Invalid index is ignored.\n * @param index\n */\n setPage: (index: number) => void;\n}\n\nexport default interface ViewPagerProps extends ComponentProps<{\n ref?: Ref<ViewPagerInstance>;\n\n /**\n * Collection of ViewPager components.\n */\n children?: ReactNode;\n\n /**\n * Index of initial page that should be selected.\n * @default 0\n */\n initialPage?: number;\n\n /**\n * Whether to load the page immediately (`eager`) or on an as-needed basis (`lazy`).\n * @default 'lazy'\n */\n loading?: Loading;\n\n /**\n * Callback fired when an index is changed.\n */\n onChange?: (newIndex: number) => void,\n\n /**\n * The component used to render the wrapper of the page.\n * @default 'ChildrenMemoizedPage'\n */\n pageComponent?: PageComponent,\n\n /**\n * When this value is changed, page will be rerender.\n */\n pageForceRerenderKey?: any;\n\n /**\n * Mobile only. Should pager view scroll, when scroll enabled.\n * @default true\n */\n scrollEnabled?: boolean;\n\n /**\n * Mobile only. Determines whether the keyboard gets dismissed in response to a drag.\n * @default 'on-drag'\n */\n keyboardDismissMode?: KeyboardDismissMode;\n}> {}\n"],"mappings":""}
|
|
1
|
+
{"version":3,"names":[],"sources":["ViewPagerProps.ts"],"sourcesContent":["import type { ComponentType, PropsWithChildren, ReactNode, Ref } from 'react';\nimport type { ViewProps } from 'react-native';\nimport type { SharedValue } from 'react-native-reanimated';\nimport type { ComponentProps } from '@fountain-ui/core';\n\nexport type KeyboardDismissMode = 'none' | 'on-drag';\n\nexport type PageProps = PropsWithChildren<ViewProps> & {\n index: number;\n loading: ViewPagerProps['loading'];\n offscreenPageRerenderLimit: number;\n sharedIndex: SharedValue<number>;\n rerenderKey?: ViewPagerProps['pageForceRerenderKey'];\n};\n\nexport type PageComponent = ComponentType<PageProps>;\n\nexport type Loading = 'lazy' | 'eager';\n\nexport interface ViewPagerInstance {\n /**\n * Function to scroll to a specific page in the ViewPager. Invalid index is ignored.\n * @param index\n */\n setPage: (index: number) => void;\n}\n\nexport default interface ViewPagerProps extends ComponentProps<{\n ref?: Ref<ViewPagerInstance>;\n\n /**\n * Collection of ViewPager components.\n */\n children?: ReactNode;\n\n /**\n * Index of initial page that should be selected.\n * @default 0\n */\n initialPage?: number;\n\n /**\n * Whether to load the page immediately (`eager`) or on an as-needed basis (`lazy`).\n * @default 'lazy'\n */\n loading?: Loading;\n\n /**\n * Mobile only. The number of pages that should be re-rendered to either side of the current page.\n * Changing this value after the component mount has no effect.\n * @default 0\n */\n offscreenPageRerenderLimit?: number;\n\n /**\n * Callback fired when an index is changed.\n */\n onChange?: (newIndex: number) => void,\n\n /**\n * The component used to render the wrapper of the page.\n * @default 'ChildrenMemoizedPage'\n */\n pageComponent?: PageComponent,\n\n /**\n * When this value is changed, page will be rerender.\n */\n pageForceRerenderKey?: any;\n\n /**\n * Mobile only. Should pager view scroll, when scroll enabled.\n * @default true\n */\n scrollEnabled?: boolean;\n\n /**\n * Mobile only. Determines whether the keyboard gets dismissed in response to a drag.\n * @default 'on-drag'\n */\n keyboardDismissMode?: KeyboardDismissMode;\n\n /**\n * Unstable API.\n */\n UNSTABLE_sharedIndex?: SharedValue<number>;\n}> {}\n"],"mappings":""}
|
|
@@ -34,17 +34,17 @@ const ViewPager = /*#__PURE__*/(0, _react.forwardRef)(function ViewPager(props,
|
|
|
34
34
|
loading = _utils.defaultLoading,
|
|
35
35
|
pageComponent = _utils.defaultPageComponent,
|
|
36
36
|
pageForceRerenderKey,
|
|
37
|
-
style
|
|
37
|
+
style,
|
|
38
|
+
UNSTABLE_sharedIndex
|
|
38
39
|
} = props;
|
|
39
|
-
const
|
|
40
|
-
|
|
41
|
-
const setPage = newIndex => {
|
|
40
|
+
const fallbackSharedIndex = (0, _reactNativeReanimated.useSharedValue)(initialPage);
|
|
41
|
+
const sharedIndex = UNSTABLE_sharedIndex ?? fallbackSharedIndex;
|
|
42
|
+
const setPage = (0, _react.useCallback)(newIndex => {
|
|
42
43
|
sharedIndex.value = newIndex;
|
|
43
|
-
};
|
|
44
|
-
|
|
44
|
+
}, [sharedIndex]);
|
|
45
45
|
(0, _react.useImperativeHandle)(ref, () => ({
|
|
46
46
|
setPage
|
|
47
|
-
}), []);
|
|
47
|
+
}), [setPage]);
|
|
48
48
|
const PageComponent = pageComponent;
|
|
49
49
|
return /*#__PURE__*/_react.default.createElement(_reactNative.View, {
|
|
50
50
|
style: [styles.root, style]
|
|
@@ -53,6 +53,8 @@ const ViewPager = /*#__PURE__*/(0, _react.forwardRef)(function ViewPager(props,
|
|
|
53
53
|
children: child,
|
|
54
54
|
index: index,
|
|
55
55
|
loading: loading,
|
|
56
|
+
offscreenPageRerenderLimit: 0 // All offscreen pages will not be re-rendered
|
|
57
|
+
,
|
|
56
58
|
rerenderKey: pageForceRerenderKey,
|
|
57
59
|
sharedIndex: sharedIndex
|
|
58
60
|
})));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["styles","StyleSheet","create","root","overflow","position","ViewPager","forwardRef","props","ref","children","initialPage","defaultInitialPage","loading","defaultLoading","pageComponent","defaultPageComponent","pageForceRerenderKey","style","
|
|
1
|
+
{"version":3,"names":["styles","StyleSheet","create","root","overflow","position","ViewPager","forwardRef","props","ref","children","initialPage","defaultInitialPage","loading","defaultLoading","pageComponent","defaultPageComponent","pageForceRerenderKey","style","UNSTABLE_sharedIndex","fallbackSharedIndex","useSharedValue","sharedIndex","setPage","useCallback","newIndex","value","useImperativeHandle","PageComponent","Children","map","child","index"],"sources":["ViewPagerWeb.tsx"],"sourcesContent":["import React, { Children, forwardRef, useImperativeHandle, useCallback } from 'react';\nimport { View } from 'react-native';\nimport { useSharedValue } from 'react-native-reanimated';\nimport { StyleSheet } from '@fountain-ui/core';\nimport type ViewPagerProps from './ViewPagerProps';\nimport type { ViewPagerInstance } from './ViewPagerProps';\nimport { defaultInitialPage, defaultLoading, defaultPageComponent } from './utils';\n\nconst styles = StyleSheet.create({\n root: {\n // @ts-ignore\n overflow: 'auto',\n position: 'relative',\n },\n});\n\nconst ViewPager = forwardRef<ViewPagerInstance, ViewPagerProps>(function ViewPager(props, ref) {\n const {\n children,\n initialPage = defaultInitialPage,\n loading = defaultLoading,\n pageComponent = defaultPageComponent,\n pageForceRerenderKey,\n style,\n UNSTABLE_sharedIndex,\n } = props;\n\n const fallbackSharedIndex = useSharedValue<number>(initialPage);\n\n const sharedIndex = UNSTABLE_sharedIndex ?? fallbackSharedIndex;\n\n const setPage = useCallback((newIndex: number) => {\n sharedIndex.value = newIndex;\n }, [sharedIndex]);\n\n useImperativeHandle(\n ref,\n () => ({ setPage }),\n [setPage],\n );\n\n const PageComponent = pageComponent;\n\n return (\n <View style={[styles.root, style]}>\n {Children.map(children, (child, index) => (\n <PageComponent\n key={index}\n children={child}\n index={index}\n loading={loading}\n offscreenPageRerenderLimit={0} // All offscreen pages will not be re-rendered\n rerenderKey={pageForceRerenderKey}\n sharedIndex={sharedIndex}\n />\n ))}\n </View>\n );\n});\n\nexport default ViewPager;\n"],"mappings":";;;;;;;AAAA;;AACA;;AACA;;AACA;;AAGA;;;;;;AAEA,MAAMA,MAAM,GAAGC,gBAAA,CAAWC,MAAX,CAAkB;EAC7BC,IAAI,EAAE;IACF;IACAC,QAAQ,EAAE,MAFR;IAGFC,QAAQ,EAAE;EAHR;AADuB,CAAlB,CAAf;;AAQA,MAAMC,SAAS,gBAAG,IAAAC,iBAAA,EAA8C,SAASD,SAAT,CAAmBE,KAAnB,EAA0BC,GAA1B,EAA+B;EAC3F,MAAM;IACFC,QADE;IAEFC,WAAW,GAAGC,yBAFZ;IAGFC,OAAO,GAAGC,qBAHR;IAIFC,aAAa,GAAGC,2BAJd;IAKFC,oBALE;IAMFC,KANE;IAOFC;EAPE,IAQFX,KARJ;EAUA,MAAMY,mBAAmB,GAAG,IAAAC,qCAAA,EAAuBV,WAAvB,CAA5B;EAEA,MAAMW,WAAW,GAAGH,oBAAoB,IAAIC,mBAA5C;EAEA,MAAMG,OAAO,GAAG,IAAAC,kBAAA,EAAaC,QAAD,IAAsB;IAC9CH,WAAW,CAACI,KAAZ,GAAoBD,QAApB;EACH,CAFe,EAEb,CAACH,WAAD,CAFa,CAAhB;EAIA,IAAAK,0BAAA,EACIlB,GADJ,EAEI,OAAO;IAAEc;EAAF,CAAP,CAFJ,EAGI,CAACA,OAAD,CAHJ;EAMA,MAAMK,aAAa,GAAGb,aAAtB;EAEA,oBACI,6BAAC,iBAAD;IAAM,KAAK,EAAE,CAACf,MAAM,CAACG,IAAR,EAAce,KAAd;EAAb,GACKW,eAAA,CAASC,GAAT,CAAapB,QAAb,EAAuB,CAACqB,KAAD,EAAQC,KAAR,kBACpB,6BAAC,aAAD;IACI,GAAG,EAAEA,KADT;IAEI,QAAQ,EAAED,KAFd;IAGI,KAAK,EAAEC,KAHX;IAII,OAAO,EAAEnB,OAJb;IAKI,0BAA0B,EAAE,CALhC,CAKmC;IALnC;IAMI,WAAW,EAAEI,oBANjB;IAOI,WAAW,EAAEK;EAPjB,EADH,CADL,CADJ;AAeH,CA1CiB,CAAlB;eA4CehB,S"}
|
|
@@ -9,8 +9,16 @@ Object.defineProperty(exports, "default", {
|
|
|
9
9
|
return _ViewPagerWeb.default;
|
|
10
10
|
}
|
|
11
11
|
});
|
|
12
|
+
Object.defineProperty(exports, "useViewPagerPageState", {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function () {
|
|
15
|
+
return _PageStateContext.useViewPagerPageState;
|
|
16
|
+
}
|
|
17
|
+
});
|
|
12
18
|
|
|
13
19
|
var _ViewPagerWeb = _interopRequireDefault(require("./ViewPagerWeb"));
|
|
14
20
|
|
|
21
|
+
var _PageStateContext = require("./PageStateContext");
|
|
22
|
+
|
|
15
23
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
16
24
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export { default } from './ViewPagerWeb';\nexport type { default as ViewPagerProps, ViewPagerInstance } from './ViewPagerProps';\n"],"mappings":"
|
|
1
|
+
{"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export { default } from './ViewPagerWeb';\nexport type { default as ViewPagerProps, ViewPagerInstance } from './ViewPagerProps';\nexport { useViewPagerPageState } from './PageStateContext';\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;;AAEA"}
|
|
@@ -9,8 +9,16 @@ Object.defineProperty(exports, "default", {
|
|
|
9
9
|
return _ViewPagerNative.default;
|
|
10
10
|
}
|
|
11
11
|
});
|
|
12
|
+
Object.defineProperty(exports, "useViewPagerPageState", {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function () {
|
|
15
|
+
return _PageStateContext.useViewPagerPageState;
|
|
16
|
+
}
|
|
17
|
+
});
|
|
12
18
|
|
|
13
19
|
var _ViewPagerNative = _interopRequireDefault(require("./ViewPagerNative"));
|
|
14
20
|
|
|
21
|
+
var _PageStateContext = require("./PageStateContext");
|
|
22
|
+
|
|
15
23
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
16
24
|
//# sourceMappingURL=index.native.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["index.native.ts"],"sourcesContent":["export { default } from './ViewPagerNative';\n"],"mappings":"
|
|
1
|
+
{"version":3,"names":[],"sources":["index.native.ts"],"sourcesContent":["export { default } from './ViewPagerNative';\nexport { useViewPagerPageState } from './PageStateContext';\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;;AACA"}
|