react-native-reanimated-carousel 4.0.0-alpha.0 → 4.0.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +21 -160
- package/lib/commonjs/components/Carousel.js +231 -0
- package/lib/commonjs/components/Carousel.js.map +1 -0
- package/lib/commonjs/components/LazyView.js +22 -0
- package/lib/commonjs/components/LazyView.js.map +1 -0
- package/lib/commonjs/components/ScrollViewGesture.js +297 -0
- package/lib/commonjs/components/ScrollViewGesture.js.map +1 -0
- package/lib/commonjs/constants/index.js +21 -1
- package/lib/commonjs/constants/index.js.map +1 -1
- package/lib/commonjs/hooks/useAutoPlay.js +56 -1
- package/lib/commonjs/hooks/useAutoPlay.js.map +1 -1
- package/lib/commonjs/hooks/useCarouselController.js +244 -1
- package/lib/commonjs/hooks/useCarouselController.js.map +1 -1
- package/lib/commonjs/hooks/useCheckMounted.js +23 -1
- package/lib/commonjs/hooks/useCheckMounted.js.map +1 -1
- package/lib/commonjs/hooks/useCommonVariables.js +76 -1
- package/lib/commonjs/hooks/useCommonVariables.js.map +1 -1
- package/lib/commonjs/hooks/useInitProps.js +78 -1
- package/lib/commonjs/hooks/useInitProps.js.map +1 -1
- package/lib/commonjs/hooks/useLayoutConfig.js +39 -1
- package/lib/commonjs/hooks/useLayoutConfig.js.map +1 -1
- package/lib/commonjs/hooks/useOffsetX.js +48 -1
- package/lib/commonjs/hooks/useOffsetX.js.map +1 -1
- package/lib/commonjs/hooks/useOnProgressChange.js +38 -1
- package/lib/commonjs/hooks/useOnProgressChange.js.map +1 -1
- package/lib/commonjs/hooks/usePropsErrorBoundary.js +36 -1
- package/lib/commonjs/hooks/usePropsErrorBoundary.js.map +1 -1
- package/lib/commonjs/hooks/useUpdateGestureConfig.js +20 -0
- package/lib/commonjs/hooks/useUpdateGestureConfig.js.map +1 -0
- package/lib/commonjs/hooks/useVisibleRanges.js +42 -1
- package/lib/commonjs/hooks/useVisibleRanges.js.map +1 -1
- package/lib/commonjs/index.js +13 -1
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/layouts/BaseLayout.js +110 -1
- package/lib/commonjs/layouts/BaseLayout.js.map +1 -1
- package/lib/commonjs/layouts/ParallaxLayout.js +83 -1
- package/lib/commonjs/layouts/ParallaxLayout.js.map +1 -1
- package/lib/commonjs/layouts/index.js +20 -1
- package/lib/commonjs/layouts/index.js.map +1 -1
- package/lib/commonjs/layouts/normal.js +27 -1
- package/lib/commonjs/layouts/normal.js.map +1 -1
- package/lib/commonjs/layouts/parallax.js +38 -1
- package/lib/commonjs/layouts/parallax.js.map +1 -1
- package/lib/commonjs/layouts/stack.js +215 -1
- package/lib/commonjs/layouts/stack.js.map +1 -1
- package/lib/commonjs/store/index.js +14 -1
- package/lib/commonjs/store/index.js.map +1 -1
- package/lib/commonjs/types.js +5 -1
- package/lib/commonjs/utils/computeNewIndexWhenDataChanges.js +52 -0
- package/lib/commonjs/utils/computeNewIndexWhenDataChanges.js.map +1 -0
- package/lib/commonjs/utils/computed-with-auto-fill-data.js +124 -0
- package/lib/commonjs/utils/computed-with-auto-fill-data.js.map +1 -0
- package/lib/commonjs/utils/deal-with-animation.js +21 -0
- package/lib/commonjs/utils/deal-with-animation.js.map +1 -0
- package/lib/commonjs/utils/handleroffset-direction.js +16 -0
- package/lib/commonjs/utils/handleroffset-direction.js.map +1 -0
- package/lib/commonjs/utils/index.test.js +74 -0
- package/lib/commonjs/utils/index.test.js.map +1 -0
- package/lib/commonjs/utils/log.js +22 -1
- package/lib/commonjs/utils/log.js.map +1 -1
- package/lib/module/{Carousel.js → components/Carousel.js} +11 -12
- package/lib/module/components/Carousel.js.map +1 -0
- package/lib/module/{ScrollViewGesture.js → components/ScrollViewGesture.js} +14 -6
- package/lib/module/components/ScrollViewGesture.js.map +1 -0
- package/lib/module/hooks/useCarouselController.js +3 -3
- package/lib/module/hooks/useCarouselController.js.map +1 -1
- package/lib/module/hooks/useCommonVariables.js +2 -2
- package/lib/module/hooks/useCommonVariables.js.map +1 -1
- package/lib/module/hooks/useInitProps.js +1 -3
- package/lib/module/hooks/useInitProps.js.map +1 -1
- package/lib/module/hooks/useOnProgressChange.js +1 -1
- package/lib/module/hooks/useOnProgressChange.js.map +1 -1
- package/lib/module/hooks/useUpdateGestureConfig.js +10 -0
- package/lib/module/hooks/useUpdateGestureConfig.js.map +1 -0
- package/lib/module/index.js +1 -2
- package/lib/module/index.js.map +1 -1
- package/lib/module/layouts/BaseLayout.js +1 -1
- package/lib/module/layouts/BaseLayout.js.map +1 -1
- package/lib/module/layouts/ParallaxLayout.js +1 -1
- package/lib/module/layouts/ParallaxLayout.js.map +1 -1
- package/lib/module/utils/{computedWithAutoFillData.js → computed-with-auto-fill-data.js} +1 -1
- package/lib/module/utils/computed-with-auto-fill-data.js.map +1 -0
- package/lib/module/utils/{dealWithAnimation.js → deal-with-animation.js} +1 -1
- package/lib/module/utils/deal-with-animation.js.map +1 -0
- package/lib/module/utils/{handlerOffsetDirection.js → handleroffset-direction.js} +1 -1
- package/lib/module/utils/handleroffset-direction.js.map +1 -0
- package/lib/typescript/{Carousel.d.ts → components/Carousel.d.ts} +1 -1
- package/lib/typescript/hooks/useUpdateGestureConfig.d.ts +4 -0
- package/lib/typescript/index.d.ts +2 -2
- package/lib/typescript/types.d.ts +103 -103
- package/package.json +18 -16
- package/src/{Carousel.tsx → components/Carousel.tsx} +13 -13
- package/src/{ScrollViewGesture.tsx → components/ScrollViewGesture.tsx} +30 -15
- package/src/hooks/useCarouselController.tsx +3 -3
- package/src/hooks/useCommonVariables.ts +2 -2
- package/src/hooks/useInitProps.ts +1 -3
- package/src/hooks/useOnProgressChange.ts +1 -1
- package/src/hooks/useUpdateGestureConfig.ts +13 -0
- package/src/index.tsx +2 -2
- package/src/layouts/BaseLayout.tsx +1 -1
- package/src/layouts/ParallaxLayout.tsx +1 -1
- package/src/types.ts +122 -124
- package/README.zh-CN.md +0 -202
- package/lib/commonjs/Carousel.js +0 -2
- package/lib/commonjs/Carousel.js.map +0 -1
- package/lib/commonjs/LazyView.js +0 -2
- package/lib/commonjs/LazyView.js.map +0 -1
- package/lib/commonjs/ScrollViewGesture.js +0 -2
- package/lib/commonjs/ScrollViewGesture.js.map +0 -1
- package/lib/commonjs/hooks/computeNewIndexWhenDataChanges.js +0 -2
- package/lib/commonjs/hooks/computeNewIndexWhenDataChanges.js.map +0 -1
- package/lib/commonjs/hooks/index.test.js +0 -2
- package/lib/commonjs/hooks/index.test.js.map +0 -1
- package/lib/commonjs/utils/computedWithAutoFillData.js +0 -2
- package/lib/commonjs/utils/computedWithAutoFillData.js.map +0 -1
- package/lib/commonjs/utils/dealWithAnimation.js +0 -2
- package/lib/commonjs/utils/dealWithAnimation.js.map +0 -1
- package/lib/commonjs/utils/handlerOffsetDirection.js +0 -2
- package/lib/commonjs/utils/handlerOffsetDirection.js.map +0 -1
- package/lib/module/Carousel.js.map +0 -1
- package/lib/module/ScrollViewGesture.js.map +0 -1
- package/lib/module/utils/computedWithAutoFillData.js.map +0 -1
- package/lib/module/utils/dealWithAnimation.js.map +0 -1
- package/lib/module/utils/handlerOffsetDirection.js.map +0 -1
- /package/lib/module/{LazyView.js → components/LazyView.js} +0 -0
- /package/lib/module/{LazyView.js.map → components/LazyView.js.map} +0 -0
- /package/lib/module/{hooks → utils}/computeNewIndexWhenDataChanges.js +0 -0
- /package/lib/module/{hooks → utils}/computeNewIndexWhenDataChanges.js.map +0 -0
- /package/lib/module/{hooks → utils}/index.test.js +0 -0
- /package/lib/module/{hooks → utils}/index.test.js.map +0 -0
- /package/lib/typescript/{LazyView.d.ts → components/LazyView.d.ts} +0 -0
- /package/lib/typescript/{ScrollViewGesture.d.ts → components/ScrollViewGesture.d.ts} +0 -0
- /package/lib/typescript/{hooks → utils}/computeNewIndexWhenDataChanges.d.ts +0 -0
- /package/lib/typescript/utils/{computedWithAutoFillData.d.ts → computed-with-auto-fill-data.d.ts} +0 -0
- /package/lib/typescript/utils/{dealWithAnimation.d.ts → deal-with-animation.d.ts} +0 -0
- /package/lib/typescript/utils/{handlerOffsetDirection.d.ts → handleroffset-direction.d.ts} +0 -0
- /package/lib/typescript/{hooks → utils}/index.test.d.ts +0 -0
- /package/src/{LazyView.tsx → components/LazyView.tsx} +0 -0
- /package/src/{hooks → utils}/computeNewIndexWhenDataChanges.ts +0 -0
- /package/src/utils/{computedWithAutoFillData.ts → computed-with-auto-fill-data.ts} +0 -0
- /package/src/utils/{dealWithAnimation.ts → deal-with-animation.ts} +0 -0
- /package/src/utils/{handlerOffsetDirection.ts → handleroffset-direction.ts} +0 -0
- /package/src/{hooks → utils}/index.test.ts +0 -0
|
@@ -1,33 +1,33 @@
|
|
|
1
1
|
import type { StyleProp, ViewStyle } from "react-native";
|
|
2
|
-
import type {
|
|
2
|
+
import type { PanGesture } from "react-native-gesture-handler";
|
|
3
3
|
import type { AnimatedStyleProp, SharedValue, WithSpringConfig, WithTimingConfig } from "react-native-reanimated";
|
|
4
4
|
import type Animated from "react-native-reanimated";
|
|
5
5
|
import type { TParallaxModeProps } from "./layouts/parallax";
|
|
6
6
|
import type { TStackModeProps } from "./layouts/stack";
|
|
7
7
|
export declare type IComputedDirectionTypes<T, VP = {}, HP = {}> = (T & VP & {
|
|
8
8
|
/**
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
* Layout items vertically instead of horizontally
|
|
10
|
+
*/
|
|
11
11
|
vertical: true;
|
|
12
12
|
/**
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
* Layout items vertically instead of horizontally
|
|
14
|
+
*/
|
|
15
15
|
/**
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
* Specified carousel container width.
|
|
17
|
+
*/
|
|
18
18
|
width?: number;
|
|
19
19
|
height: number;
|
|
20
20
|
}) | (T & HP & {
|
|
21
21
|
/**
|
|
22
|
-
|
|
23
|
-
|
|
22
|
+
* Layout items vertically instead of horizontally
|
|
23
|
+
*/
|
|
24
24
|
vertical?: false;
|
|
25
25
|
/**
|
|
26
|
-
|
|
27
|
-
|
|
26
|
+
* Layout items vertically instead of horizontally
|
|
27
|
+
*/
|
|
28
28
|
/**
|
|
29
|
-
|
|
30
|
-
|
|
29
|
+
* Specified carousel container width.
|
|
30
|
+
*/
|
|
31
31
|
width: number;
|
|
32
32
|
height?: number;
|
|
33
33
|
});
|
|
@@ -47,157 +47,157 @@ export declare type WithAnimation = WithSpringAnimation | WithTimingAnimation;
|
|
|
47
47
|
export declare type TCarouselProps<T = any> = {
|
|
48
48
|
ref?: React.Ref<ICarouselInstance>;
|
|
49
49
|
/**
|
|
50
|
-
|
|
51
|
-
|
|
50
|
+
* The default animated value of the carousel.
|
|
51
|
+
*/
|
|
52
52
|
defaultScrollOffsetValue?: SharedValue<number>;
|
|
53
53
|
/**
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
54
|
+
* Carousel loop playback.
|
|
55
|
+
* @default true
|
|
56
|
+
*/
|
|
57
57
|
loop?: boolean;
|
|
58
58
|
/**
|
|
59
|
-
|
|
60
|
-
|
|
59
|
+
* Carousel items data set.
|
|
60
|
+
*/
|
|
61
61
|
data: T[];
|
|
62
62
|
/**
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
63
|
+
* Auto fill data array to allow loop playback when the loop props is true.
|
|
64
|
+
* @default true
|
|
65
|
+
* @example
|
|
66
|
+
* [1] => [1, 1, 1]
|
|
67
|
+
* [1, 2] => [1, 2, 1, 2]
|
|
68
|
+
*/
|
|
69
69
|
autoFillData?: boolean;
|
|
70
70
|
/**
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
71
|
+
* Default index
|
|
72
|
+
* @default 0
|
|
73
|
+
*/
|
|
74
74
|
defaultIndex?: number;
|
|
75
75
|
/**
|
|
76
|
-
|
|
77
|
-
|
|
76
|
+
* Auto play
|
|
77
|
+
*/
|
|
78
78
|
autoPlay?: boolean;
|
|
79
79
|
/**
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
80
|
+
* Auto play
|
|
81
|
+
* @description reverse playback
|
|
82
|
+
*/
|
|
83
83
|
autoPlayReverse?: boolean;
|
|
84
84
|
/**
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
85
|
+
* Auto play
|
|
86
|
+
* @description playback interval
|
|
87
|
+
*/
|
|
88
88
|
autoPlayInterval?: number;
|
|
89
89
|
/**
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
90
|
+
* Time a scroll animation takes to finish
|
|
91
|
+
* @default 500 (ms)
|
|
92
|
+
*/
|
|
93
93
|
scrollAnimationDuration?: number;
|
|
94
94
|
/**
|
|
95
|
-
|
|
96
|
-
|
|
95
|
+
* Carousel container style
|
|
96
|
+
*/
|
|
97
97
|
style?: StyleProp<ViewStyle>;
|
|
98
98
|
/**
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
99
|
+
* PanGesture config
|
|
100
|
+
*/
|
|
101
|
+
onConfigurePanGesture?: (panGesture: PanGesture) => void;
|
|
102
102
|
/**
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
103
|
+
* Determines the maximum number of items will respond to pan gesture events,
|
|
104
|
+
* windowSize={11} will active visible item plus up to 5 items above and 5 below the viewpor,
|
|
105
|
+
* Reducing this number will reduce the calculation of the animation value and may improve performance.
|
|
106
|
+
* @default 0 all items will respond to pan gesture events.
|
|
107
|
+
*/
|
|
108
108
|
windowSize?: number;
|
|
109
109
|
/**
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
110
|
+
* When true, the scroll view stops on multiples of the scroll view's size when scrolling.
|
|
111
|
+
* @default true
|
|
112
|
+
*/
|
|
113
113
|
pagingEnabled?: boolean;
|
|
114
114
|
/**
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
115
|
+
* If enabled, releasing the touch will scroll to the nearest item.
|
|
116
|
+
* valid when pagingEnabled=false
|
|
117
|
+
* @default true
|
|
118
|
+
*/
|
|
119
119
|
snapEnabled?: boolean;
|
|
120
120
|
/**
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
121
|
+
* If enabled, items will scroll to the first placement when scrolling past the edge rather than closing to the last. (previous conditions: loop=false)
|
|
122
|
+
* @default true
|
|
123
|
+
*/
|
|
124
124
|
overscrollEnabled?: boolean;
|
|
125
125
|
/**
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
126
|
+
* If false, Carousel will not respond to any gestures.
|
|
127
|
+
* @default true
|
|
128
|
+
*/
|
|
129
129
|
enabled?: boolean;
|
|
130
130
|
/**
|
|
131
|
-
|
|
132
|
-
|
|
131
|
+
* Specifies the scrolling animation effect.
|
|
132
|
+
*/
|
|
133
133
|
withAnimation?: WithAnimation;
|
|
134
134
|
/**
|
|
135
|
-
|
|
136
|
-
|
|
135
|
+
* Used to locate this view in end-to-end tests.
|
|
136
|
+
*/
|
|
137
137
|
testID?: string;
|
|
138
138
|
/**
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
139
|
+
* Maximum offset value for once scroll.
|
|
140
|
+
* props.vertical = true => maxScrollDistancePerSwipeY
|
|
141
|
+
* props.vertical = false => maxScrollDistancePerSwipeX
|
|
142
|
+
* */
|
|
143
143
|
maxScrollDistancePerSwipe?: number;
|
|
144
144
|
/**
|
|
145
|
-
|
|
146
|
-
|
|
145
|
+
* Custom carousel config.
|
|
146
|
+
*/
|
|
147
147
|
customConfig?: () => CustomConfig;
|
|
148
148
|
/**
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
149
|
+
* Custom animations.
|
|
150
|
+
* Must use `worklet`, Details: https://docs.swmansion.com/react-native-reanimated/docs/2.2.0/worklets/
|
|
151
|
+
*/
|
|
152
152
|
customAnimation?: (value: number) => AnimatedStyleProp<ViewStyle>;
|
|
153
153
|
/**
|
|
154
|
-
|
|
155
|
-
|
|
154
|
+
* Render carousel item.
|
|
155
|
+
*/
|
|
156
156
|
renderItem: CarouselRenderItem<T>;
|
|
157
157
|
/**
|
|
158
|
-
|
|
159
|
-
|
|
158
|
+
* Callback fired when navigating to an item.
|
|
159
|
+
*/
|
|
160
160
|
onSnapToItem?: (index: number) => void;
|
|
161
161
|
/**
|
|
162
|
-
|
|
163
|
-
|
|
162
|
+
* On scroll begin
|
|
163
|
+
*/
|
|
164
164
|
onScrollBegin?: () => void;
|
|
165
165
|
/**
|
|
166
|
-
|
|
167
|
-
|
|
166
|
+
* On scroll end
|
|
167
|
+
*/
|
|
168
168
|
onScrollEnd?: (index: number) => void;
|
|
169
169
|
/**
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
170
|
+
* On progress change
|
|
171
|
+
* @param offsetProgress Total of offset distance (0 390 780 ...)
|
|
172
|
+
* @param absoluteProgress Convert to index (0 1 2 ...)
|
|
173
|
+
*/
|
|
174
174
|
onProgressChange?: (offsetProgress: number, absoluteProgress: number) => void;
|
|
175
175
|
/**
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
176
|
+
* If enabled, releasing the touch will scroll to the nearest item.
|
|
177
|
+
* valid when pagingEnabled=false
|
|
178
|
+
* @deprecated please use snapEnabled instead
|
|
179
|
+
*/
|
|
180
180
|
enableSnap?: boolean;
|
|
181
181
|
} & (TParallaxModeProps | TStackModeProps);
|
|
182
182
|
export interface ICarouselInstance {
|
|
183
183
|
/**
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
184
|
+
* Scroll to previous item, it takes one optional argument (count),
|
|
185
|
+
* which allows you to specify how many items to cross
|
|
186
|
+
*/
|
|
187
187
|
prev: (opts?: Omit<TCarouselActionOptions, "index">) => void;
|
|
188
188
|
/**
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
189
|
+
* Scroll to next item, it takes one optional argument (count),
|
|
190
|
+
* which allows you to specify how many items to cross
|
|
191
|
+
*/
|
|
192
192
|
next: (opts?: Omit<TCarouselActionOptions, "index">) => void;
|
|
193
193
|
/**
|
|
194
|
-
|
|
195
|
-
|
|
194
|
+
* Get current item index
|
|
195
|
+
*/
|
|
196
196
|
getCurrentIndex: () => number;
|
|
197
197
|
/**
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
198
|
+
* Use value to scroll to a position where relative to the current position,
|
|
199
|
+
* scrollTo(-2) is equivalent to prev(2), scrollTo(2) is equivalent to next(2)
|
|
200
|
+
*/
|
|
201
201
|
scrollTo: (opts?: TCarouselActionOptions) => void;
|
|
202
202
|
}
|
|
203
203
|
export interface CarouselRenderItemInfo<ItemT> {
|
package/package.json
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-reanimated-carousel",
|
|
3
|
-
"version": "4.0.0-alpha.
|
|
3
|
+
"version": "4.0.0-alpha.1",
|
|
4
4
|
"description": "Simple carousel component.fully implemented using Reanimated 2.Infinitely scrolling, very smooth.",
|
|
5
5
|
"main": "lib/commonjs/index",
|
|
6
|
+
"module": "lib/module/index",
|
|
6
7
|
"react-native": "src/index.tsx",
|
|
7
8
|
"types": "lib/typescript/index.d.ts",
|
|
8
9
|
"source": "src/index",
|
|
@@ -50,8 +51,8 @@
|
|
|
50
51
|
},
|
|
51
52
|
"devDependencies": {
|
|
52
53
|
"@babel/plugin-syntax-dynamic-import": "^7.8.3",
|
|
53
|
-
"@changesets/changelog-
|
|
54
|
-
"@changesets/cli": "
|
|
54
|
+
"@changesets/changelog-github": "^0.5.0",
|
|
55
|
+
"@changesets/cli": "latest",
|
|
55
56
|
"@commitlint/config-conventional": "^11.0.0",
|
|
56
57
|
"@dohooo/eslint-config": "^0.0.7",
|
|
57
58
|
"@react-native-community/eslint-config": "^2.0.0",
|
|
@@ -85,11 +86,21 @@
|
|
|
85
86
|
"watch": "^1.0.2"
|
|
86
87
|
},
|
|
87
88
|
"peerDependencies": {
|
|
89
|
+
"@types/react": "*",
|
|
90
|
+
"@types/react-native": "*",
|
|
88
91
|
"react": ">=18.0.0",
|
|
89
92
|
"react-native": ">=0.70.3",
|
|
90
93
|
"react-native-gesture-handler": ">=2.9.0",
|
|
91
94
|
"react-native-reanimated": ">=3.0.0"
|
|
92
95
|
},
|
|
96
|
+
"peerDependenciesMeta": {
|
|
97
|
+
"@types/react": {
|
|
98
|
+
"optional": true
|
|
99
|
+
},
|
|
100
|
+
"@types/react-native": {
|
|
101
|
+
"optional": true
|
|
102
|
+
}
|
|
103
|
+
},
|
|
93
104
|
"jest": {
|
|
94
105
|
"preset": "react-native",
|
|
95
106
|
"modulePathIgnorePatterns": [
|
|
@@ -144,24 +155,15 @@
|
|
|
144
155
|
"source": "src",
|
|
145
156
|
"output": "lib",
|
|
146
157
|
"targets": [
|
|
147
|
-
|
|
148
|
-
"commonjs",
|
|
149
|
-
{
|
|
150
|
-
"configFile": "./babel.config.js"
|
|
151
|
-
}
|
|
152
|
-
],
|
|
158
|
+
"commonjs",
|
|
153
159
|
"module",
|
|
154
|
-
|
|
155
|
-
"typescript",
|
|
156
|
-
{
|
|
157
|
-
"project": "tsconfig.build.json"
|
|
158
|
-
}
|
|
159
|
-
]
|
|
160
|
+
"typescript"
|
|
160
161
|
]
|
|
161
162
|
},
|
|
162
163
|
"config": {
|
|
163
164
|
"commitizen": {
|
|
164
165
|
"path": "./node_modules/cz-conventional-changelog"
|
|
165
166
|
}
|
|
166
|
-
}
|
|
167
|
+
},
|
|
168
|
+
"packageManager": "yarn@4.0.2"
|
|
167
169
|
}
|
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-use-before-define */
|
|
2
1
|
import React from "react";
|
|
3
2
|
import { StyleSheet } from "react-native";
|
|
4
3
|
import { GestureHandlerRootView } from "react-native-gesture-handler";
|
|
5
4
|
import { runOnJS, useDerivedValue } from "react-native-reanimated";
|
|
6
5
|
|
|
7
|
-
import { useAutoPlay } from "./hooks/useAutoPlay";
|
|
8
|
-
import { useCarouselController } from "./hooks/useCarouselController";
|
|
9
|
-
import { useCommonVariables } from "./hooks/useCommonVariables";
|
|
10
|
-
import { useInitProps } from "./hooks/useInitProps";
|
|
11
|
-
import { useLayoutConfig } from "./hooks/useLayoutConfig";
|
|
12
|
-
import { useOnProgressChange } from "./hooks/useOnProgressChange";
|
|
13
|
-
import { usePropsErrorBoundary } from "./hooks/usePropsErrorBoundary";
|
|
14
|
-
import { useVisibleRanges } from "./hooks/useVisibleRanges";
|
|
15
|
-
import { BaseLayout } from "./layouts/BaseLayout";
|
|
16
6
|
import { ScrollViewGesture } from "./ScrollViewGesture";
|
|
17
|
-
|
|
18
|
-
import
|
|
19
|
-
import {
|
|
7
|
+
|
|
8
|
+
import { useAutoPlay } from "../hooks/useAutoPlay";
|
|
9
|
+
import { useCarouselController } from "../hooks/useCarouselController";
|
|
10
|
+
import { useCommonVariables } from "../hooks/useCommonVariables";
|
|
11
|
+
import { useInitProps } from "../hooks/useInitProps";
|
|
12
|
+
import { useLayoutConfig } from "../hooks/useLayoutConfig";
|
|
13
|
+
import { useOnProgressChange } from "../hooks/useOnProgressChange";
|
|
14
|
+
import { usePropsErrorBoundary } from "../hooks/usePropsErrorBoundary";
|
|
15
|
+
import { useVisibleRanges } from "../hooks/useVisibleRanges";
|
|
16
|
+
import { BaseLayout } from "../layouts/BaseLayout";
|
|
17
|
+
import { CTX } from "../store";
|
|
18
|
+
import type { ICarouselInstance, TCarouselProps } from "../types";
|
|
19
|
+
import { computedRealIndexWithAutoFillData } from "../utils/computed-with-auto-fill-data";
|
|
20
20
|
|
|
21
21
|
const Carousel = React.forwardRef<ICarouselInstance, TCarouselProps<any>>(
|
|
22
22
|
(_props, ref) => {
|
|
@@ -17,10 +17,11 @@ import Animated, {
|
|
|
17
17
|
withDecay,
|
|
18
18
|
} from "react-native-reanimated";
|
|
19
19
|
|
|
20
|
-
import { Easing } from "
|
|
21
|
-
import {
|
|
22
|
-
import
|
|
23
|
-
import {
|
|
20
|
+
import { Easing } from "../constants";
|
|
21
|
+
import { useUpdateGestureConfig } from "../hooks/useUpdateGestureConfig";
|
|
22
|
+
import { CTX } from "../store";
|
|
23
|
+
import type { WithTimingAnimation } from "../types";
|
|
24
|
+
import { dealWithAnimation } from "../utils/deal-with-animation";
|
|
24
25
|
|
|
25
26
|
interface Props {
|
|
26
27
|
size: number
|
|
@@ -37,6 +38,7 @@ interface Props {
|
|
|
37
38
|
const IScrollViewGesture: React.FC<PropsWithChildren<Props>> = (props) => {
|
|
38
39
|
const {
|
|
39
40
|
props: {
|
|
41
|
+
onConfigurePanGesture,
|
|
40
42
|
vertical,
|
|
41
43
|
pagingEnabled,
|
|
42
44
|
snapEnabled,
|
|
@@ -126,13 +128,13 @@ const IScrollViewGesture: React.FC<PropsWithChildren<Props>> = (props) => {
|
|
|
126
128
|
finalTranslation = origin;
|
|
127
129
|
}
|
|
128
130
|
else {
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
131
|
+
/**
|
|
132
|
+
* The page size is the same as the item size.
|
|
133
|
+
* If direction is vertical, the page size is the height of the item.
|
|
134
|
+
* If direction is horizontal, the page size is the width of the item.
|
|
135
|
+
*
|
|
136
|
+
* `page size` equals to `size` variable.
|
|
137
|
+
* */
|
|
136
138
|
if (pagingEnabled) {
|
|
137
139
|
// distance with direction
|
|
138
140
|
const offset = -(scrollEndTranslation.value >= 0 ? 1 : -1); // 1 or -1
|
|
@@ -359,15 +361,28 @@ const IScrollViewGesture: React.FC<PropsWithChildren<Props>> = (props) => {
|
|
|
359
361
|
onScrollEnd,
|
|
360
362
|
]);
|
|
361
363
|
|
|
362
|
-
const gesture = useMemo(() =>
|
|
364
|
+
const gesture = useMemo(() => {
|
|
365
|
+
const gesture = Gesture.Pan()
|
|
366
|
+
.onBegin(onGestureBegin)
|
|
367
|
+
.onUpdate(onGestureUpdate)
|
|
368
|
+
.onEnd(onGestureFinish);
|
|
369
|
+
|
|
370
|
+
if (onConfigurePanGesture)
|
|
371
|
+
onConfigurePanGesture(gesture);
|
|
372
|
+
|
|
373
|
+
return gesture;
|
|
374
|
+
},
|
|
375
|
+
[
|
|
363
376
|
onGestureBegin,
|
|
364
377
|
onGestureUpdate,
|
|
365
378
|
onGestureFinish,
|
|
379
|
+
onConfigurePanGesture,
|
|
366
380
|
]);
|
|
367
|
-
|
|
381
|
+
|
|
382
|
+
useUpdateGestureConfig(gesture, { enabled });
|
|
368
383
|
|
|
369
384
|
return (
|
|
370
|
-
<
|
|
385
|
+
<GestureDetector gesture={gesture}>
|
|
371
386
|
<Animated.View
|
|
372
387
|
ref={containerRef}
|
|
373
388
|
testID={testID}
|
|
@@ -377,7 +392,7 @@ const IScrollViewGesture: React.FC<PropsWithChildren<Props>> = (props) => {
|
|
|
377
392
|
>
|
|
378
393
|
{props.children}
|
|
379
394
|
</Animated.View>
|
|
380
|
-
</
|
|
395
|
+
</GestureDetector>
|
|
381
396
|
);
|
|
382
397
|
};
|
|
383
398
|
|
|
@@ -12,9 +12,9 @@ import type {
|
|
|
12
12
|
TCarouselProps,
|
|
13
13
|
WithTimingAnimation,
|
|
14
14
|
} from "../types";
|
|
15
|
-
import { computedRealIndexWithAutoFillData, convertToSharedIndex } from "../utils/
|
|
16
|
-
import { dealWithAnimation } from "../utils/
|
|
17
|
-
import { handlerOffsetDirection } from "../utils/
|
|
15
|
+
import { computedRealIndexWithAutoFillData, convertToSharedIndex } from "../utils/computed-with-auto-fill-data";
|
|
16
|
+
import { dealWithAnimation } from "../utils/deal-with-animation";
|
|
17
|
+
import { handlerOffsetDirection } from "../utils/handleroffset-direction";
|
|
18
18
|
import { round } from "../utils/log";
|
|
19
19
|
|
|
20
20
|
interface IOpts {
|
|
@@ -2,10 +2,10 @@ import React from "react";
|
|
|
2
2
|
import type Animated from "react-native-reanimated";
|
|
3
3
|
import { useSharedValue, useAnimatedReaction } from "react-native-reanimated";
|
|
4
4
|
|
|
5
|
-
import { computeNewIndexWhenDataChanges } from "./computeNewIndexWhenDataChanges";
|
|
6
5
|
import type { TInitializeCarouselProps } from "./useInitProps";
|
|
7
6
|
|
|
8
|
-
import {
|
|
7
|
+
import { computeNewIndexWhenDataChanges } from "../utils/computeNewIndexWhenDataChanges";
|
|
8
|
+
import { handlerOffsetDirection } from "../utils/handleroffset-direction";
|
|
9
9
|
|
|
10
10
|
interface ICommonVariables {
|
|
11
11
|
size: number
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
|
|
3
3
|
import type { TCarouselProps } from "../types";
|
|
4
|
-
import { computedFillDataWithAutoFillData } from "../utils/
|
|
4
|
+
import { computedFillDataWithAutoFillData } from "../utils/computed-with-auto-fill-data";
|
|
5
5
|
|
|
6
6
|
type TGetRequiredProps<P extends keyof TCarouselProps> = Record<
|
|
7
7
|
P,
|
|
@@ -34,7 +34,6 @@ export function useInitProps<T>(
|
|
|
34
34
|
autoPlayInterval: _autoPlayInterval = 1000,
|
|
35
35
|
scrollAnimationDuration = 500,
|
|
36
36
|
style = {},
|
|
37
|
-
panGestureHandlerProps = {},
|
|
38
37
|
autoFillData = true,
|
|
39
38
|
// switchers
|
|
40
39
|
enabled = true,
|
|
@@ -88,7 +87,6 @@ export function useInitProps<T>(
|
|
|
88
87
|
autoPlayInterval,
|
|
89
88
|
scrollAnimationDuration,
|
|
90
89
|
style,
|
|
91
|
-
panGestureHandlerProps,
|
|
92
90
|
pagingEnabled,
|
|
93
91
|
snapEnabled,
|
|
94
92
|
overscrollEnabled,
|
|
@@ -5,7 +5,7 @@ import {
|
|
|
5
5
|
} from "react-native-reanimated";
|
|
6
6
|
|
|
7
7
|
import type { TCarouselProps } from "../types";
|
|
8
|
-
import { computedOffsetXValueWithAutoFillData } from "../utils/
|
|
8
|
+
import { computedOffsetXValueWithAutoFillData } from "../utils/computed-with-auto-fill-data";
|
|
9
9
|
|
|
10
10
|
export function useOnProgressChange(
|
|
11
11
|
opts: {
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { useEffect } from "react";
|
|
2
|
+
import type { PanGesture } from "react-native-gesture-handler";
|
|
3
|
+
|
|
4
|
+
export const useUpdateGestureConfig = (gesture: PanGesture, config: {
|
|
5
|
+
enabled?: boolean
|
|
6
|
+
}) => {
|
|
7
|
+
const { enabled } = config;
|
|
8
|
+
|
|
9
|
+
useEffect(() => {
|
|
10
|
+
if (typeof enabled !== "undefined")
|
|
11
|
+
gesture.enabled(enabled);
|
|
12
|
+
}, [enabled, gesture]);
|
|
13
|
+
};
|
package/src/index.tsx
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import Carousel from "./Carousel";
|
|
1
|
+
import Carousel from "./components/Carousel";
|
|
2
2
|
export type {
|
|
3
3
|
TCarouselProps,
|
|
4
4
|
ICarouselInstance,
|
|
5
5
|
IComputedDirectionTypes,
|
|
6
6
|
CarouselRenderItem,
|
|
7
7
|
} from "./types";
|
|
8
|
-
export { ILayoutConfig } from "./layouts/stack";
|
|
8
|
+
export type { ILayoutConfig } from "./layouts/stack";
|
|
9
9
|
|
|
10
10
|
export default Carousel;
|
|
@@ -10,11 +10,11 @@ import Animated, {
|
|
|
10
10
|
|
|
11
11
|
import type { ILayoutConfig } from "./stack";
|
|
12
12
|
|
|
13
|
+
import { LazyView } from "../components/LazyView";
|
|
13
14
|
import { useCheckMounted } from "../hooks/useCheckMounted";
|
|
14
15
|
import type { IOpts } from "../hooks/useOffsetX";
|
|
15
16
|
import { useOffsetX } from "../hooks/useOffsetX";
|
|
16
17
|
import type { IVisibleRanges } from "../hooks/useVisibleRanges";
|
|
17
|
-
import { LazyView } from "../LazyView";
|
|
18
18
|
import { CTX } from "../store";
|
|
19
19
|
|
|
20
20
|
export type TAnimationStyle = (value: number) => AnimatedStyleProp<ViewStyle>;
|
|
@@ -10,9 +10,9 @@ import Animated, {
|
|
|
10
10
|
|
|
11
11
|
import type { ILayoutConfig } from "./parallax";
|
|
12
12
|
|
|
13
|
+
import { LazyView } from "../components/LazyView";
|
|
13
14
|
import { useOffsetX } from "../hooks/useOffsetX";
|
|
14
15
|
import type { IVisibleRanges } from "../hooks/useVisibleRanges";
|
|
15
|
-
import { LazyView } from "../LazyView";
|
|
16
16
|
import type { IComputedDirectionTypes } from "../types";
|
|
17
17
|
|
|
18
18
|
export const ParallaxLayout: React.FC<PropsWithChildren<IComputedDirectionTypes<
|