@fountain-ui/lab 2.0.0-beta.14 → 2.0.0-beta.15
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 +27 -30
- package/build/commonjs/Carousel/Carousel.js.map +1 -1
- package/build/commonjs/Carousel/animation/createDefaultScrollAnimation.js +2 -2
- package/build/commonjs/Carousel/animation/createDefaultScrollAnimation.js.map +1 -1
- package/build/commonjs/Carousel/animation/parallaxItemStyleFactory.js +2 -2
- package/build/commonjs/Carousel/animation/parallaxItemStyleFactory.js.map +1 -1
- package/build/commonjs/Carousel/components/ItemView.js +2 -2
- package/build/commonjs/Carousel/components/ItemView.js.map +1 -1
- package/build/commonjs/Carousel/components/ScrollViewGesture.js +6 -6
- package/build/commonjs/Carousel/components/ScrollViewGesture.js.map +1 -1
- package/build/commonjs/Carousel/{hooks → components}/useItemInterpolation.js +6 -4
- package/build/commonjs/Carousel/components/useItemInterpolation.js.map +1 -0
- package/build/commonjs/Carousel/hooks/index.js +0 -16
- package/build/commonjs/Carousel/hooks/index.js.map +1 -1
- package/build/commonjs/Carousel/hooks/useIndexController.js +15 -46
- package/build/commonjs/Carousel/hooks/useIndexController.js.map +1 -1
- package/build/commonjs/Carousel/hooks/useItemVisibilityStore.js +12 -12
- package/build/commonjs/Carousel/hooks/useItemVisibilityStore.js.map +1 -1
- package/build/commonjs/Carousel/hooks/usePagingAnimation.js +70 -56
- package/build/commonjs/Carousel/hooks/usePagingAnimation.js.map +1 -1
- package/build/commonjs/Carousel/tick.js +16 -0
- package/build/commonjs/Carousel/tick.js.map +1 -0
- package/build/commonjs/Carousel/types.js.map +1 -1
- package/build/commonjs/ViewPager/ChildrenMemoizedPage.js +44 -35
- package/build/commonjs/ViewPager/ChildrenMemoizedPage.js.map +1 -1
- package/build/commonjs/ViewPager/ViewPagerNative.js +2 -3
- package/build/commonjs/ViewPager/ViewPagerNative.js.map +1 -1
- package/build/commonjs/ViewPager/usePageStore.js +5 -0
- package/build/commonjs/ViewPager/usePageStore.js.map +1 -1
- package/build/commonjs/ViewabilityTrackerView/measureViewability.js +6 -6
- package/build/commonjs/ViewabilityTrackerView/measureViewability.js.map +1 -1
- package/build/module/Carousel/Carousel.js +27 -32
- package/build/module/Carousel/Carousel.js.map +1 -1
- package/build/module/Carousel/animation/createDefaultScrollAnimation.js +2 -2
- package/build/module/Carousel/animation/createDefaultScrollAnimation.js.map +1 -1
- package/build/module/Carousel/animation/parallaxItemStyleFactory.js +2 -2
- package/build/module/Carousel/animation/parallaxItemStyleFactory.js.map +1 -1
- package/build/module/Carousel/components/ItemView.js +1 -1
- package/build/module/Carousel/components/ItemView.js.map +1 -1
- package/build/module/Carousel/components/ScrollViewGesture.js +6 -6
- package/build/module/Carousel/components/ScrollViewGesture.js.map +1 -1
- package/build/module/Carousel/{hooks → components}/useItemInterpolation.js +3 -3
- package/build/module/Carousel/components/useItemInterpolation.js.map +1 -0
- package/build/module/Carousel/hooks/index.js +0 -2
- package/build/module/Carousel/hooks/index.js.map +1 -1
- package/build/module/Carousel/hooks/useIndexController.js +14 -39
- package/build/module/Carousel/hooks/useIndexController.js.map +1 -1
- package/build/module/Carousel/hooks/useItemVisibilityStore.js +10 -11
- package/build/module/Carousel/hooks/useItemVisibilityStore.js.map +1 -1
- package/build/module/Carousel/hooks/usePagingAnimation.js +71 -56
- package/build/module/Carousel/hooks/usePagingAnimation.js.map +1 -1
- package/build/module/Carousel/tick.js +6 -0
- package/build/module/Carousel/tick.js.map +1 -0
- package/build/module/Carousel/types.js.map +1 -1
- package/build/module/ViewPager/ChildrenMemoizedPage.js +44 -35
- package/build/module/ViewPager/ChildrenMemoizedPage.js.map +1 -1
- package/build/module/ViewPager/ViewPagerNative.js +2 -3
- package/build/module/ViewPager/ViewPagerNative.js.map +1 -1
- package/build/module/ViewPager/usePageStore.js +5 -0
- package/build/module/ViewPager/usePageStore.js.map +1 -1
- package/build/module/ViewabilityTrackerView/measureViewability.js +2 -2
- package/build/module/ViewabilityTrackerView/measureViewability.js.map +1 -1
- package/build/typescript/Carousel/components/ScrollViewGesture.d.ts +2 -2
- package/build/typescript/Carousel/{hooks → components}/useItemInterpolation.d.ts +0 -0
- package/build/typescript/Carousel/hooks/index.d.ts +0 -2
- package/build/typescript/Carousel/hooks/useIndexController.d.ts +0 -2
- package/build/typescript/Carousel/hooks/useItemVisibilityStore.d.ts +5 -2
- package/build/typescript/Carousel/hooks/usePagingAnimation.d.ts +5 -7
- package/build/typescript/Carousel/tick.d.ts +2 -0
- package/build/typescript/Carousel/types.d.ts +1 -2
- package/package.json +3 -3
- package/src/Carousel/Carousel.tsx +25 -34
- package/src/Carousel/animation/createDefaultScrollAnimation.ts +2 -2
- package/src/Carousel/animation/parallaxItemStyleFactory.ts +1 -1
- package/src/Carousel/components/ItemView.tsx +1 -1
- package/src/Carousel/components/ScrollViewGesture.tsx +8 -7
- package/src/Carousel/{hooks → components}/useItemInterpolation.ts +3 -3
- package/src/Carousel/hooks/index.ts +0 -2
- package/src/Carousel/hooks/useIndexController.tsx +14 -44
- package/src/Carousel/hooks/useItemVisibilityStore.ts +17 -13
- package/src/Carousel/hooks/usePagingAnimation.ts +95 -64
- package/src/Carousel/tick.ts +6 -0
- package/src/Carousel/types.ts +1 -2
- package/src/ViewPager/ChildrenMemoizedPage.tsx +46 -39
- package/src/ViewPager/ViewPagerNative.tsx +3 -3
- package/src/ViewPager/usePageStore.ts +6 -0
- package/src/ViewabilityTrackerView/measureViewability.ts +1 -3
- package/build/commonjs/Carousel/hooks/useDimensionChangeReaction.js +0 -23
- package/build/commonjs/Carousel/hooks/useDimensionChangeReaction.js.map +0 -1
- package/build/commonjs/Carousel/hooks/useItemInterpolation.js.map +0 -1
- package/build/module/Carousel/hooks/useDimensionChangeReaction.js +0 -14
- package/build/module/Carousel/hooks/useDimensionChangeReaction.js.map +0 -1
- package/build/module/Carousel/hooks/useItemInterpolation.js.map +0 -1
- package/build/typescript/Carousel/hooks/useDimensionChangeReaction.d.ts +0 -7
- package/src/Carousel/hooks/useDimensionChangeReaction.ts +0 -25
package/src/Carousel/types.ts
CHANGED
|
@@ -24,10 +24,9 @@ export interface GetCurrentIndex {
|
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
export interface IndexController {
|
|
27
|
-
currentIndex: number;
|
|
28
27
|
getCurrentIndex: GetCurrentIndex;
|
|
29
28
|
lastIndex: number;
|
|
30
|
-
|
|
29
|
+
notifyOffsetHasChanged: (offset: number) => void;
|
|
31
30
|
}
|
|
32
31
|
|
|
33
32
|
export type PagingAnimationType = 'directional' | 'index';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React, { memo, useContext, useEffect, useMemo, useState } from 'react';
|
|
1
|
+
import React, { memo, useCallback, useContext, useEffect, useMemo, useReducer, useRef, useState } from 'react';
|
|
2
2
|
import { Platform, View } from 'react-native';
|
|
3
3
|
import { StyleSheet } from '@fountain-ui/core';
|
|
4
4
|
import type { PageProps } from './types';
|
|
@@ -10,9 +10,14 @@ const styles = StyleSheet.create({
|
|
|
10
10
|
none: { display: 'none' },
|
|
11
11
|
});
|
|
12
12
|
|
|
13
|
-
interface
|
|
13
|
+
interface InternalPageDescription {
|
|
14
14
|
isActive: boolean;
|
|
15
|
-
|
|
15
|
+
becomeNeighbor: boolean;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
interface InternalPageState {
|
|
19
|
+
active: boolean;
|
|
20
|
+
loaded: boolean;
|
|
16
21
|
}
|
|
17
22
|
|
|
18
23
|
function Page(props: PageProps) {
|
|
@@ -26,63 +31,65 @@ function Page(props: PageProps) {
|
|
|
26
31
|
|
|
27
32
|
const { pageStore } = useContext(InternalContext);
|
|
28
33
|
|
|
29
|
-
const
|
|
30
|
-
const activeIndex =
|
|
34
|
+
const computePageDescription: (page: number) => InternalPageDescription = useCallback((page: number) => {
|
|
35
|
+
const activeIndex = page;
|
|
31
36
|
|
|
32
37
|
const isActive = index === activeIndex;
|
|
33
38
|
|
|
39
|
+
const shouldRerender = index >= activeIndex - offscreenPageRerenderLimit
|
|
40
|
+
&& index <= activeIndex + offscreenPageRerenderLimit;
|
|
41
|
+
|
|
42
|
+
const becomeNeighbor = shouldRerender && !isActive;
|
|
43
|
+
|
|
44
|
+
return { isActive, becomeNeighbor };
|
|
45
|
+
}, [index]);
|
|
46
|
+
|
|
47
|
+
const [initialState] = useState<InternalPageState>(() => {
|
|
48
|
+
const { isActive, becomeNeighbor } = computePageDescription(initialPage);
|
|
49
|
+
|
|
34
50
|
if (loading === 'eager') {
|
|
35
|
-
return { isActive,
|
|
51
|
+
return { active: isActive, loaded: true };
|
|
36
52
|
}
|
|
37
53
|
|
|
38
|
-
|
|
39
|
-
|
|
54
|
+
return { active: isActive, loaded: isActive || becomeNeighbor };
|
|
55
|
+
});
|
|
40
56
|
|
|
41
|
-
|
|
42
|
-
|
|
57
|
+
// `Bailing out of a state update` is not working as expected.
|
|
58
|
+
const pageStateRef = useRef<InternalPageState>(initialState);
|
|
59
|
+
const [, forceRender] = useReducer((s) => s + 1, 0);
|
|
43
60
|
|
|
44
|
-
const
|
|
61
|
+
const { active, loaded } = pageStateRef.current;
|
|
45
62
|
|
|
46
|
-
const content =
|
|
63
|
+
const content = loaded ? children : null;
|
|
47
64
|
|
|
48
65
|
useEffect(() => {
|
|
49
66
|
return pageStore.subscribe(newPage => {
|
|
50
|
-
const
|
|
51
|
-
|
|
52
|
-
const isActive = index === activeIndex;
|
|
53
|
-
|
|
54
|
-
const shouldRerender = index >= activeIndex - offscreenPageRerenderLimit
|
|
55
|
-
&& index <= activeIndex + offscreenPageRerenderLimit;
|
|
67
|
+
const { isActive, becomeNeighbor } = computePageDescription(newPage);
|
|
56
68
|
|
|
57
|
-
const
|
|
69
|
+
const currentState = pageStateRef.current;
|
|
58
70
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
isActive,
|
|
64
|
-
isLoaded: isActive || prevState.isLoaded,
|
|
65
|
-
};
|
|
66
|
-
}
|
|
71
|
+
const newState: InternalPageState = {
|
|
72
|
+
active: isActive,
|
|
73
|
+
loaded: isActive || becomeNeighbor ? true : currentState.loaded,
|
|
74
|
+
};
|
|
67
75
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
}
|
|
76
|
+
if (
|
|
77
|
+
currentState.active !== newState.active
|
|
78
|
+
|| currentState.loaded !== newState.loaded
|
|
79
|
+
) {
|
|
80
|
+
pageStateRef.current = newState;
|
|
74
81
|
|
|
75
|
-
|
|
76
|
-
}
|
|
82
|
+
forceRender();
|
|
83
|
+
}
|
|
77
84
|
});
|
|
78
|
-
}, [pageStore,
|
|
85
|
+
}, [pageStore, computePageDescription]);
|
|
79
86
|
|
|
80
87
|
const contextValue = useMemo(() => ({
|
|
81
|
-
isActive:
|
|
82
|
-
}), [
|
|
88
|
+
isActive: active,
|
|
89
|
+
}), [active]);
|
|
83
90
|
|
|
84
91
|
const style = Platform.OS === 'web'
|
|
85
|
-
? (
|
|
92
|
+
? (active ? StyleSheet.absoluteFill : styles.none)
|
|
86
93
|
: styles.fill;
|
|
87
94
|
|
|
88
95
|
return (
|
|
@@ -77,7 +77,7 @@ const ViewPager = forwardRef<ViewPagerInstance, ViewPagerProps>(function ViewPag
|
|
|
77
77
|
return () => {
|
|
78
78
|
animatedValue.removeListener(id);
|
|
79
79
|
};
|
|
80
|
-
}, [sharedPage]);
|
|
80
|
+
}, [sharedPage, setPage]);
|
|
81
81
|
|
|
82
82
|
const handlePageSelected = useCallback((e: ViewPagerOnPageSelectedEvent) => {
|
|
83
83
|
if (Number.isFinite(desiredPageRef.current)) {
|
|
@@ -103,9 +103,9 @@ const ViewPager = forwardRef<ViewPagerInstance, ViewPagerProps>(function ViewPag
|
|
|
103
103
|
if (trustfulNextPage !== pageRef.current) {
|
|
104
104
|
desiredPageRef.current = trustfulNextPage;
|
|
105
105
|
sharedPage.animatedValue.setValue(trustfulNextPage);
|
|
106
|
-
}
|
|
107
106
|
|
|
108
|
-
|
|
107
|
+
onChange?.(trustfulNextPage);
|
|
108
|
+
}
|
|
109
109
|
}
|
|
110
110
|
}, [onChange, sharedPage]);
|
|
111
111
|
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { View } from 'react-native';
|
|
2
|
+
import { clamp } from '@fountain-ui/utils';
|
|
2
3
|
|
|
3
4
|
interface Rect {
|
|
4
5
|
top: number,
|
|
@@ -27,9 +28,6 @@ const normalizePagePosition = (value?: number): number =>
|
|
|
27
28
|
const normalizeViewSize = (size: number): number =>
|
|
28
29
|
Number.isFinite(size) && size > 0 ? size : Number.MAX_SAFE_INTEGER;
|
|
29
30
|
|
|
30
|
-
const clamp = (value: number, min: number, max: number): number =>
|
|
31
|
-
Math.min(Math.max(value, min), max);
|
|
32
|
-
|
|
33
31
|
export default function measureViewability({
|
|
34
32
|
view,
|
|
35
33
|
windowWidth,
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = useDimensionChangeReaction;
|
|
7
|
-
|
|
8
|
-
var _react = require("react");
|
|
9
|
-
|
|
10
|
-
function useDimensionChangeReaction(params) {
|
|
11
|
-
const {
|
|
12
|
-
controlledTx,
|
|
13
|
-
currentIndex,
|
|
14
|
-
itemWidth
|
|
15
|
-
} = params;
|
|
16
|
-
(0, _react.useEffect)(() => {
|
|
17
|
-
const newTx = -currentIndex * itemWidth;
|
|
18
|
-
controlledTx.setValue(newTx);
|
|
19
|
-
}, [controlledTx, currentIndex, itemWidth]);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
;
|
|
23
|
-
//# sourceMappingURL=useDimensionChangeReaction.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["useDimensionChangeReaction","params","controlledTx","currentIndex","itemWidth","useEffect","newTx","setValue"],"sources":["useDimensionChangeReaction.ts"],"sourcesContent":["import { useEffect } from 'react';\nimport { Animated } from 'react-native';\n\nexport interface Parameters {\n controlledTx: Animated.AnimatedValue;\n currentIndex: number;\n itemWidth: number;\n}\n\nexport default function useDimensionChangeReaction(params: Parameters) {\n const {\n controlledTx,\n currentIndex,\n itemWidth,\n } = params;\n\n useEffect(() => {\n const newTx = -currentIndex * itemWidth;\n controlledTx.setValue(newTx);\n }, [\n controlledTx,\n currentIndex,\n itemWidth,\n ]);\n};\n"],"mappings":";;;;;;;AAAA;;AASe,SAASA,0BAAT,CAAoCC,MAApC,EAAwD;EACnE,MAAM;IACFC,YADE;IAEFC,YAFE;IAGFC;EAHE,IAIFH,MAJJ;EAMA,IAAAI,gBAAA,EAAU,MAAM;IACZ,MAAMC,KAAK,GAAG,CAACH,YAAD,GAAgBC,SAA9B;IACAF,YAAY,CAACK,QAAb,CAAsBD,KAAtB;EACH,CAHD,EAGG,CACCJ,YADD,EAECC,YAFD,EAGCC,SAHD,CAHH;AAQH;;AAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["OVERSCROLL_FRICTION_FACTOR","useItemInterpolation","index","itemWidth","data","globalInterpolation","loop","useContext","InternalContext","numberOfData","length","interpolationConfigOnLoop","useMemo","lastIndex","maxWidth","Math","abs","halfOfItemWidth","positiveCount","round","startPosition","max","min","inputRange","Number","MIN_VALUE","outputRange","extrapolate","interpolationConfigOnNoLoop","friction","interpolationConfig","offsetX","interpolate","Animated","divide"],"sources":["useItemInterpolation.ts"],"sourcesContent":["import { useContext, useMemo } from 'react';\nimport { Animated } from 'react-native';\nimport { InternalContext } from '../components';\n\nconst OVERSCROLL_FRICTION_FACTOR = 4;\n\nexport default function useItemInterpolation(index: number): Animated.AnimatedInterpolation {\n const {\n itemWidth,\n data,\n globalInterpolation,\n loop,\n } = useContext(InternalContext);\n\n const numberOfData = data.length;\n\n const interpolationConfigOnLoop = useMemo<Animated.InterpolationConfigType>(() => {\n const lastIndex = numberOfData - 1;\n const maxWidth = Math.abs(itemWidth * numberOfData);\n const halfOfItemWidth = 0.5 * itemWidth;\n\n const positiveCount = Math.round(lastIndex / 2);\n const startPosition = index > positiveCount\n ? (index - numberOfData) * itemWidth\n : itemWidth * index;\n\n const max = positiveCount * itemWidth;\n const min = -((lastIndex - positiveCount) * itemWidth);\n\n const inputRange = [\n -maxWidth,\n min - halfOfItemWidth - startPosition - Number.MIN_VALUE,\n min - halfOfItemWidth - startPosition,\n 0,\n max + halfOfItemWidth - startPosition,\n max + halfOfItemWidth - startPosition + Number.MIN_VALUE,\n maxWidth,\n ];\n\n const outputRange = [\n startPosition,\n max + halfOfItemWidth - Number.MIN_VALUE,\n min - halfOfItemWidth,\n startPosition,\n max + halfOfItemWidth,\n min - halfOfItemWidth + Number.MIN_VALUE,\n startPosition,\n ];\n\n return {\n inputRange,\n outputRange,\n extrapolate: 'clamp',\n };\n }, [\n index,\n itemWidth,\n numberOfData,\n ]);\n\n const interpolationConfigOnNoLoop = useMemo<Animated.InterpolationConfigType>(() => {\n const lastIndex = numberOfData - 1;\n const maxWidth = itemWidth * lastIndex;\n const startPosition = itemWidth * index;\n const friction = itemWidth / OVERSCROLL_FRICTION_FACTOR;\n\n const inputRange = [\n -(maxWidth + itemWidth), // overscroll\n -maxWidth,\n 0,\n itemWidth, // overscroll\n ];\n\n const outputRange = [\n -maxWidth + startPosition - friction,\n -maxWidth + startPosition,\n startPosition,\n startPosition + friction,\n ];\n\n return {\n inputRange,\n outputRange,\n extrapolate: 'clamp',\n };\n }, [\n index,\n itemWidth,\n numberOfData,\n ]);\n\n return useMemo(() => {\n const interpolationConfig = loop\n ? interpolationConfigOnLoop\n : interpolationConfigOnNoLoop;\n\n const offsetX = globalInterpolation.interpolate(interpolationConfig);\n\n return Animated.divide(offsetX, itemWidth);\n }, [\n globalInterpolation,\n interpolationConfigOnLoop,\n interpolationConfigOnNoLoop,\n itemWidth,\n loop,\n ]);\n};\n"],"mappings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GCiB,2BAHD,EAICzB,SAJD,EAKCG,IALD,CARI,CAAP;AAeH;;AAAA"}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { useEffect } from 'react';
|
|
2
|
-
export default function useDimensionChangeReaction(params) {
|
|
3
|
-
const {
|
|
4
|
-
controlledTx,
|
|
5
|
-
currentIndex,
|
|
6
|
-
itemWidth
|
|
7
|
-
} = params;
|
|
8
|
-
useEffect(() => {
|
|
9
|
-
const newTx = -currentIndex * itemWidth;
|
|
10
|
-
controlledTx.setValue(newTx);
|
|
11
|
-
}, [controlledTx, currentIndex, itemWidth]);
|
|
12
|
-
}
|
|
13
|
-
;
|
|
14
|
-
//# sourceMappingURL=useDimensionChangeReaction.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["useEffect","useDimensionChangeReaction","params","controlledTx","currentIndex","itemWidth","newTx","setValue"],"sources":["useDimensionChangeReaction.ts"],"sourcesContent":["import { useEffect } from 'react';\nimport { Animated } from 'react-native';\n\nexport interface Parameters {\n controlledTx: Animated.AnimatedValue;\n currentIndex: number;\n itemWidth: number;\n}\n\nexport default function useDimensionChangeReaction(params: Parameters) {\n const {\n controlledTx,\n currentIndex,\n itemWidth,\n } = params;\n\n useEffect(() => {\n const newTx = -currentIndex * itemWidth;\n controlledTx.setValue(newTx);\n }, [\n controlledTx,\n currentIndex,\n itemWidth,\n ]);\n};\n"],"mappings":"AAAA,SAASA,SAAT,QAA0B,OAA1B;AASA,eAAe,SAASC,0BAAT,CAAoCC,MAApC,EAAwD;EACnE,MAAM;IACFC,YADE;IAEFC,YAFE;IAGFC;EAHE,IAIFH,MAJJ;EAMAF,SAAS,CAAC,MAAM;IACZ,MAAMM,KAAK,GAAG,CAACF,YAAD,GAAgBC,SAA9B;IACAF,YAAY,CAACI,QAAb,CAAsBD,KAAtB;EACH,CAHQ,EAGN,CACCH,YADD,EAECC,YAFD,EAGCC,SAHD,CAHM,CAAT;AAQH;AAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["useContext","useMemo","Animated","InternalContext","OVERSCROLL_FRICTION_FACTOR","useItemInterpolation","index","itemWidth","data","globalInterpolation","loop","numberOfData","length","interpolationConfigOnLoop","lastIndex","maxWidth","Math","abs","halfOfItemWidth","positiveCount","round","startPosition","max","min","inputRange","Number","MIN_VALUE","outputRange","extrapolate","interpolationConfigOnNoLoop","friction","interpolationConfig","offsetX","interpolate","divide"],"sources":["useItemInterpolation.ts"],"sourcesContent":["import { useContext, useMemo } from 'react';\nimport { Animated } from 'react-native';\nimport { InternalContext } from '../components';\n\nconst OVERSCROLL_FRICTION_FACTOR = 4;\n\nexport default function useItemInterpolation(index: number): Animated.AnimatedInterpolation {\n const {\n itemWidth,\n data,\n globalInterpolation,\n loop,\n } = useContext(InternalContext);\n\n const numberOfData = data.length;\n\n const interpolationConfigOnLoop = useMemo<Animated.InterpolationConfigType>(() => {\n const lastIndex = numberOfData - 1;\n const maxWidth = Math.abs(itemWidth * numberOfData);\n const halfOfItemWidth = 0.5 * itemWidth;\n\n const positiveCount = Math.round(lastIndex / 2);\n const startPosition = index > positiveCount\n ? (index - numberOfData) * itemWidth\n : itemWidth * index;\n\n const max = positiveCount * itemWidth;\n const min = -((lastIndex - positiveCount) * itemWidth);\n\n const inputRange = [\n -maxWidth,\n min - halfOfItemWidth - startPosition - Number.MIN_VALUE,\n min - halfOfItemWidth - startPosition,\n 0,\n max + halfOfItemWidth - startPosition,\n max + halfOfItemWidth - startPosition + Number.MIN_VALUE,\n maxWidth,\n ];\n\n const outputRange = [\n startPosition,\n max + halfOfItemWidth - Number.MIN_VALUE,\n min - halfOfItemWidth,\n startPosition,\n max + halfOfItemWidth,\n min - halfOfItemWidth + Number.MIN_VALUE,\n startPosition,\n ];\n\n return {\n inputRange,\n outputRange,\n extrapolate: 'clamp',\n };\n }, [\n index,\n itemWidth,\n numberOfData,\n ]);\n\n const interpolationConfigOnNoLoop = useMemo<Animated.InterpolationConfigType>(() => {\n const lastIndex = numberOfData - 1;\n const maxWidth = itemWidth * lastIndex;\n const startPosition = itemWidth * index;\n const friction = itemWidth / OVERSCROLL_FRICTION_FACTOR;\n\n const inputRange = [\n -(maxWidth + itemWidth), // overscroll\n -maxWidth,\n 0,\n itemWidth, // overscroll\n ];\n\n const outputRange = [\n -maxWidth + startPosition - friction,\n -maxWidth + startPosition,\n startPosition,\n startPosition + friction,\n ];\n\n return {\n inputRange,\n outputRange,\n extrapolate: 'clamp',\n };\n }, [\n index,\n itemWidth,\n numberOfData,\n ]);\n\n return useMemo(() => {\n const interpolationConfig = loop\n ? interpolationConfigOnLoop\n : interpolationConfigOnNoLoop;\n\n const offsetX = globalInterpolation.interpolate(interpolationConfig);\n\n return Animated.divide(offsetX, itemWidth);\n }, [\n globalInterpolation,\n interpolationConfigOnLoop,\n interpolationConfigOnNoLoop,\n itemWidth,\n loop,\n ]);\n};\n"],"mappings":"AAAA,SAASA,UAAT,EAAqBC,OAArB,QAAoC,OAApC;AACA,SAASC,QAAT,QAAyB,cAAzB;AACA,SAASC,eAAT,QAAgC,eAAhC;AAEA,MAAMC,0BAA0B,GAAG,CAAnC;AAEA,eAAe,SAASC,oBAAT,CAA8BC,KAA9B,EAA6E;EACxF,MAAM;IACFC,SADE;IAEFC,IAFE;IAGFC,mBAHE;IAIFC;EAJE,IAKFV,UAAU,CAACG,eAAD,CALd;EAOA,MAAMQ,YAAY,GAAGH,IAAI,CAACI,MAA1B;EAEA,MAAMC,yBAAyB,GAAGZ,OAAO,CAAmC,MAAM;IAC9E,MAAMa,SAAS,GAAGH,YAAY,GAAG,CAAjC;IACA,MAAMI,QAAQ,GAAGC,IAAI,CAACC,GAAL,CAASV,SAAS,GAAGI,YAArB,CAAjB;IACA,MAAMO,eAAe,GAAG,MAAMX,SAA9B;IAEA,MAAMY,aAAa,GAAGH,IAAI,CAACI,KAAL,CAAWN,SAAS,GAAG,CAAvB,CAAtB;IACA,MAAMO,aAAa,GAAGf,KAAK,GAAGa,aAA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,SAJe,CAIJ;IAJI,CAAnB;IAOA,MAAMoB,WAAW,GAAG,CAChB,CAACZ,QAAD,GAAYM,aAAZ,GAA4BS,QADZ,EAEhB,CAACf,QAAD,GAAYM,aAFI,EAGhBA,aAHgB,EAIhBA,aAAa,GAAGS,QAJA,CAApB;IAOA,OAAO;MACHN,UADG;MAEHG,WAFG;MAGHC,WAAW,EAAE;IAHV,CAAP;EAKH,CAzB0C,EAyBxC,CACCtB,KADD,EAECC,SAFD,EAGCI,YAHD,CAzBwC,CAA3C;EA+BA,OAAOV,OAAO,CAAC,MAAM;IACjB,MAAM8B,mBAAmB,GAAGrB,IAAI,GAC1BG,yBAD0B,GAE1BgB,2BAFN;IAIA,MAAMG,OAAO,GAAGvB,mBAAmB,CAACwB,WAApB,CAAgCF,mBAAhC,CAAhB;IAEA,OAAO7B,QAAQ,CAACgC,MAAT,CAAgBF,OAAhB,EAAyBzB,SAAzB,CAAP;EACH,CARa,EAQX,CACCE,mBADD,EAECI,yBAFD,EAGCgB,2BAHD,EAICtB,SAJD,EAKCG,IALD,CARW,CAAd;AAeH;AAAA"}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { useEffect } from 'react';
|
|
2
|
-
import { Animated } from 'react-native';
|
|
3
|
-
|
|
4
|
-
export interface Parameters {
|
|
5
|
-
controlledTx: Animated.AnimatedValue;
|
|
6
|
-
currentIndex: number;
|
|
7
|
-
itemWidth: number;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export default function useDimensionChangeReaction(params: Parameters) {
|
|
11
|
-
const {
|
|
12
|
-
controlledTx,
|
|
13
|
-
currentIndex,
|
|
14
|
-
itemWidth,
|
|
15
|
-
} = params;
|
|
16
|
-
|
|
17
|
-
useEffect(() => {
|
|
18
|
-
const newTx = -currentIndex * itemWidth;
|
|
19
|
-
controlledTx.setValue(newTx);
|
|
20
|
-
}, [
|
|
21
|
-
controlledTx,
|
|
22
|
-
currentIndex,
|
|
23
|
-
itemWidth,
|
|
24
|
-
]);
|
|
25
|
-
};
|