-
-
Notifications
You must be signed in to change notification settings - Fork 340
/
Copy pathtypes.ts
269 lines (257 loc) · 8.56 KB
/
types.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
import type { StyleProp, ViewStyle } from "react-native";
import type { PanGesture } from "react-native-gesture-handler";
import type { SharedValue, WithSpringConfig, WithTimingConfig } from "react-native-reanimated";
import type Animated from "react-native-reanimated";
import type { TParallaxModeProps } from "./layouts/parallax";
import type { TStackModeProps } from "./layouts/stack";
// biome-ignore lint/complexity/noBannedTypes: <explanation>
export type IComputedDirectionTypes<T, VP = {}, HP = {}> =
| (T &
VP & {
/**
* Layout items vertically instead of horizontally
*/
vertical: true;
/**
* Layout items vertically instead of horizontally
*/
/**
* Specified carousel container width.
*/
width?: number;
height: number;
})
| (T &
HP & {
/**
* Layout items vertically instead of horizontally
*/
vertical?: false;
/**
* Layout items vertically instead of horizontally
*/
/**
* Specified carousel container width.
*/
width: number;
height?: number;
});
export interface CustomConfig {
type?: "negative" | "positive";
viewCount?: number;
}
export interface WithSpringAnimation {
type: "spring";
config: WithSpringConfig;
}
export interface WithTimingAnimation {
type: "timing";
config: WithTimingConfig;
}
export type WithAnimation = WithSpringAnimation | WithTimingAnimation;
export type TCarouselProps<T = any> = {
/**
* @test_coverage ✅ tested in Carousel.test.tsx > should handle the ref props
*/
ref?: React.Ref<ICarouselInstance>;
/**
* The default animated value of the carousel.
* @test_coverage ✅ tested in Carousel.test.tsx > should render the correct progress value with the defaultScrollOffsetValue props
*/
defaultScrollOffsetValue?: SharedValue<number>;
/**
* Carousel loop playback.
* @default true
* @test_coverage ✅ tested in Carousel.test.tsx > should swipe back to the first item when loop is true
*/
loop?: boolean;
/**
* Carousel items data set.
* @test_coverage ✅ tested in Carousel.test.tsx > should render correctly
*/
data: T[];
/**
* Auto fill data array to allow loop playback when the loop props is true.
* @default true
* @example
* [1] => [1, 1, 1]
* [1, 2] => [1, 2, 1, 2]
* @test_coverage ✅ tested in Carousel.test.tsx > should auto fill data array to allow loop playback when the loop props is true
*/
autoFillData?: boolean;
/**
* Default index
* @default 0
* @test_coverage ✅ tested in Carousel.test.tsx > should render the correct item with the defaultIndex props
*/
defaultIndex?: number;
/**
* Auto play
* @test_coverage ✅ tested in Carousel.test.tsx > should swipe automatically when autoPlay is true
*/
autoPlay?: boolean;
/**
* Auto play
* @description reverse playback
* @test_coverage ✅ tested in Carousel.test.tsx > should swipe automatically in reverse when autoPlayReverse is true
*/
autoPlayReverse?: boolean;
/**
* Auto play
* @description playback interval
*/
autoPlayInterval?: number;
/**
* Time a scroll animation takes to finish
* @default 500 (ms)
*/
scrollAnimationDuration?: number;
/**
* Carousel content style
*/
style?: StyleProp<ViewStyle>;
/**
* Carousel container style
*/
containerStyle?: StyleProp<ViewStyle>;
/**
* PanGesture config
* @test_coverage ✅ tested in Carousel.test.tsx > should call the onConfigurePanGesture callback
*/
onConfigurePanGesture?: (panGesture: PanGesture) => void;
/**
* Determines the maximum number of items will respond to pan gesture events,
* windowSize={11} will active visible item plus up to 5 items above and 5 below the viewpor,
* Reducing this number will reduce the calculation of the animation value and may improve performance.
* @default 0 all items will respond to pan gesture events.
*/
windowSize?: number;
/**
* When true, the scroll view stops on multiples of the scroll view's size when scrolling.
* @default true
* @test_coverage ✅ tested in Carousel.test.tsx > should swipe to the next item when pagingEnabled is true
*/
pagingEnabled?: boolean;
/**
* If enabled, releasing the touch will scroll to the nearest item.
* valid when pagingEnabled=false
* @default true
*/
snapEnabled?: boolean;
/**
* If enabled, items will scroll to the first placement when scrolling past the edge rather than closing to the last. (previous conditions: loop=false)
* @default true
* @test_coverage ✅ tested in Carousel.test.tsx > should respect overscrollEnabled=false and prevent scrolling beyond bounds
*/
overscrollEnabled?: boolean;
/**
* If false, Carousel will not respond to any gestures.
* @default true
*/
enabled?: boolean;
/**
* Specifies the scrolling animation effect.
*/
withAnimation?: WithAnimation;
/**
* Used to locate this view in end-to-end tests.
*/
testID?: string;
/**
* Maximum offset value for once scroll.
* Carousel cannot scroll over than this value.
* */
maxScrollDistancePerSwipe?: number;
/**
* Minimum offset value for once scroll.
* If the translation value is less than this value, the carousel will not scroll.
* */
minScrollDistancePerSwipe?: number;
/**
* @experimental This API will be changed in the future.
* If positive, the carousel will scroll to the positive direction and vice versa.
* @test_coverage ✅ tested in Carousel.test.tsx > should swipe to the correct direction when fixedDirection is positive
* */
fixedDirection?: "positive" | "negative";
/**
* Custom carousel config.
*/
customConfig?: () => CustomConfig;
/**
* Custom animations.
* Must use `worklet`, Details: https://docs.swmansion.com/react-native-reanimated/docs/2.2.0/worklets/
* @test_coverage ✅ tested in Carousel.test.tsx > should apply the custom animation
*/
customAnimation?: (value: number, index: number) => ViewStyle;
/**
* Render carousel item.
* @test_coverage ✅ tested in Carousel.test.tsx > should render items correctly
*/
renderItem: CarouselRenderItem<T>;
/**
* Callback fired when navigating to an item.
* @test_coverage ✅ tested in Carousel.test.tsx > should call the onSnapToItem callback
*/
onSnapToItem?: (index: number) => void;
/**
* On scroll start
* @test_coverage ✅ tested in Carousel.test.tsx > should call the onScrollStart callback
*/
onScrollStart?: () => void;
/**
* On scroll end
* @test_coverage ✅ tested in Carousel.test.tsx > should call the onScrollEnd callback
*/
onScrollEnd?: (index: number) => void;
/**
* On progress change
* @param offsetProgress Total of offset distance (0 390 780 ...)
* @param absoluteProgress Convert to index (0 1 2 ...)
* @test_coverage ✅ tested in Carousel.test.tsx > should call the onProgressChange callback
*
* If you want to update a shared value automatically, you can use the shared value as a parameter directly.
*/
onProgressChange?:
| ((offsetProgress: number, absoluteProgress: number) => void)
| SharedValue<number>;
// ============================== deprecated props ==============================
/**
* If enabled, releasing the touch will scroll to the nearest item.
* valid when pagingEnabled=false
* @deprecated please use snapEnabled instead
*/
enableSnap?: boolean;
} & (TParallaxModeProps | TStackModeProps);
export interface ICarouselInstance {
/**
* Scroll to previous item, it takes one optional argument (count),
* which allows you to specify how many items to cross
*/
prev: (opts?: Omit<TCarouselActionOptions, "index">) => void;
/**
* Scroll to next item, it takes one optional argument (count),
* which allows you to specify how many items to cross
*/
next: (opts?: Omit<TCarouselActionOptions, "index">) => void;
/**
* Get current item index
*/
getCurrentIndex: () => number;
/**
* Use value to scroll to a position where relative to the current position,
* scrollTo({count: -2}) is equivalent to prev(2), scrollTo({count: 2}) is equivalent to next(2)
*/
scrollTo: (opts?: TCarouselActionOptions) => void;
}
export interface CarouselRenderItemInfo<ItemT> {
item: ItemT;
index: number;
animationValue: Animated.SharedValue<number>;
}
export type CarouselRenderItem<ItemT> = (info: CarouselRenderItemInfo<ItemT>) => React.ReactElement;
export interface TCarouselActionOptions {
index?: number;
count?: number;
animated?: boolean;
onFinished?: () => void;
}