react-native-reanimated-carousel 4.0.0-alpha.5 → 4.0.0-alpha.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/lib/commonjs/{layouts → components}/BaseLayout.js +4 -2
- package/lib/commonjs/components/BaseLayout.js.map +1 -0
- package/lib/commonjs/components/Carousel.js +4 -3
- package/lib/commonjs/components/Carousel.js.map +1 -1
- package/lib/commonjs/components/ScrollViewGesture.js +34 -30
- package/lib/commonjs/components/ScrollViewGesture.js.map +1 -1
- package/lib/commonjs/hooks/useLayoutConfig.js.map +1 -1
- package/lib/commonjs/hooks/useOffsetX.js +9 -6
- package/lib/commonjs/hooks/useOffsetX.js.map +1 -1
- package/lib/commonjs/hooks/useOffsetX.test.js +53 -0
- package/lib/commonjs/hooks/useOffsetX.test.js.map +1 -0
- package/lib/commonjs/hooks/usePanGestureProxy.js +84 -0
- package/lib/commonjs/hooks/usePanGestureProxy.js.map +1 -0
- package/lib/commonjs/hooks/usePanGestureProxy.test.js +397 -0
- package/lib/commonjs/hooks/usePanGestureProxy.test.js.map +1 -0
- package/lib/commonjs/hooks/useUpdateGestureConfig.js.map +1 -1
- package/lib/commonjs/hooks/useVisibleRanges.js +17 -6
- package/lib/commonjs/hooks/useVisibleRanges.js.map +1 -1
- package/lib/commonjs/hooks/useVisibleRanges.test.js +162 -0
- package/lib/commonjs/hooks/useVisibleRanges.test.js.map +1 -0
- package/lib/module/{layouts → components}/BaseLayout.js +4 -2
- package/lib/module/components/BaseLayout.js.map +1 -0
- package/lib/module/components/Carousel.js +3 -2
- package/lib/module/components/Carousel.js.map +1 -1
- package/lib/module/components/ScrollViewGesture.js +36 -31
- package/lib/module/components/ScrollViewGesture.js.map +1 -1
- package/lib/module/hooks/useLayoutConfig.js.map +1 -1
- package/lib/module/hooks/useOffsetX.js +9 -6
- package/lib/module/hooks/useOffsetX.js.map +1 -1
- package/lib/module/hooks/useOffsetX.test.js +48 -0
- package/lib/module/hooks/useOffsetX.test.js.map +1 -0
- package/lib/module/hooks/usePanGestureProxy.js +71 -0
- package/lib/module/hooks/usePanGestureProxy.js.map +1 -0
- package/lib/module/hooks/usePanGestureProxy.test.js +383 -0
- package/lib/module/hooks/usePanGestureProxy.test.js.map +1 -0
- package/lib/module/hooks/useUpdateGestureConfig.js.map +1 -1
- package/lib/module/hooks/useVisibleRanges.js +17 -6
- package/lib/module/hooks/useVisibleRanges.js.map +1 -1
- package/lib/module/hooks/useVisibleRanges.test.js +157 -0
- package/lib/module/hooks/useVisibleRanges.test.js.map +1 -0
- package/lib/typescript/hooks/useLayoutConfig.d.ts +1 -1
- package/lib/typescript/hooks/useOffsetX.test.d.ts +1 -0
- package/lib/typescript/hooks/usePanGestureProxy.d.ts +9 -0
- package/lib/typescript/hooks/usePanGestureProxy.test.d.ts +1 -0
- package/lib/typescript/hooks/useUpdateGestureConfig.d.ts +3 -2
- package/lib/typescript/hooks/useVisibleRanges.d.ts +1 -0
- package/lib/typescript/hooks/useVisibleRanges.test.d.ts +1 -0
- package/lib/typescript/types.d.ts +5 -0
- package/package.json +2 -1
- package/src/{layouts → components}/BaseLayout.tsx +10 -8
- package/src/components/Carousel.tsx +2 -1
- package/src/components/ScrollViewGesture.tsx +48 -43
- package/src/hooks/useLayoutConfig.ts +1 -1
- package/src/hooks/useOffsetX.test.ts +54 -0
- package/src/hooks/useOffsetX.ts +33 -31
- package/src/hooks/usePanGestureProxy.test.tsx +377 -0
- package/src/hooks/usePanGestureProxy.ts +110 -0
- package/src/hooks/useUpdateGestureConfig.ts +4 -2
- package/src/hooks/useVisibleRanges.test.tsx +179 -0
- package/src/hooks/useVisibleRanges.tsx +23 -7
- package/src/types.ts +5 -0
- package/lib/commonjs/layouts/BaseLayout.js.map +0 -1
- package/lib/commonjs/layouts/ParallaxLayout.js +0 -84
- package/lib/commonjs/layouts/ParallaxLayout.js.map +0 -1
- package/lib/module/layouts/BaseLayout.js.map +0 -1
- package/lib/module/layouts/ParallaxLayout.js +0 -61
- package/lib/module/layouts/ParallaxLayout.js.map +0 -1
- package/lib/typescript/layouts/ParallaxLayout.d.ts +0 -13
- package/src/layouts/ParallaxLayout.tsx +0 -141
- /package/lib/typescript/{layouts → components}/BaseLayout.d.ts +0 -0
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
import { useSharedValue } from "react-native-reanimated";
|
|
2
|
+
|
|
3
|
+
import { renderHook } from "@testing-library/react-hooks";
|
|
4
|
+
|
|
5
|
+
import { useVisibleRanges } from "./useVisibleRanges";
|
|
6
|
+
|
|
7
|
+
const viewSize = 393;
|
|
8
|
+
|
|
9
|
+
describe("useVisibleRanges", () => {
|
|
10
|
+
it("should only display the front of the list when loop is false", async () => {
|
|
11
|
+
const hook = renderHook(() => {
|
|
12
|
+
const translation = useSharedValue(-0);
|
|
13
|
+
const range = useVisibleRanges({
|
|
14
|
+
total: 10,
|
|
15
|
+
translation,
|
|
16
|
+
viewSize,
|
|
17
|
+
windowSize: 4,
|
|
18
|
+
loop: false,
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
return range;
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
const expected = hook.result.current.value;
|
|
25
|
+
|
|
26
|
+
expect(expected).toMatchInlineSnapshot(`
|
|
27
|
+
{
|
|
28
|
+
"negativeRange": [
|
|
29
|
+
-3,
|
|
30
|
+
0,
|
|
31
|
+
],
|
|
32
|
+
"positiveRange": [
|
|
33
|
+
0,
|
|
34
|
+
3,
|
|
35
|
+
],
|
|
36
|
+
}
|
|
37
|
+
`);
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it("should display the rear of the list and the front of the list when loop is true", async () => {
|
|
41
|
+
const hook = renderHook(() => {
|
|
42
|
+
const translation = useSharedValue(-0);
|
|
43
|
+
const range = useVisibleRanges({
|
|
44
|
+
total: 10,
|
|
45
|
+
translation,
|
|
46
|
+
viewSize,
|
|
47
|
+
windowSize: 4,
|
|
48
|
+
loop: true,
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
return range;
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
const expected = hook.result.current.value;
|
|
55
|
+
|
|
56
|
+
expect(expected).toMatchInlineSnapshot(`
|
|
57
|
+
{
|
|
58
|
+
"negativeRange": [
|
|
59
|
+
8,
|
|
60
|
+
9,
|
|
61
|
+
],
|
|
62
|
+
"positiveRange": [
|
|
63
|
+
0,
|
|
64
|
+
2,
|
|
65
|
+
],
|
|
66
|
+
}
|
|
67
|
+
`);
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
it("should shows the increased range of the list when the loop is false and swiped the carousel.", async () => {
|
|
71
|
+
const slide0hook = renderHook(() => {
|
|
72
|
+
const translation = useSharedValue(-0 * viewSize);
|
|
73
|
+
const range = useVisibleRanges({
|
|
74
|
+
total: 10,
|
|
75
|
+
translation,
|
|
76
|
+
viewSize,
|
|
77
|
+
windowSize: 4,
|
|
78
|
+
loop: false,
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
return range;
|
|
82
|
+
}).result.current.value;
|
|
83
|
+
|
|
84
|
+
const slide1hook = renderHook(() => {
|
|
85
|
+
const translation = useSharedValue(-1 * viewSize);
|
|
86
|
+
const range = useVisibleRanges({
|
|
87
|
+
total: 10,
|
|
88
|
+
translation,
|
|
89
|
+
viewSize,
|
|
90
|
+
windowSize: 4,
|
|
91
|
+
loop: false,
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
return range;
|
|
95
|
+
}).result.current.value;
|
|
96
|
+
|
|
97
|
+
const slide2hook = renderHook(() => {
|
|
98
|
+
const translation = useSharedValue(-2 * viewSize);
|
|
99
|
+
const range = useVisibleRanges({
|
|
100
|
+
total: 10,
|
|
101
|
+
translation,
|
|
102
|
+
viewSize,
|
|
103
|
+
windowSize: 4,
|
|
104
|
+
loop: false,
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
return range;
|
|
108
|
+
}).result.current.value;
|
|
109
|
+
|
|
110
|
+
const slide3hook = renderHook(() => {
|
|
111
|
+
const translation = useSharedValue(-3 * viewSize);
|
|
112
|
+
const range = useVisibleRanges({
|
|
113
|
+
total: 10,
|
|
114
|
+
translation,
|
|
115
|
+
viewSize,
|
|
116
|
+
windowSize: 4,
|
|
117
|
+
loop: false,
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
return range;
|
|
121
|
+
}).result.current.value;
|
|
122
|
+
|
|
123
|
+
// [0,3] Display the 0,1,2,3 items.
|
|
124
|
+
expect(slide0hook).toMatchInlineSnapshot(`
|
|
125
|
+
{
|
|
126
|
+
"negativeRange": [
|
|
127
|
+
-3,
|
|
128
|
+
0,
|
|
129
|
+
],
|
|
130
|
+
"positiveRange": [
|
|
131
|
+
0,
|
|
132
|
+
3,
|
|
133
|
+
],
|
|
134
|
+
}
|
|
135
|
+
`);
|
|
136
|
+
|
|
137
|
+
// [1,4] Display the 1,2,3,4 items.
|
|
138
|
+
expect(slide1hook).toMatchInlineSnapshot(`
|
|
139
|
+
{
|
|
140
|
+
"negativeRange": [
|
|
141
|
+
-2,
|
|
142
|
+
1,
|
|
143
|
+
],
|
|
144
|
+
"positiveRange": [
|
|
145
|
+
1,
|
|
146
|
+
4,
|
|
147
|
+
],
|
|
148
|
+
}
|
|
149
|
+
`);
|
|
150
|
+
|
|
151
|
+
// [2,5] Display the 2,3,4,5 items.
|
|
152
|
+
expect(slide2hook).toMatchInlineSnapshot(`
|
|
153
|
+
{
|
|
154
|
+
"negativeRange": [
|
|
155
|
+
-1,
|
|
156
|
+
2,
|
|
157
|
+
],
|
|
158
|
+
"positiveRange": [
|
|
159
|
+
2,
|
|
160
|
+
5,
|
|
161
|
+
],
|
|
162
|
+
}
|
|
163
|
+
`);
|
|
164
|
+
|
|
165
|
+
// [3.6] Display the 3,4,5,6 items.
|
|
166
|
+
expect(slide3hook).toMatchInlineSnapshot(`
|
|
167
|
+
{
|
|
168
|
+
"negativeRange": [
|
|
169
|
+
0,
|
|
170
|
+
3,
|
|
171
|
+
],
|
|
172
|
+
"positiveRange": [
|
|
173
|
+
3,
|
|
174
|
+
6,
|
|
175
|
+
],
|
|
176
|
+
}
|
|
177
|
+
`);
|
|
178
|
+
});
|
|
179
|
+
});
|
|
@@ -11,12 +11,14 @@ export function useVisibleRanges(options: {
|
|
|
11
11
|
viewSize: number
|
|
12
12
|
windowSize?: number
|
|
13
13
|
translation: Animated.SharedValue<number>
|
|
14
|
+
loop?: boolean
|
|
14
15
|
}): IVisibleRanges {
|
|
15
16
|
const {
|
|
16
17
|
total = 0,
|
|
17
18
|
viewSize,
|
|
18
19
|
translation,
|
|
19
20
|
windowSize: _windowSize = 0,
|
|
21
|
+
loop,
|
|
20
22
|
} = options;
|
|
21
23
|
|
|
22
24
|
const windowSize = total <= _windowSize ? total : _windowSize;
|
|
@@ -24,16 +26,29 @@ export function useVisibleRanges(options: {
|
|
|
24
26
|
const ranges = useDerivedValue(() => {
|
|
25
27
|
const positiveCount = Math.round(windowSize / 2);
|
|
26
28
|
const negativeCount = windowSize - positiveCount;
|
|
27
|
-
|
|
28
|
-
|
|
29
|
+
|
|
30
|
+
let currentIndex = Math.round(-translation.value / viewSize);
|
|
31
|
+
currentIndex = currentIndex < 0 ? (currentIndex % total) + total : currentIndex;
|
|
32
|
+
|
|
33
|
+
if (!loop) {
|
|
34
|
+
// Adjusting negative range if the carousel is not loopable.
|
|
35
|
+
// So, It will be only displayed the positive items.
|
|
36
|
+
return {
|
|
37
|
+
negativeRange: [0 + currentIndex - (windowSize - 1), 0 + currentIndex],
|
|
38
|
+
positiveRange: [0 + currentIndex, windowSize - 1 + currentIndex],
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
|
|
29
42
|
const negativeRange = [
|
|
30
|
-
(
|
|
31
|
-
(
|
|
43
|
+
(currentIndex - negativeCount + total) % total,
|
|
44
|
+
(currentIndex - 1 + total) % total,
|
|
32
45
|
];
|
|
46
|
+
|
|
33
47
|
const positiveRange = [
|
|
34
|
-
(
|
|
35
|
-
(
|
|
48
|
+
(currentIndex + total) % total,
|
|
49
|
+
(currentIndex + positiveCount + total) % total,
|
|
36
50
|
];
|
|
51
|
+
|
|
37
52
|
if (negativeRange[0] < total && negativeRange[0] > negativeRange[1]) {
|
|
38
53
|
negativeRange[1] = total - 1;
|
|
39
54
|
positiveRange[0] = 0;
|
|
@@ -42,8 +57,9 @@ export function useVisibleRanges(options: {
|
|
|
42
57
|
negativeRange[1] = total - 1;
|
|
43
58
|
positiveRange[0] = 0;
|
|
44
59
|
}
|
|
60
|
+
|
|
45
61
|
return { negativeRange, positiveRange };
|
|
46
|
-
}, [total, windowSize, translation]);
|
|
62
|
+
}, [loop, total, windowSize, translation]);
|
|
47
63
|
|
|
48
64
|
return ranges;
|
|
49
65
|
}
|
package/src/types.ts
CHANGED
|
@@ -157,6 +157,11 @@ export type TCarouselProps<T = any> = {
|
|
|
157
157
|
* props.vertical = false => maxScrollDistancePerSwipeX
|
|
158
158
|
* */
|
|
159
159
|
maxScrollDistancePerSwipe?: number
|
|
160
|
+
/**
|
|
161
|
+
* @experimental This API will be changed in the future.
|
|
162
|
+
* If positive, the carousel will scroll to the positive direction and vice versa.
|
|
163
|
+
* */
|
|
164
|
+
fixedDirection?: "positive" | "negative"
|
|
160
165
|
/**
|
|
161
166
|
* Custom carousel config.
|
|
162
167
|
*/
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["BaseLayout.tsx"],"names":["BaseLayout","props","mounted","handlerOffset","index","children","visibleRanges","animationStyle","context","React","useContext","CTX","loop","dataLength","width","height","vertical","customConfig","mode","modeConfig","size","shouldUpdate","setShouldUpdate","useState","offsetXConfig","snapDirection","showLength","type","viewCount","x","animationValue","value","animatedStyle","updateView","useCallback","negativeRange","positiveRange","current","position"],"mappings":";;;;;;;AAAA;;AAGA;;AASA;;AACA;;AAEA;;AAEA;;;;;;;;AAIO,MAAMA,UAQX,GAAIC,KAAD,IAAW;AACd,QAAMC,OAAO,GAAG,uCAAhB;AACA,QAAM;AAAEC,IAAAA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F;AAsBD,CAtGM","sourcesContent":["import React from \"react\";\nimport type { ViewStyle } from \"react-native\";\nimport type { AnimatedStyleProp } from \"react-native-reanimated\";\nimport Animated, {\n runOnJS,\n useAnimatedReaction,\n useAnimatedStyle,\n useDerivedValue,\n} from \"react-native-reanimated\";\n\nimport type { ILayoutConfig } from \"./stack\";\n\nimport { LazyView } from \"../components/LazyView\";\nimport { useCheckMounted } from \"../hooks/useCheckMounted\";\nimport type { IOpts } from \"../hooks/useOffsetX\";\nimport { useOffsetX } from \"../hooks/useOffsetX\";\nimport type { IVisibleRanges } from \"../hooks/useVisibleRanges\";\nimport { CTX } from \"../store\";\n\nexport type TAnimationStyle = (value: number) => AnimatedStyleProp<ViewStyle>;\n\nexport const BaseLayout: React.FC<{\n index: number\n handlerOffset: Animated.SharedValue<number>\n visibleRanges: IVisibleRanges\n animationStyle: TAnimationStyle\n children: (ctx: {\n animationValue: Animated.SharedValue<number>\n }) => React.ReactElement\n}> = (props) => {\n const mounted = useCheckMounted();\n const { handlerOffset, index, children, visibleRanges, animationStyle }\n = props;\n\n const context = React.useContext(CTX);\n const {\n props: {\n loop,\n dataLength,\n width,\n height,\n vertical,\n customConfig,\n mode,\n modeConfig,\n },\n } = context;\n const size = vertical ? height : width;\n const [shouldUpdate, setShouldUpdate] = React.useState(false);\n let offsetXConfig: IOpts = {\n handlerOffset,\n index,\n size,\n dataLength,\n loop,\n ...(typeof customConfig === \"function\" ? customConfig() : {}),\n };\n\n if (mode === \"horizontal-stack\") {\n const { snapDirection, showLength } = modeConfig as ILayoutConfig;\n\n offsetXConfig = {\n handlerOffset,\n index,\n size,\n dataLength,\n loop,\n type: snapDirection === \"right\" ? \"negative\" : \"positive\",\n viewCount: showLength,\n };\n }\n\n const x = useOffsetX(offsetXConfig, visibleRanges);\n const animationValue = useDerivedValue(() => x.value / size, [x, size]);\n const animatedStyle = useAnimatedStyle(\n () => animationStyle(x.value / size),\n [animationStyle],\n );\n\n const updateView = React.useCallback(\n (negativeRange: number[], positiveRange: number[]) => {\n mounted.current\n && setShouldUpdate(\n (index >= negativeRange[0] && index <= negativeRange[1])\n || (index >= positiveRange[0] && index <= positiveRange[1]),\n );\n },\n [index, mounted],\n );\n\n useAnimatedReaction(\n () => visibleRanges.value,\n () => {\n runOnJS(updateView)(\n visibleRanges.value.negativeRange,\n visibleRanges.value.positiveRange,\n );\n },\n [visibleRanges.value],\n );\n\n return (\n <Animated.View\n style={[\n {\n width: width || \"100%\",\n height: height || \"100%\",\n position: \"absolute\",\n },\n animatedStyle,\n ]}\n /**\n * We use this testID to know when the carousel item is ready to be tested in test.\n * e.g.\n * The testID of first item will be changed to __CAROUSEL_ITEM_0_READY__ from __CAROUSEL_ITEM_0_NOT_READY__ when the item is ready.\n * */\n testID={`__CAROUSEL_ITEM_${index}_${shouldUpdate ? \"READY\" : \"NOT_READY\"}__`}\n >\n <LazyView shouldUpdate={shouldUpdate}>\n {children({ animationValue })}\n </LazyView>\n </Animated.View>\n );\n};\n"]}
|
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.ParallaxLayout = void 0;
|
|
7
|
-
|
|
8
|
-
var _react = _interopRequireDefault(require("react"));
|
|
9
|
-
|
|
10
|
-
var _reactNativeReanimated = _interopRequireWildcard(require("react-native-reanimated"));
|
|
11
|
-
|
|
12
|
-
var _LazyView = require("../components/LazyView");
|
|
13
|
-
|
|
14
|
-
var _useOffsetX = require("../hooks/useOffsetX");
|
|
15
|
-
|
|
16
|
-
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
|
-
|
|
18
|
-
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
|
-
|
|
20
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
21
|
-
|
|
22
|
-
const ParallaxLayout = props => {
|
|
23
|
-
const {
|
|
24
|
-
handlerOffset,
|
|
25
|
-
parallaxScrollingOffset = 100,
|
|
26
|
-
parallaxScrollingScale = 0.8,
|
|
27
|
-
parallaxAdjacentItemScale = parallaxScrollingScale ** 2,
|
|
28
|
-
index,
|
|
29
|
-
width,
|
|
30
|
-
height,
|
|
31
|
-
loop,
|
|
32
|
-
dataLength,
|
|
33
|
-
children,
|
|
34
|
-
visibleRanges,
|
|
35
|
-
vertical
|
|
36
|
-
} = props;
|
|
37
|
-
|
|
38
|
-
const [shouldUpdate, setShouldUpdate] = _react.default.useState(false);
|
|
39
|
-
|
|
40
|
-
const size = props.vertical ? props.height : props.width;
|
|
41
|
-
const x = (0, _useOffsetX.useOffsetX)({
|
|
42
|
-
handlerOffset,
|
|
43
|
-
index,
|
|
44
|
-
size,
|
|
45
|
-
dataLength,
|
|
46
|
-
loop
|
|
47
|
-
}, visibleRanges);
|
|
48
|
-
const offsetXStyle = (0, _reactNativeReanimated.useAnimatedStyle)(() => {
|
|
49
|
-
const value = x.value / size;
|
|
50
|
-
const translate = (0, _reactNativeReanimated.interpolate)(value, [-1, 0, 1], [-size + parallaxScrollingOffset, 0, size - parallaxScrollingOffset], _reactNativeReanimated.Extrapolate.EXTEND);
|
|
51
|
-
const zIndex = (0, _reactNativeReanimated.interpolate)(value, [-1, 0, 1], [0, size, 0], _reactNativeReanimated.Extrapolate.CLAMP);
|
|
52
|
-
const scale = (0, _reactNativeReanimated.interpolate)(value, [-1, 0, 1], [parallaxAdjacentItemScale, parallaxScrollingScale, parallaxAdjacentItemScale], _reactNativeReanimated.Extrapolate.CLAMP);
|
|
53
|
-
return {
|
|
54
|
-
transform: [vertical ? {
|
|
55
|
-
translateY: translate
|
|
56
|
-
} : {
|
|
57
|
-
translateX: translate
|
|
58
|
-
}, {
|
|
59
|
-
scale
|
|
60
|
-
}],
|
|
61
|
-
zIndex
|
|
62
|
-
};
|
|
63
|
-
}, [loop, vertical, parallaxScrollingOffset]);
|
|
64
|
-
|
|
65
|
-
const updateView = _react.default.useCallback((negativeRange, positiveRange) => {
|
|
66
|
-
setShouldUpdate(index >= negativeRange[0] && index <= negativeRange[1] || index >= positiveRange[0] && index <= positiveRange[1]);
|
|
67
|
-
}, [index]);
|
|
68
|
-
|
|
69
|
-
(0, _reactNativeReanimated.useAnimatedReaction)(() => visibleRanges.value, () => {
|
|
70
|
-
(0, _reactNativeReanimated.runOnJS)(updateView)(visibleRanges.value.negativeRange, visibleRanges.value.positiveRange);
|
|
71
|
-
}, [visibleRanges.value]);
|
|
72
|
-
return /*#__PURE__*/_react.default.createElement(_reactNativeReanimated.default.View, {
|
|
73
|
-
style: [{
|
|
74
|
-
width: width || "100%",
|
|
75
|
-
height: height || "100%",
|
|
76
|
-
position: "absolute"
|
|
77
|
-
}, offsetXStyle]
|
|
78
|
-
}, /*#__PURE__*/_react.default.createElement(_LazyView.LazyView, {
|
|
79
|
-
shouldUpdate: shouldUpdate
|
|
80
|
-
}, children));
|
|
81
|
-
};
|
|
82
|
-
|
|
83
|
-
exports.ParallaxLayout = ParallaxLayout;
|
|
84
|
-
//# sourceMappingURL=ParallaxLayout.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["ParallaxLayout.tsx"],"names":["ParallaxLayout","props","handlerOffset","parallaxScrollingOffset","parallaxScrollingScale","parallaxAdjacentItemScale","index","width","height","loop","dataLength","children","visibleRanges","vertical","shouldUpdate","setShouldUpdate","React","useState","size","x","offsetXStyle","value","translate","Extrapolate","EXTEND","zIndex","CLAMP","scale","transform","translateY","translateX","updateView","useCallback","negativeRange","positiveRange","position"],"mappings":";;;;;;;AACA;;AACA;;AAUA;;AACA;;;;;;;;AAIO,MAAMA,cAQV,GAAIC,KAAD,IAAW;AACf,QAAM;AACJC,IAAAA,aADI;AAEJC,IAAAA,uBAAuB,GAAG,GAFtB;AAGJC,IAAAA,sBAAsB,GAAG,GAHrB;AAIJC,IAAAA,yBAAyB,GAAGD,sBAAsB,IAAI,CAJlD;AAKJE,IAAAA,KALI;AAMJC,IAAAA,KANI;AAOJC,IAAAA,MAPI;AAQJC,IAAAA,IARI;AASJC,IAAAA,UATI;AAUJC,IAAAA,QAVI;AAWJC,IAAAA,aAXI;AAYJC,IAAAA;AAZI,MAaFZ,KAbJ;;AAeA,QAAM,CAACa,YAAD,EAAeC,eAAf,IAAkCC,eAAMC,QAAN,CAAe,KAAf,CAAxC;;AAEA,QAAMC,IAAI,GAAGjB,KAAK,CAACY,QAAN,GAAiBZ,KAAK,CAACO,MAAvB,GAAgCP,KAAK,CAACM,KAAnD;AAEA,QAAMY,CAAC,GAAG,4BACR;AACEjB,IAAAA,aADF;AAEEI,IAAAA,KAFF;AAGEY,IAAAA,IAHF;AAIER,IAAAA,UAJF;AAKED,IAAAA;AALF,GADQ,EAQRG,aARQ,CAAV;AAWA,QAAMQ,YAAY,GAAG,6CAAiB,MAAM;AAC1C,UAAMC,KAAK,GAAGF,CAAC,CAACE,KAAF,GAAUH,IAAxB;AAEA,UAAMI,SAAS,GAAG,wCAChBD,KADgB,EAEhB,CAAC,CAAC,CAAF,EAAK,CAAL,EAAQ,CAAR,CAFgB,E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oBa,aAFtB;AAID,GAPH,EAQE,CAACtB,aAAa,CAACS,KAAf,CARF;AAWA,sBACE,6BAAC,8BAAD,CAAU,IAAV;AACE,IAAA,KAAK,EAAE,CACL;AACEd,MAAAA,KAAK,EAAEA,KAAK,IAAI,MADlB;AAEEC,MAAAA,MAAM,EAAEA,MAAM,IAAI,MAFpB;AAGE2B,MAAAA,QAAQ,EAAE;AAHZ,KADK,EAMLf,YANK;AADT,kBAUE,6BAAC,kBAAD;AAAU,IAAA,YAAY,EAAEN;AAAxB,KAAuCH,QAAvC,CAVF,CADF;AAcD,CA3HM","sourcesContent":["import type { PropsWithChildren } from \"react\";\nimport React from \"react\";\nimport Animated, {\n Extrapolate,\n interpolate,\n runOnJS,\n useAnimatedReaction,\n useAnimatedStyle,\n} from \"react-native-reanimated\";\n\nimport type { ILayoutConfig } from \"./parallax\";\n\nimport { LazyView } from \"../components/LazyView\";\nimport { useOffsetX } from \"../hooks/useOffsetX\";\nimport type { IVisibleRanges } from \"../hooks/useVisibleRanges\";\nimport type { IComputedDirectionTypes } from \"../types\";\n\nexport const ParallaxLayout: React.FC<PropsWithChildren<IComputedDirectionTypes<\n{\n loop?: boolean\n handlerOffset: Animated.SharedValue<number>\n index: number\n dataLength: number\n visibleRanges: IVisibleRanges\n} & ILayoutConfig\n>>> = (props) => {\n const {\n handlerOffset,\n parallaxScrollingOffset = 100,\n parallaxScrollingScale = 0.8,\n parallaxAdjacentItemScale = parallaxScrollingScale ** 2,\n index,\n width,\n height,\n loop,\n dataLength,\n children,\n visibleRanges,\n vertical,\n } = props;\n\n const [shouldUpdate, setShouldUpdate] = React.useState(false);\n\n const size = props.vertical ? props.height : props.width;\n\n const x = useOffsetX(\n {\n handlerOffset,\n index,\n size,\n dataLength,\n loop,\n },\n visibleRanges,\n );\n\n const offsetXStyle = useAnimatedStyle(() => {\n const value = x.value / size;\n\n const translate = interpolate(\n value,\n [-1, 0, 1],\n [\n -size + parallaxScrollingOffset,\n 0,\n size - parallaxScrollingOffset,\n ],\n Extrapolate.EXTEND,\n );\n\n const zIndex = interpolate(\n value,\n [-1, 0, 1],\n [0, size, 0],\n Extrapolate.CLAMP,\n );\n\n const scale = interpolate(\n value,\n [-1, 0, 1],\n [\n parallaxAdjacentItemScale,\n parallaxScrollingScale,\n parallaxAdjacentItemScale,\n ],\n Extrapolate.CLAMP,\n );\n\n return {\n transform: [\n vertical\n ? {\n translateY: translate,\n }\n : {\n translateX: translate,\n },\n {\n scale,\n },\n ],\n zIndex,\n };\n }, [loop, vertical, parallaxScrollingOffset]);\n\n const updateView = React.useCallback(\n (negativeRange: number[], positiveRange: number[]) => {\n setShouldUpdate(\n (index >= negativeRange[0] && index <= negativeRange[1])\n || (index >= positiveRange[0] && index <= positiveRange[1]),\n );\n },\n [index],\n );\n\n useAnimatedReaction(\n () => visibleRanges.value,\n () => {\n runOnJS(updateView)(\n visibleRanges.value.negativeRange,\n visibleRanges.value.positiveRange,\n );\n },\n [visibleRanges.value],\n );\n\n return (\n <Animated.View\n style={[\n {\n width: width || \"100%\",\n height: height || \"100%\",\n position: \"absolute\",\n },\n offsetXStyle,\n ]}\n >\n <LazyView shouldUpdate={shouldUpdate}>{children}</LazyView>\n </Animated.View>\n );\n};\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["BaseLayout.tsx"],"names":["React","Animated","runOnJS","useAnimatedReaction","useAnimatedStyle","useDerivedValue","LazyView","useCheckMounted","useOffsetX","CTX","BaseLayout","props","mounted","handlerOffset","index","children","visibleRanges","animationStyle","context","useContext","loop","dataLength","width","height","vertical","customConfig","mode","modeConfig","size","shouldUpdate","setShouldUpdate","useState","offsetXConfig","snapDirection","showLength","type","viewCount","x","animationValue","value","animatedStyle","updateView","useCallback","negativeRange","positiveRange","current","position"],"mappings":"AAAA,OAAOA,KAAP,MAAkB,OAAlB;AAGA,OAAOC,QAAP,IACEC,OADF,EAEEC,mBAFF,EAGEC,gBAHF,EAIEC,eAJF,QAKO,yBALP;A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AAM,EAAEA,MAAM,IAAI,MAFpB;AAGEuB,MAAAA,QAAQ,EAAE;AAHZ,KADK,EAMLN,aANK;AAQP;AACN;AACA;AACA;AACA;AAbI;AAcE,IAAA,MAAM,EAAG,mBAAkB1B,KAAM,IAAGe,YAAY,GAAG,OAAH,GAAa,WAAY;AAd3E,kBAgBE,oBAAC,QAAD;AAAU,IAAA,YAAY,EAAEA;AAAxB,KACGd,QAAQ,CAAC;AAAEuB,IAAAA;AAAF,GAAD,CADX,CAhBF,CADF;AAsBD,CAtGM","sourcesContent":["import React from \"react\";\nimport type { ViewStyle } from \"react-native\";\nimport type { AnimatedStyleProp } from \"react-native-reanimated\";\nimport Animated, {\n runOnJS,\n useAnimatedReaction,\n useAnimatedStyle,\n useDerivedValue,\n} from \"react-native-reanimated\";\n\nimport type { ILayoutConfig } from \"./stack\";\n\nimport { LazyView } from \"../components/LazyView\";\nimport { useCheckMounted } from \"../hooks/useCheckMounted\";\nimport type { IOpts } from \"../hooks/useOffsetX\";\nimport { useOffsetX } from \"../hooks/useOffsetX\";\nimport type { IVisibleRanges } from \"../hooks/useVisibleRanges\";\nimport { CTX } from \"../store\";\n\nexport type TAnimationStyle = (value: number) => AnimatedStyleProp<ViewStyle>;\n\nexport const BaseLayout: React.FC<{\n index: number\n handlerOffset: Animated.SharedValue<number>\n visibleRanges: IVisibleRanges\n animationStyle: TAnimationStyle\n children: (ctx: {\n animationValue: Animated.SharedValue<number>\n }) => React.ReactElement\n}> = (props) => {\n const mounted = useCheckMounted();\n const { handlerOffset, index, children, visibleRanges, animationStyle }\n = props;\n\n const context = React.useContext(CTX);\n const {\n props: {\n loop,\n dataLength,\n width,\n height,\n vertical,\n customConfig,\n mode,\n modeConfig,\n },\n } = context;\n const size = vertical ? height : width;\n const [shouldUpdate, setShouldUpdate] = React.useState(false);\n let offsetXConfig: IOpts = {\n handlerOffset,\n index,\n size,\n dataLength,\n loop,\n ...(typeof customConfig === \"function\" ? customConfig() : {}),\n };\n\n if (mode === \"horizontal-stack\") {\n const { snapDirection, showLength } = modeConfig as ILayoutConfig;\n\n offsetXConfig = {\n handlerOffset,\n index,\n size,\n dataLength,\n loop,\n type: snapDirection === \"right\" ? \"negative\" : \"positive\",\n viewCount: showLength,\n };\n }\n\n const x = useOffsetX(offsetXConfig, visibleRanges);\n const animationValue = useDerivedValue(() => x.value / size, [x, size]);\n const animatedStyle = useAnimatedStyle(\n () => animationStyle(x.value / size),\n [animationStyle],\n );\n\n const updateView = React.useCallback(\n (negativeRange: number[], positiveRange: number[]) => {\n mounted.current\n && setShouldUpdate(\n (index >= negativeRange[0] && index <= negativeRange[1])\n || (index >= positiveRange[0] && index <= positiveRange[1]),\n );\n },\n [index, mounted],\n );\n\n useAnimatedReaction(\n () => visibleRanges.value,\n () => {\n runOnJS(updateView)(\n visibleRanges.value.negativeRange,\n visibleRanges.value.positiveRange,\n );\n },\n [visibleRanges.value],\n );\n\n return (\n <Animated.View\n style={[\n {\n width: width || \"100%\",\n height: height || \"100%\",\n position: \"absolute\",\n },\n animatedStyle,\n ]}\n /**\n * We use this testID to know when the carousel item is ready to be tested in test.\n * e.g.\n * The testID of first item will be changed to __CAROUSEL_ITEM_0_READY__ from __CAROUSEL_ITEM_0_NOT_READY__ when the item is ready.\n * */\n testID={`__CAROUSEL_ITEM_${index}_${shouldUpdate ? \"READY\" : \"NOT_READY\"}__`}\n >\n <LazyView shouldUpdate={shouldUpdate}>\n {children({ animationValue })}\n </LazyView>\n </Animated.View>\n );\n};\n"]}
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
import Animated, { Extrapolate, interpolate, runOnJS, useAnimatedReaction, useAnimatedStyle } from "react-native-reanimated";
|
|
3
|
-
import { LazyView } from "../components/LazyView";
|
|
4
|
-
import { useOffsetX } from "../hooks/useOffsetX";
|
|
5
|
-
export const ParallaxLayout = props => {
|
|
6
|
-
const {
|
|
7
|
-
handlerOffset,
|
|
8
|
-
parallaxScrollingOffset = 100,
|
|
9
|
-
parallaxScrollingScale = 0.8,
|
|
10
|
-
parallaxAdjacentItemScale = parallaxScrollingScale ** 2,
|
|
11
|
-
index,
|
|
12
|
-
width,
|
|
13
|
-
height,
|
|
14
|
-
loop,
|
|
15
|
-
dataLength,
|
|
16
|
-
children,
|
|
17
|
-
visibleRanges,
|
|
18
|
-
vertical
|
|
19
|
-
} = props;
|
|
20
|
-
const [shouldUpdate, setShouldUpdate] = React.useState(false);
|
|
21
|
-
const size = props.vertical ? props.height : props.width;
|
|
22
|
-
const x = useOffsetX({
|
|
23
|
-
handlerOffset,
|
|
24
|
-
index,
|
|
25
|
-
size,
|
|
26
|
-
dataLength,
|
|
27
|
-
loop
|
|
28
|
-
}, visibleRanges);
|
|
29
|
-
const offsetXStyle = useAnimatedStyle(() => {
|
|
30
|
-
const value = x.value / size;
|
|
31
|
-
const translate = interpolate(value, [-1, 0, 1], [-size + parallaxScrollingOffset, 0, size - parallaxScrollingOffset], Extrapolate.EXTEND);
|
|
32
|
-
const zIndex = interpolate(value, [-1, 0, 1], [0, size, 0], Extrapolate.CLAMP);
|
|
33
|
-
const scale = interpolate(value, [-1, 0, 1], [parallaxAdjacentItemScale, parallaxScrollingScale, parallaxAdjacentItemScale], Extrapolate.CLAMP);
|
|
34
|
-
return {
|
|
35
|
-
transform: [vertical ? {
|
|
36
|
-
translateY: translate
|
|
37
|
-
} : {
|
|
38
|
-
translateX: translate
|
|
39
|
-
}, {
|
|
40
|
-
scale
|
|
41
|
-
}],
|
|
42
|
-
zIndex
|
|
43
|
-
};
|
|
44
|
-
}, [loop, vertical, parallaxScrollingOffset]);
|
|
45
|
-
const updateView = React.useCallback((negativeRange, positiveRange) => {
|
|
46
|
-
setShouldUpdate(index >= negativeRange[0] && index <= negativeRange[1] || index >= positiveRange[0] && index <= positiveRange[1]);
|
|
47
|
-
}, [index]);
|
|
48
|
-
useAnimatedReaction(() => visibleRanges.value, () => {
|
|
49
|
-
runOnJS(updateView)(visibleRanges.value.negativeRange, visibleRanges.value.positiveRange);
|
|
50
|
-
}, [visibleRanges.value]);
|
|
51
|
-
return /*#__PURE__*/React.createElement(Animated.View, {
|
|
52
|
-
style: [{
|
|
53
|
-
width: width || "100%",
|
|
54
|
-
height: height || "100%",
|
|
55
|
-
position: "absolute"
|
|
56
|
-
}, offsetXStyle]
|
|
57
|
-
}, /*#__PURE__*/React.createElement(LazyView, {
|
|
58
|
-
shouldUpdate: shouldUpdate
|
|
59
|
-
}, children));
|
|
60
|
-
};
|
|
61
|
-
//# sourceMappingURL=ParallaxLayout.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["ParallaxLayout.tsx"],"names":["React","Animated","Extrapolate","interpolate","runOnJS","useAnimatedReaction","useAnimatedStyle","LazyView","useOffsetX","ParallaxLayout","props","handlerOffset","parallaxScrollingOffset","parallaxScrollingScale","parallaxAdjacentItemScale","index","width","height","loop","dataLength","children","visibleRanges","vertical","shouldUpdate","setShouldUpdate","useState","size","x","offsetXStyle","value","translate","EXTEND","zIndex","CLAMP","scale","transform","translateY","translateX","updateView","useCallback","negativeRange","positiveRange","position"],"mappings":"AACA,OAAOA,KAAP,MAAkB,OAAlB;AACA,OAAOC,QAAP,IACEC,WADF,EAEEC,WAFF,EAGEC,OAHF,EAIEC,mBAJF,EAKEC,gBALF,QAMO,yBANP;AAUA,SAASC,QAAT,QAAyB,wBAAzB;AACA,SAASC,UAAT,QAA2B,qBAA3B;AAIA,OAAO,MAAMC,cAQV,GAAIC,KAAD,IAAW;AACf,QAAM;AACJC,IAAAA,aADI;AAEJC,IAAAA,uBAAuB,GAAG,GAFtB;AAGJC,IAAAA,sBAAsB,GAAG,GAHrB;AAIJC,IAAAA,yBAAyB,GAAGD,sBAAsB,IAAI,CAJlD;AAKJE,IAAAA,KALI;AAMJC,IAAAA,KANI;AAOJC,IAAAA,MAPI;AAQJC,IAAAA,IARI;AASJC,IAAAA,UATI;AAUJC,IAAAA,QAVI;AAWJC,IAAAA,aAXI;AAY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,EAAEP;AADZ,OALK,EAQT;AACEI,QAAAA;AADF,OARS,CADN;AAaLF,MAAAA;AAbK,KAAP;AAeD,GA/CoC,EA+ClC,CAACd,IAAD,EAAOI,QAAP,EAAiBV,uBAAjB,CA/CkC,CAArC;AAiDA,QAAM0B,UAAU,GAAGtC,KAAK,CAACuC,WAAN,CACjB,CAACC,aAAD,EAA0BC,aAA1B,KAAsD;AACpDjB,IAAAA,eAAe,CACZT,KAAK,IAAIyB,aAAa,CAAC,CAAD,CAAtB,IAA6BzB,KAAK,IAAIyB,aAAa,CAAC,CAAD,CAApD,IACgBzB,KAAK,IAAI0B,aAAa,CAAC,CAAD,CAAtB,IAA6B1B,KAAK,IAAI0B,aAAa,CAAC,CAAD,CAFtD,CAAf;AAID,GANgB,EAOjB,CAAC1B,KAAD,CAPiB,CAAnB;AAUAV,EAAAA,mBAAmB,CACjB,MAAMgB,aAAa,CAACQ,KADH,EAEjB,MAAM;AACJzB,IAAAA,OAAO,CAACkC,UAAD,CAAP,CACEjB,aAAa,CAACQ,KAAd,CAAoBW,aADtB,EAEEnB,aAAa,CAACQ,KAAd,CAAoBY,aAFtB;AAID,GAPgB,EAQjB,CAACpB,aAAa,CAACQ,KAAf,CARiB,CAAnB;AAWA,sBACE,oBAAC,QAAD,CAAU,IAAV;AACE,IAAA,KAAK,EAAE,CACL;AACEb,MAAAA,KAAK,EAAEA,KAAK,IAAI,MADlB;AAEEC,MAAAA,MAAM,EAAEA,MAAM,IAAI,MAFpB;AAGEyB,MAAAA,QAAQ,EAAE;AAHZ,KADK,EAMLd,YANK;AADT,kBAUE,oBAAC,QAAD;AAAU,IAAA,YAAY,EAAEL;AAAxB,KAAuCH,QAAvC,CAVF,CADF;AAcD,CA3HM","sourcesContent":["import type { PropsWithChildren } from \"react\";\nimport React from \"react\";\nimport Animated, {\n Extrapolate,\n interpolate,\n runOnJS,\n useAnimatedReaction,\n useAnimatedStyle,\n} from \"react-native-reanimated\";\n\nimport type { ILayoutConfig } from \"./parallax\";\n\nimport { LazyView } from \"../components/LazyView\";\nimport { useOffsetX } from \"../hooks/useOffsetX\";\nimport type { IVisibleRanges } from \"../hooks/useVisibleRanges\";\nimport type { IComputedDirectionTypes } from \"../types\";\n\nexport const ParallaxLayout: React.FC<PropsWithChildren<IComputedDirectionTypes<\n{\n loop?: boolean\n handlerOffset: Animated.SharedValue<number>\n index: number\n dataLength: number\n visibleRanges: IVisibleRanges\n} & ILayoutConfig\n>>> = (props) => {\n const {\n handlerOffset,\n parallaxScrollingOffset = 100,\n parallaxScrollingScale = 0.8,\n parallaxAdjacentItemScale = parallaxScrollingScale ** 2,\n index,\n width,\n height,\n loop,\n dataLength,\n children,\n visibleRanges,\n vertical,\n } = props;\n\n const [shouldUpdate, setShouldUpdate] = React.useState(false);\n\n const size = props.vertical ? props.height : props.width;\n\n const x = useOffsetX(\n {\n handlerOffset,\n index,\n size,\n dataLength,\n loop,\n },\n visibleRanges,\n );\n\n const offsetXStyle = useAnimatedStyle(() => {\n const value = x.value / size;\n\n const translate = interpolate(\n value,\n [-1, 0, 1],\n [\n -size + parallaxScrollingOffset,\n 0,\n size - parallaxScrollingOffset,\n ],\n Extrapolate.EXTEND,\n );\n\n const zIndex = interpolate(\n value,\n [-1, 0, 1],\n [0, size, 0],\n Extrapolate.CLAMP,\n );\n\n const scale = interpolate(\n value,\n [-1, 0, 1],\n [\n parallaxAdjacentItemScale,\n parallaxScrollingScale,\n parallaxAdjacentItemScale,\n ],\n Extrapolate.CLAMP,\n );\n\n return {\n transform: [\n vertical\n ? {\n translateY: translate,\n }\n : {\n translateX: translate,\n },\n {\n scale,\n },\n ],\n zIndex,\n };\n }, [loop, vertical, parallaxScrollingOffset]);\n\n const updateView = React.useCallback(\n (negativeRange: number[], positiveRange: number[]) => {\n setShouldUpdate(\n (index >= negativeRange[0] && index <= negativeRange[1])\n || (index >= positiveRange[0] && index <= positiveRange[1]),\n );\n },\n [index],\n );\n\n useAnimatedReaction(\n () => visibleRanges.value,\n () => {\n runOnJS(updateView)(\n visibleRanges.value.negativeRange,\n visibleRanges.value.positiveRange,\n );\n },\n [visibleRanges.value],\n );\n\n return (\n <Animated.View\n style={[\n {\n width: width || \"100%\",\n height: height || \"100%\",\n position: \"absolute\",\n },\n offsetXStyle,\n ]}\n >\n <LazyView shouldUpdate={shouldUpdate}>{children}</LazyView>\n </Animated.View>\n );\n};\n"]}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import type { PropsWithChildren } from "react";
|
|
2
|
-
import React from "react";
|
|
3
|
-
import Animated from "react-native-reanimated";
|
|
4
|
-
import type { ILayoutConfig } from "./parallax";
|
|
5
|
-
import type { IVisibleRanges } from "../hooks/useVisibleRanges";
|
|
6
|
-
import type { IComputedDirectionTypes } from "../types";
|
|
7
|
-
export declare const ParallaxLayout: React.FC<PropsWithChildren<IComputedDirectionTypes<{
|
|
8
|
-
loop?: boolean;
|
|
9
|
-
handlerOffset: Animated.SharedValue<number>;
|
|
10
|
-
index: number;
|
|
11
|
-
dataLength: number;
|
|
12
|
-
visibleRanges: IVisibleRanges;
|
|
13
|
-
} & ILayoutConfig>>>;
|
|
@@ -1,141 +0,0 @@
|
|
|
1
|
-
import type { PropsWithChildren } from "react";
|
|
2
|
-
import React from "react";
|
|
3
|
-
import Animated, {
|
|
4
|
-
Extrapolate,
|
|
5
|
-
interpolate,
|
|
6
|
-
runOnJS,
|
|
7
|
-
useAnimatedReaction,
|
|
8
|
-
useAnimatedStyle,
|
|
9
|
-
} from "react-native-reanimated";
|
|
10
|
-
|
|
11
|
-
import type { ILayoutConfig } from "./parallax";
|
|
12
|
-
|
|
13
|
-
import { LazyView } from "../components/LazyView";
|
|
14
|
-
import { useOffsetX } from "../hooks/useOffsetX";
|
|
15
|
-
import type { IVisibleRanges } from "../hooks/useVisibleRanges";
|
|
16
|
-
import type { IComputedDirectionTypes } from "../types";
|
|
17
|
-
|
|
18
|
-
export const ParallaxLayout: React.FC<PropsWithChildren<IComputedDirectionTypes<
|
|
19
|
-
{
|
|
20
|
-
loop?: boolean
|
|
21
|
-
handlerOffset: Animated.SharedValue<number>
|
|
22
|
-
index: number
|
|
23
|
-
dataLength: number
|
|
24
|
-
visibleRanges: IVisibleRanges
|
|
25
|
-
} & ILayoutConfig
|
|
26
|
-
>>> = (props) => {
|
|
27
|
-
const {
|
|
28
|
-
handlerOffset,
|
|
29
|
-
parallaxScrollingOffset = 100,
|
|
30
|
-
parallaxScrollingScale = 0.8,
|
|
31
|
-
parallaxAdjacentItemScale = parallaxScrollingScale ** 2,
|
|
32
|
-
index,
|
|
33
|
-
width,
|
|
34
|
-
height,
|
|
35
|
-
loop,
|
|
36
|
-
dataLength,
|
|
37
|
-
children,
|
|
38
|
-
visibleRanges,
|
|
39
|
-
vertical,
|
|
40
|
-
} = props;
|
|
41
|
-
|
|
42
|
-
const [shouldUpdate, setShouldUpdate] = React.useState(false);
|
|
43
|
-
|
|
44
|
-
const size = props.vertical ? props.height : props.width;
|
|
45
|
-
|
|
46
|
-
const x = useOffsetX(
|
|
47
|
-
{
|
|
48
|
-
handlerOffset,
|
|
49
|
-
index,
|
|
50
|
-
size,
|
|
51
|
-
dataLength,
|
|
52
|
-
loop,
|
|
53
|
-
},
|
|
54
|
-
visibleRanges,
|
|
55
|
-
);
|
|
56
|
-
|
|
57
|
-
const offsetXStyle = useAnimatedStyle(() => {
|
|
58
|
-
const value = x.value / size;
|
|
59
|
-
|
|
60
|
-
const translate = interpolate(
|
|
61
|
-
value,
|
|
62
|
-
[-1, 0, 1],
|
|
63
|
-
[
|
|
64
|
-
-size + parallaxScrollingOffset,
|
|
65
|
-
0,
|
|
66
|
-
size - parallaxScrollingOffset,
|
|
67
|
-
],
|
|
68
|
-
Extrapolate.EXTEND,
|
|
69
|
-
);
|
|
70
|
-
|
|
71
|
-
const zIndex = interpolate(
|
|
72
|
-
value,
|
|
73
|
-
[-1, 0, 1],
|
|
74
|
-
[0, size, 0],
|
|
75
|
-
Extrapolate.CLAMP,
|
|
76
|
-
);
|
|
77
|
-
|
|
78
|
-
const scale = interpolate(
|
|
79
|
-
value,
|
|
80
|
-
[-1, 0, 1],
|
|
81
|
-
[
|
|
82
|
-
parallaxAdjacentItemScale,
|
|
83
|
-
parallaxScrollingScale,
|
|
84
|
-
parallaxAdjacentItemScale,
|
|
85
|
-
],
|
|
86
|
-
Extrapolate.CLAMP,
|
|
87
|
-
);
|
|
88
|
-
|
|
89
|
-
return {
|
|
90
|
-
transform: [
|
|
91
|
-
vertical
|
|
92
|
-
? {
|
|
93
|
-
translateY: translate,
|
|
94
|
-
}
|
|
95
|
-
: {
|
|
96
|
-
translateX: translate,
|
|
97
|
-
},
|
|
98
|
-
{
|
|
99
|
-
scale,
|
|
100
|
-
},
|
|
101
|
-
],
|
|
102
|
-
zIndex,
|
|
103
|
-
};
|
|
104
|
-
}, [loop, vertical, parallaxScrollingOffset]);
|
|
105
|
-
|
|
106
|
-
const updateView = React.useCallback(
|
|
107
|
-
(negativeRange: number[], positiveRange: number[]) => {
|
|
108
|
-
setShouldUpdate(
|
|
109
|
-
(index >= negativeRange[0] && index <= negativeRange[1])
|
|
110
|
-
|| (index >= positiveRange[0] && index <= positiveRange[1]),
|
|
111
|
-
);
|
|
112
|
-
},
|
|
113
|
-
[index],
|
|
114
|
-
);
|
|
115
|
-
|
|
116
|
-
useAnimatedReaction(
|
|
117
|
-
() => visibleRanges.value,
|
|
118
|
-
() => {
|
|
119
|
-
runOnJS(updateView)(
|
|
120
|
-
visibleRanges.value.negativeRange,
|
|
121
|
-
visibleRanges.value.positiveRange,
|
|
122
|
-
);
|
|
123
|
-
},
|
|
124
|
-
[visibleRanges.value],
|
|
125
|
-
);
|
|
126
|
-
|
|
127
|
-
return (
|
|
128
|
-
<Animated.View
|
|
129
|
-
style={[
|
|
130
|
-
{
|
|
131
|
-
width: width || "100%",
|
|
132
|
-
height: height || "100%",
|
|
133
|
-
position: "absolute",
|
|
134
|
-
},
|
|
135
|
-
offsetXStyle,
|
|
136
|
-
]}
|
|
137
|
-
>
|
|
138
|
-
<LazyView shouldUpdate={shouldUpdate}>{children}</LazyView>
|
|
139
|
-
</Animated.View>
|
|
140
|
-
);
|
|
141
|
-
};
|
|
File without changes
|