react-native-reanimated-carousel 3.1.4 → 3.1.5
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/Carousel.js +1 -1
- package/lib/commonjs/Carousel.js.map +1 -1
- package/lib/commonjs/ScrollViewGesture.js +1 -1
- package/lib/commonjs/ScrollViewGesture.js.map +1 -1
- package/lib/commonjs/hooks/useCarouselController.js +1 -1
- package/lib/commonjs/hooks/useCarouselController.js.map +1 -1
- package/lib/commonjs/hooks/useCommonVariables.js +1 -1
- package/lib/commonjs/hooks/useCommonVariables.js.map +1 -1
- package/lib/commonjs/hooks/useInitProps.js +1 -1
- package/lib/commonjs/hooks/useInitProps.js.map +1 -1
- package/lib/commonjs/hooks/useOffsetX.js +1 -1
- package/lib/commonjs/hooks/useOffsetX.js.map +1 -1
- package/lib/commonjs/hooks/useOnProgressChange.js +1 -1
- package/lib/commonjs/hooks/useOnProgressChange.js.map +1 -1
- package/lib/commonjs/hooks/usePropsErrorBoundary.js +1 -1
- package/lib/commonjs/hooks/usePropsErrorBoundary.js.map +1 -1
- package/lib/commonjs/layouts/BaseLayout.js +1 -1
- package/lib/commonjs/layouts/BaseLayout.js.map +1 -1
- package/lib/commonjs/layouts/ParallaxLayout.js +1 -1
- package/lib/commonjs/layouts/ParallaxLayout.js.map +1 -1
- package/lib/module/Carousel.js +17 -10
- package/lib/module/Carousel.js.map +1 -1
- package/lib/module/ScrollViewGesture.js +3 -3
- package/lib/module/ScrollViewGesture.js.map +1 -1
- package/lib/module/hooks/useCarouselController.js +5 -5
- package/lib/module/hooks/useCarouselController.js.map +1 -1
- package/lib/module/hooks/useCommonVariables.js +6 -6
- package/lib/module/hooks/useCommonVariables.js.map +1 -1
- package/lib/module/hooks/useInitProps.js +10 -5
- package/lib/module/hooks/useInitProps.js.map +1 -1
- package/lib/module/hooks/useOffsetX.js +5 -4
- package/lib/module/hooks/useOffsetX.js.map +1 -1
- package/lib/module/hooks/useOnProgressChange.js +1 -2
- package/lib/module/hooks/useOnProgressChange.js.map +1 -1
- package/lib/module/hooks/usePropsErrorBoundary.js +1 -2
- package/lib/module/hooks/usePropsErrorBoundary.js.map +1 -1
- package/lib/module/layouts/BaseLayout.js +3 -3
- package/lib/module/layouts/BaseLayout.js.map +1 -1
- package/lib/module/layouts/ParallaxLayout.js +2 -2
- package/lib/module/layouts/ParallaxLayout.js.map +1 -1
- package/lib/typescript/hooks/useCarouselController.d.ts +1 -1
- package/lib/typescript/hooks/useInitProps.d.ts +2 -0
- package/lib/typescript/hooks/useOffsetX.d.ts +1 -1
- package/lib/typescript/hooks/useOnProgressChange.d.ts +1 -1
- package/lib/typescript/hooks/usePropsErrorBoundary.d.ts +3 -1
- package/lib/typescript/layouts/ParallaxLayout.d.ts +1 -1
- package/package.json +1 -1
- package/src/Carousel.tsx +15 -10
- package/src/ScrollViewGesture.tsx +2 -2
- package/src/hooks/useCarouselController.tsx +6 -6
- package/src/hooks/useCommonVariables.ts +6 -6
- package/src/hooks/useInitProps.ts +13 -4
- package/src/hooks/useOffsetX.ts +6 -5
- package/src/hooks/useOnProgressChange.ts +2 -4
- package/src/hooks/usePropsErrorBoundary.ts +2 -3
- package/src/layouts/BaseLayout.tsx +3 -3
- package/src/layouts/ParallaxLayout.tsx +3 -3
package/src/hooks/useOffsetX.ts
CHANGED
|
@@ -11,7 +11,7 @@ export interface IOpts {
|
|
|
11
11
|
index: number
|
|
12
12
|
size: number
|
|
13
13
|
handlerOffset: Animated.SharedValue<number>
|
|
14
|
-
|
|
14
|
+
dataLength: number
|
|
15
15
|
type?: "positive" | "negative"
|
|
16
16
|
viewCount?: number
|
|
17
17
|
loop?: boolean
|
|
@@ -23,16 +23,17 @@ export const useOffsetX = (opts: IOpts, visibleRanges: IVisibleRanges) => {
|
|
|
23
23
|
index,
|
|
24
24
|
size,
|
|
25
25
|
loop,
|
|
26
|
-
|
|
26
|
+
dataLength,
|
|
27
27
|
type = "positive",
|
|
28
|
-
viewCount
|
|
28
|
+
viewCount: _viewCount,
|
|
29
29
|
} = opts;
|
|
30
30
|
|
|
31
|
-
const ITEM_LENGTH =
|
|
31
|
+
const ITEM_LENGTH = dataLength;
|
|
32
32
|
const VALID_LENGTH = ITEM_LENGTH - 1;
|
|
33
33
|
const TOTAL_WIDTH = size * ITEM_LENGTH;
|
|
34
34
|
const HALF_WIDTH = 0.5 * size;
|
|
35
35
|
|
|
36
|
+
const viewCount = _viewCount ?? Math.round((ITEM_LENGTH - 1) / 2);
|
|
36
37
|
const positiveCount
|
|
37
38
|
= type === "positive" ? viewCount : VALID_LENGTH - viewCount;
|
|
38
39
|
|
|
@@ -81,7 +82,7 @@ export const useOffsetX = (opts: IOpts, visibleRanges: IVisibleRanges) => {
|
|
|
81
82
|
}
|
|
82
83
|
|
|
83
84
|
return handlerOffset.value + size * index;
|
|
84
|
-
}, [loop,
|
|
85
|
+
}, [loop, dataLength, viewCount, type, size, visibleRanges]);
|
|
85
86
|
|
|
86
87
|
return x;
|
|
87
88
|
};
|
|
@@ -13,14 +13,12 @@ export function useOnProgressChange(
|
|
|
13
13
|
autoFillData: boolean
|
|
14
14
|
loop: boolean
|
|
15
15
|
offsetX: Animated.SharedValue<number>
|
|
16
|
-
|
|
16
|
+
rawDataLength: number
|
|
17
17
|
} & Pick<TCarouselProps, "onProgressChange">,
|
|
18
18
|
) {
|
|
19
|
-
const { autoFillData, loop, offsetX,
|
|
19
|
+
const { autoFillData, loop, offsetX, size, rawDataLength, onProgressChange }
|
|
20
20
|
= opts;
|
|
21
21
|
|
|
22
|
-
const rawDataLength = rawData.length;
|
|
23
|
-
|
|
24
22
|
useAnimatedReaction(
|
|
25
23
|
() => offsetX.value,
|
|
26
24
|
(_value) => {
|
|
@@ -2,11 +2,10 @@ import React from "react";
|
|
|
2
2
|
|
|
3
3
|
import type { TCarouselProps } from "../types";
|
|
4
4
|
|
|
5
|
-
export function usePropsErrorBoundary(props: TCarouselProps) {
|
|
5
|
+
export function usePropsErrorBoundary(props: TCarouselProps & { dataLength: number }) {
|
|
6
6
|
React.useEffect(() => {
|
|
7
|
-
const { defaultIndex,
|
|
7
|
+
const { defaultIndex, dataLength: viewCount } = props;
|
|
8
8
|
|
|
9
|
-
const viewCount = data.length;
|
|
10
9
|
if (typeof defaultIndex === "number" && viewCount > 0) {
|
|
11
10
|
if (defaultIndex < 0 || defaultIndex >= viewCount) {
|
|
12
11
|
throw new Error(
|
|
@@ -36,7 +36,7 @@ export const BaseLayout: React.FC<{
|
|
|
36
36
|
const {
|
|
37
37
|
props: {
|
|
38
38
|
loop,
|
|
39
|
-
|
|
39
|
+
dataLength,
|
|
40
40
|
width,
|
|
41
41
|
height,
|
|
42
42
|
vertical,
|
|
@@ -51,7 +51,7 @@ export const BaseLayout: React.FC<{
|
|
|
51
51
|
handlerOffset,
|
|
52
52
|
index,
|
|
53
53
|
size,
|
|
54
|
-
|
|
54
|
+
dataLength,
|
|
55
55
|
loop,
|
|
56
56
|
...(typeof customConfig === "function" ? customConfig() : {}),
|
|
57
57
|
};
|
|
@@ -63,7 +63,7 @@ export const BaseLayout: React.FC<{
|
|
|
63
63
|
handlerOffset,
|
|
64
64
|
index,
|
|
65
65
|
size,
|
|
66
|
-
|
|
66
|
+
dataLength,
|
|
67
67
|
loop,
|
|
68
68
|
type: snapDirection === "right" ? "negative" : "positive",
|
|
69
69
|
viewCount: showLength,
|
|
@@ -20,7 +20,7 @@ IComputedDirectionTypes<
|
|
|
20
20
|
loop?: boolean
|
|
21
21
|
handlerOffset: Animated.SharedValue<number>
|
|
22
22
|
index: number
|
|
23
|
-
|
|
23
|
+
dataLength: number
|
|
24
24
|
visibleRanges: IVisibleRanges
|
|
25
25
|
} & ILayoutConfig
|
|
26
26
|
>
|
|
@@ -34,7 +34,7 @@ IComputedDirectionTypes<
|
|
|
34
34
|
width,
|
|
35
35
|
height,
|
|
36
36
|
loop,
|
|
37
|
-
|
|
37
|
+
dataLength,
|
|
38
38
|
children,
|
|
39
39
|
visibleRanges,
|
|
40
40
|
vertical,
|
|
@@ -49,7 +49,7 @@ IComputedDirectionTypes<
|
|
|
49
49
|
handlerOffset,
|
|
50
50
|
index,
|
|
51
51
|
size,
|
|
52
|
-
|
|
52
|
+
dataLength,
|
|
53
53
|
loop,
|
|
54
54
|
},
|
|
55
55
|
visibleRanges,
|