@momo-kits/carousel 0.165.2-beta.2 → 0.167.1-beta.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/animation.ts +62 -0
- package/index.tsx +455 -390
- package/package.json +5 -6
- package/types.ts +48 -123
- package/core/LICENSE +0 -21
- package/core/README.md +0 -16
- package/core/components/Carousel.tsx +0 -28
- package/core/components/CarouselLayout.tsx +0 -231
- package/core/components/ItemLayout.tsx +0 -215
- package/core/components/ItemRenderer.tsx +0 -126
- package/core/components/LazyView.tsx +0 -14
- package/core/components/ScrollViewGesture.tsx +0 -443
- package/core/constants/index.ts +0 -11
- package/core/hooks/useAutoPlay.ts +0 -63
- package/core/hooks/useCarouselController.tsx +0 -295
- package/core/hooks/useCheckMounted.ts +0 -14
- package/core/hooks/useCommonVariables.ts +0 -261
- package/core/hooks/useInitProps.ts +0 -177
- package/core/hooks/useLayoutConfig.ts +0 -35
- package/core/hooks/useOffsetX.ts +0 -81
- package/core/hooks/useOnProgressChange.ts +0 -33
- package/core/hooks/usePanGestureProxy.ts +0 -144
- package/core/hooks/usePropsErrorBoundary.ts +0 -41
- package/core/hooks/useUpdateGestureConfig.ts +0 -17
- package/core/hooks/useVisibleRanges.tsx +0 -141
- package/core/layouts/index.tsx +0 -10
- package/core/layouts/normal.ts +0 -32
- package/core/layouts/parallax.ts +0 -50
- package/core/layouts/stack.ts +0 -266
- package/core/public-types.ts +0 -209
- package/core/store/index.tsx +0 -63
- package/core/types.ts +0 -32
- package/core/utils/carousel-direction.ts +0 -39
- package/core/utils/carousel-math.ts +0 -156
- package/core/utils/compute-gesture-translation.ts +0 -29
- package/core/utils/compute-offset-if-size-changed.ts +0 -14
- package/core/utils/computed-with-auto-fill-data.ts +0 -92
- package/core/utils/deal-with-animation.ts +0 -19
- package/core/utils/log.ts +0 -12
- package/core/utils/sanitize-animation-style.ts +0 -20
package/core/layouts/normal.ts
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { interpolate } from "react-native-reanimated";
|
|
2
|
-
|
|
3
|
-
import type { CarouselDirectionSign } from "../utils/carousel-direction";
|
|
4
|
-
import { toPhysicalHorizontalValue } from "../utils/carousel-direction";
|
|
5
|
-
|
|
6
|
-
export function normalLayout(opts: {
|
|
7
|
-
size: number;
|
|
8
|
-
isVertical: boolean;
|
|
9
|
-
directionSign: CarouselDirectionSign;
|
|
10
|
-
}) {
|
|
11
|
-
const { size, isVertical, directionSign } = opts;
|
|
12
|
-
|
|
13
|
-
return (value: number) => {
|
|
14
|
-
"worklet";
|
|
15
|
-
const logicalTranslate = interpolate(value, [-1, 0, 1], [-size, 0, size]);
|
|
16
|
-
const translate = isVertical
|
|
17
|
-
? logicalTranslate
|
|
18
|
-
: toPhysicalHorizontalValue(logicalTranslate, directionSign);
|
|
19
|
-
|
|
20
|
-
return {
|
|
21
|
-
transform: [
|
|
22
|
-
isVertical
|
|
23
|
-
? {
|
|
24
|
-
translateY: translate,
|
|
25
|
-
}
|
|
26
|
-
: {
|
|
27
|
-
translateX: translate,
|
|
28
|
-
},
|
|
29
|
-
],
|
|
30
|
-
};
|
|
31
|
-
};
|
|
32
|
-
}
|
package/core/layouts/parallax.ts
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import { Extrapolation, interpolate } from "react-native-reanimated";
|
|
2
|
-
|
|
3
|
-
import type { CarouselLayout } from "../types";
|
|
4
|
-
import type { CarouselDirectionSign } from "../utils/carousel-direction";
|
|
5
|
-
import { toPhysicalHorizontalValue } from "../utils/carousel-direction";
|
|
6
|
-
|
|
7
|
-
type ParallaxLayout = Extract<CarouselLayout, { type: "parallax" }>;
|
|
8
|
-
|
|
9
|
-
export function parallaxLayout(
|
|
10
|
-
baseConfig: {
|
|
11
|
-
size: number;
|
|
12
|
-
isVertical: boolean;
|
|
13
|
-
directionSign: CarouselDirectionSign;
|
|
14
|
-
},
|
|
15
|
-
config: ParallaxLayout
|
|
16
|
-
) {
|
|
17
|
-
const { size, isVertical, directionSign } = baseConfig;
|
|
18
|
-
const { offset = 100, scale = 0.8, adjacentScale = scale ** 2 } = config;
|
|
19
|
-
|
|
20
|
-
return (relativeProgress: number) => {
|
|
21
|
-
"worklet";
|
|
22
|
-
const logicalTranslate = interpolate(
|
|
23
|
-
relativeProgress,
|
|
24
|
-
[-1, 0, 1],
|
|
25
|
-
[-size + offset, 0, size - offset]
|
|
26
|
-
);
|
|
27
|
-
const translate = isVertical
|
|
28
|
-
? logicalTranslate
|
|
29
|
-
: toPhysicalHorizontalValue(logicalTranslate, directionSign);
|
|
30
|
-
|
|
31
|
-
const zIndex = Math.round(
|
|
32
|
-
interpolate(relativeProgress, [-1, 0, 1], [0, size, 0], Extrapolation.CLAMP)
|
|
33
|
-
);
|
|
34
|
-
|
|
35
|
-
const animatedScale = interpolate(
|
|
36
|
-
relativeProgress,
|
|
37
|
-
[-1, 0, 1],
|
|
38
|
-
[adjacentScale, scale, adjacentScale],
|
|
39
|
-
Extrapolation.CLAMP
|
|
40
|
-
);
|
|
41
|
-
|
|
42
|
-
return {
|
|
43
|
-
transform: [
|
|
44
|
-
isVertical ? { translateY: translate } : { translateX: translate },
|
|
45
|
-
{ scale: animatedScale },
|
|
46
|
-
],
|
|
47
|
-
zIndex,
|
|
48
|
-
};
|
|
49
|
-
};
|
|
50
|
-
}
|
package/core/layouts/stack.ts
DELETED
|
@@ -1,266 +0,0 @@
|
|
|
1
|
-
import type { TransformsStyle, ViewStyle } from "react-native";
|
|
2
|
-
import { Dimensions } from "react-native";
|
|
3
|
-
import { Extrapolation, interpolate } from "react-native-reanimated";
|
|
4
|
-
|
|
5
|
-
import type { CarouselLayout } from "../types";
|
|
6
|
-
import type { CarouselDirectionSign } from "../utils/carousel-direction";
|
|
7
|
-
import { toPhysicalHorizontalValue } from "../utils/carousel-direction";
|
|
8
|
-
|
|
9
|
-
const screen = Dimensions.get("window");
|
|
10
|
-
|
|
11
|
-
type StackLayout = Extract<CarouselLayout, { type: "horizontal-stack" | "vertical-stack" }>;
|
|
12
|
-
|
|
13
|
-
export function horizontalStackLayout(
|
|
14
|
-
config: StackLayout,
|
|
15
|
-
directionSign: CarouselDirectionSign = 1
|
|
16
|
-
) {
|
|
17
|
-
return (_value: number) => {
|
|
18
|
-
"worklet";
|
|
19
|
-
|
|
20
|
-
const {
|
|
21
|
-
visibleCount,
|
|
22
|
-
exitDirection: snapDirection = "left",
|
|
23
|
-
exitDistance: moveSize = screen.width,
|
|
24
|
-
spacing: stackInterval = 18,
|
|
25
|
-
scaleStep: scaleInterval = 0.04,
|
|
26
|
-
opacityStep: opacityInterval = 0.1,
|
|
27
|
-
rotation: rotateZDeg = 30,
|
|
28
|
-
} = config;
|
|
29
|
-
|
|
30
|
-
const physicalProgress = toPhysicalHorizontalValue(_value, directionSign);
|
|
31
|
-
const { validLength, value, inputRange } = getCommonVariables({
|
|
32
|
-
showLength: visibleCount!,
|
|
33
|
-
value: physicalProgress,
|
|
34
|
-
snapDirection,
|
|
35
|
-
});
|
|
36
|
-
const { zIndex, opacity } = getCommonStyles({
|
|
37
|
-
validLength,
|
|
38
|
-
value,
|
|
39
|
-
opacityInterval,
|
|
40
|
-
snapDirection,
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
let translateX: number;
|
|
44
|
-
let scale: number;
|
|
45
|
-
let rotateZ: string;
|
|
46
|
-
|
|
47
|
-
if (snapDirection === "left") {
|
|
48
|
-
translateX = interpolate(
|
|
49
|
-
value,
|
|
50
|
-
inputRange,
|
|
51
|
-
[-moveSize, 0, validLength * stackInterval],
|
|
52
|
-
Extrapolation.CLAMP
|
|
53
|
-
);
|
|
54
|
-
scale = interpolate(
|
|
55
|
-
value,
|
|
56
|
-
inputRange,
|
|
57
|
-
[1, 1, 1 - validLength * scaleInterval],
|
|
58
|
-
Extrapolation.CLAMP
|
|
59
|
-
);
|
|
60
|
-
rotateZ = `${interpolate(value, inputRange, [-rotateZDeg, 0, 0], Extrapolation.CLAMP)}deg`;
|
|
61
|
-
} else if (snapDirection === "right") {
|
|
62
|
-
translateX = interpolate(
|
|
63
|
-
value,
|
|
64
|
-
inputRange,
|
|
65
|
-
[-validLength * stackInterval, 0, moveSize],
|
|
66
|
-
Extrapolation.CLAMP
|
|
67
|
-
);
|
|
68
|
-
scale = interpolate(
|
|
69
|
-
value,
|
|
70
|
-
inputRange,
|
|
71
|
-
[1 - validLength * scaleInterval, 1, 1],
|
|
72
|
-
Extrapolation.CLAMP
|
|
73
|
-
);
|
|
74
|
-
rotateZ = `${interpolate(value, inputRange, [0, 0, rotateZDeg], Extrapolation.CLAMP)}deg`;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
const transform: TransformsStyle["transform"] = [
|
|
78
|
-
{
|
|
79
|
-
translateX: translateX!,
|
|
80
|
-
},
|
|
81
|
-
{
|
|
82
|
-
scale: scale!,
|
|
83
|
-
},
|
|
84
|
-
{
|
|
85
|
-
rotateZ: rotateZ!,
|
|
86
|
-
},
|
|
87
|
-
];
|
|
88
|
-
|
|
89
|
-
const styles: ViewStyle = {
|
|
90
|
-
transform,
|
|
91
|
-
zIndex,
|
|
92
|
-
opacity,
|
|
93
|
-
};
|
|
94
|
-
|
|
95
|
-
return styles;
|
|
96
|
-
};
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
export function verticalStackLayout(config: StackLayout) {
|
|
100
|
-
return (_value: number) => {
|
|
101
|
-
"worklet";
|
|
102
|
-
|
|
103
|
-
const {
|
|
104
|
-
visibleCount,
|
|
105
|
-
exitDirection: snapDirection = "left",
|
|
106
|
-
exitDistance: moveSize = screen.width,
|
|
107
|
-
spacing: stackInterval = 18,
|
|
108
|
-
scaleStep: scaleInterval = 0.04,
|
|
109
|
-
opacityStep: opacityInterval = 0.1,
|
|
110
|
-
rotation: rotateZDeg = 30,
|
|
111
|
-
} = config;
|
|
112
|
-
|
|
113
|
-
const { validLength, value, inputRange } = getCommonVariables({
|
|
114
|
-
showLength: visibleCount!,
|
|
115
|
-
value: _value,
|
|
116
|
-
snapDirection,
|
|
117
|
-
});
|
|
118
|
-
const { zIndex, opacity } = getCommonStyles({
|
|
119
|
-
validLength,
|
|
120
|
-
value,
|
|
121
|
-
opacityInterval,
|
|
122
|
-
snapDirection,
|
|
123
|
-
});
|
|
124
|
-
|
|
125
|
-
let translateX: number;
|
|
126
|
-
let scale: number;
|
|
127
|
-
let rotateZ: string;
|
|
128
|
-
let translateY: number;
|
|
129
|
-
|
|
130
|
-
if (snapDirection === "left") {
|
|
131
|
-
translateX = interpolate(value, inputRange, [-moveSize, 0, 0], Extrapolation.CLAMP);
|
|
132
|
-
scale = interpolate(
|
|
133
|
-
value,
|
|
134
|
-
inputRange,
|
|
135
|
-
[1, 1, 1 - validLength * scaleInterval],
|
|
136
|
-
Extrapolation.CLAMP
|
|
137
|
-
);
|
|
138
|
-
rotateZ = `${interpolate(value, inputRange, [-rotateZDeg, 0, 0], Extrapolation.CLAMP)}deg`;
|
|
139
|
-
translateY = interpolate(
|
|
140
|
-
value,
|
|
141
|
-
inputRange,
|
|
142
|
-
[0, 0, validLength * stackInterval],
|
|
143
|
-
Extrapolation.CLAMP
|
|
144
|
-
);
|
|
145
|
-
} else if (snapDirection === "right") {
|
|
146
|
-
translateX = interpolate(value, inputRange, [0, 0, moveSize], Extrapolation.CLAMP);
|
|
147
|
-
scale = interpolate(
|
|
148
|
-
value,
|
|
149
|
-
inputRange,
|
|
150
|
-
[1 - validLength * scaleInterval, 1, 1],
|
|
151
|
-
Extrapolation.CLAMP
|
|
152
|
-
);
|
|
153
|
-
rotateZ = `${interpolate(value, inputRange, [0, 0, rotateZDeg], Extrapolation.CLAMP)}deg`;
|
|
154
|
-
translateY = interpolate(
|
|
155
|
-
value,
|
|
156
|
-
inputRange,
|
|
157
|
-
[validLength * stackInterval, 0, 0],
|
|
158
|
-
Extrapolation.CLAMP
|
|
159
|
-
);
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
const transform: TransformsStyle["transform"] = [
|
|
163
|
-
{
|
|
164
|
-
translateX: translateX!,
|
|
165
|
-
},
|
|
166
|
-
{
|
|
167
|
-
scale: scale!,
|
|
168
|
-
},
|
|
169
|
-
{
|
|
170
|
-
rotateZ: rotateZ!,
|
|
171
|
-
},
|
|
172
|
-
{
|
|
173
|
-
translateY: translateY!,
|
|
174
|
-
},
|
|
175
|
-
];
|
|
176
|
-
|
|
177
|
-
const styles: ViewStyle = {
|
|
178
|
-
transform,
|
|
179
|
-
zIndex,
|
|
180
|
-
opacity,
|
|
181
|
-
};
|
|
182
|
-
|
|
183
|
-
return styles;
|
|
184
|
-
};
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
function getCommonVariables(opts: {
|
|
188
|
-
value: number;
|
|
189
|
-
showLength: number;
|
|
190
|
-
snapDirection: "left" | "right";
|
|
191
|
-
}) {
|
|
192
|
-
"worklet";
|
|
193
|
-
|
|
194
|
-
const { showLength, value: _value, snapDirection } = opts;
|
|
195
|
-
function easeInOutCubic(v: number): number {
|
|
196
|
-
return v < 0.5 ? 4 * v * v * v : 1 - (-2 * v + 2) ** 3 / 2;
|
|
197
|
-
}
|
|
198
|
-
const page = Math.floor(Math.abs(_value));
|
|
199
|
-
const diff = Math.abs(_value) % 1;
|
|
200
|
-
const value = _value < 0 ? -(page + easeInOutCubic(diff)) : page + easeInOutCubic(diff);
|
|
201
|
-
const validLength = showLength! - 1;
|
|
202
|
-
|
|
203
|
-
let inputRange: [number, number, number];
|
|
204
|
-
|
|
205
|
-
if (snapDirection === "left") inputRange = [-1, 0, validLength];
|
|
206
|
-
else if (snapDirection === "right") inputRange = [-validLength, 0, 1];
|
|
207
|
-
else throw new Error("snapDirection must be set to either left or right");
|
|
208
|
-
|
|
209
|
-
return {
|
|
210
|
-
inputRange,
|
|
211
|
-
validLength,
|
|
212
|
-
value,
|
|
213
|
-
};
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
function getCommonStyles(opts: {
|
|
217
|
-
value: number;
|
|
218
|
-
validLength: number;
|
|
219
|
-
opacityInterval: number;
|
|
220
|
-
snapDirection: "left" | "right";
|
|
221
|
-
}) {
|
|
222
|
-
"worklet";
|
|
223
|
-
|
|
224
|
-
const { snapDirection, validLength, value, opacityInterval } = opts;
|
|
225
|
-
|
|
226
|
-
let zIndex: number;
|
|
227
|
-
let opacity: number;
|
|
228
|
-
|
|
229
|
-
if (snapDirection === "left") {
|
|
230
|
-
zIndex =
|
|
231
|
-
Math.floor(
|
|
232
|
-
interpolate(
|
|
233
|
-
value,
|
|
234
|
-
[-1.5, -1, -1 + Number.MIN_VALUE, 0, validLength],
|
|
235
|
-
[Number.MIN_VALUE, validLength, validLength, validLength - 1, -1]
|
|
236
|
-
) * 10000
|
|
237
|
-
) / 100;
|
|
238
|
-
|
|
239
|
-
opacity = interpolate(
|
|
240
|
-
value,
|
|
241
|
-
[-1, 0, validLength - 1, validLength],
|
|
242
|
-
[0.25, 1, 1 - (validLength - 1) * opacityInterval, 0.25]
|
|
243
|
-
);
|
|
244
|
-
} else if (snapDirection === "right") {
|
|
245
|
-
zIndex =
|
|
246
|
-
Math.floor(
|
|
247
|
-
interpolate(
|
|
248
|
-
value,
|
|
249
|
-
[-validLength, 0, 1 - Number.MIN_VALUE, 1, 1.5],
|
|
250
|
-
[1, validLength - 1, validLength, validLength, Number.MIN_VALUE]
|
|
251
|
-
) * 10000
|
|
252
|
-
) / 100;
|
|
253
|
-
opacity = interpolate(
|
|
254
|
-
value,
|
|
255
|
-
[-validLength, 1 - validLength, 0, 1],
|
|
256
|
-
[0.25, 1 - (validLength - 1) * opacityInterval, 1, 0.25]
|
|
257
|
-
);
|
|
258
|
-
} else {
|
|
259
|
-
throw new Error("snapDirection must be set to either left or right");
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
return {
|
|
263
|
-
zIndex: Math.round(zIndex),
|
|
264
|
-
opacity,
|
|
265
|
-
};
|
|
266
|
-
}
|
package/core/public-types.ts
DELETED
|
@@ -1,209 +0,0 @@
|
|
|
1
|
-
import type * as React from "react";
|
|
2
|
-
import type { ColorValue, LayoutChangeEvent, StyleProp, ViewStyle } from "react-native";
|
|
3
|
-
import type {
|
|
4
|
-
GestureStateChangeEvent,
|
|
5
|
-
GestureType,
|
|
6
|
-
GestureUpdateEvent,
|
|
7
|
-
MouseButton,
|
|
8
|
-
PanGesture,
|
|
9
|
-
PanGestureChangeEventPayload,
|
|
10
|
-
PanGestureHandlerEventPayload,
|
|
11
|
-
PanGestureHandlerProps,
|
|
12
|
-
} from "react-native-gesture-handler";
|
|
13
|
-
import type { SharedValue, WithSpringConfig, WithTimingConfig } from "react-native-reanimated";
|
|
14
|
-
|
|
15
|
-
type CarouselOrientation = "horizontal" | "vertical";
|
|
16
|
-
type CarouselSnapMode = "page" | "nearest" | "none";
|
|
17
|
-
type CarouselAutoplayDirection = "forward" | "backward";
|
|
18
|
-
type CarouselExitDirection = "left" | "right";
|
|
19
|
-
|
|
20
|
-
type CarouselContentContainerStyle = Omit<ViewStyle, "opacity" | "transform">;
|
|
21
|
-
|
|
22
|
-
type CarouselExternalGestureRef =
|
|
23
|
-
| GestureType
|
|
24
|
-
| React.RefObject<GestureType | undefined>
|
|
25
|
-
| React.RefObject<React.ComponentType | undefined>;
|
|
26
|
-
|
|
27
|
-
type CarouselPanStateEvent = GestureStateChangeEvent<PanGestureHandlerEventPayload>;
|
|
28
|
-
type CarouselPanUpdateEvent = GestureUpdateEvent<PanGestureHandlerEventPayload>;
|
|
29
|
-
type CarouselPanChangeEvent = GestureUpdateEvent<
|
|
30
|
-
PanGestureHandlerEventPayload & PanGestureChangeEventPayload
|
|
31
|
-
>;
|
|
32
|
-
|
|
33
|
-
type CarouselLayoutSelection =
|
|
34
|
-
| {
|
|
35
|
-
layout?: CarouselLayout;
|
|
36
|
-
itemAnimation?: never;
|
|
37
|
-
}
|
|
38
|
-
| {
|
|
39
|
-
layout?: never;
|
|
40
|
-
itemAnimation: CarouselItemAnimation;
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
type InteractivePaginationProps = {
|
|
44
|
-
onPress: (index: number) => void;
|
|
45
|
-
getItemAccessibilityLabel?: (index: number, count: number) => string;
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
type DecorativePaginationProps = {
|
|
49
|
-
onPress?: never;
|
|
50
|
-
getItemAccessibilityLabel?: never;
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
type ReadonlyProgressValue = Omit<SharedValue<number>, "modify" | "set" | "value"> & {
|
|
54
|
-
readonly value: number;
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
type PaginationBaseProps = {
|
|
58
|
-
count: number;
|
|
59
|
-
progress: ReadonlyProgressValue;
|
|
60
|
-
orientation?: CarouselOrientation;
|
|
61
|
-
containerStyle?: StyleProp<Omit<ViewStyle, "direction" | "flexDirection">>;
|
|
62
|
-
dotStyle?: PaginationDotStyle;
|
|
63
|
-
activeDotStyle?: PaginationDotStyle;
|
|
64
|
-
};
|
|
65
|
-
|
|
66
|
-
export type CarouselProps<Item> = {
|
|
67
|
-
data: Item[];
|
|
68
|
-
renderItem: CarouselRenderItem<Item>;
|
|
69
|
-
keyExtractor?: (item: Item, index: number) => string;
|
|
70
|
-
defaultIndex?: number;
|
|
71
|
-
loop?: boolean;
|
|
72
|
-
autoplay?: boolean;
|
|
73
|
-
autoplayInterval?: number;
|
|
74
|
-
autoplayDirection?: CarouselAutoplayDirection;
|
|
75
|
-
orientation?: CarouselOrientation;
|
|
76
|
-
itemSize?: number;
|
|
77
|
-
scrollEnabled?: boolean;
|
|
78
|
-
snapMode?: CarouselSnapMode;
|
|
79
|
-
overscrollEnabled?: boolean;
|
|
80
|
-
renderWindowSize?: number;
|
|
81
|
-
animation?: CarouselAnimation;
|
|
82
|
-
progress?: SharedValue<number>;
|
|
83
|
-
onProgressChange?: CarouselProgressChangeHandler;
|
|
84
|
-
scrollOffsetValue?: SharedValue<number>;
|
|
85
|
-
style?: StyleProp<ViewStyle>;
|
|
86
|
-
contentContainerStyle?: StyleProp<CarouselContentContainerStyle>;
|
|
87
|
-
testID?: string;
|
|
88
|
-
onLayout?: (event: LayoutChangeEvent) => void;
|
|
89
|
-
onConfigurePanGesture?: (gesture: CarouselPanGesture) => void;
|
|
90
|
-
onScrollStart?: () => void;
|
|
91
|
-
onSnapToItem?: (index: number) => void;
|
|
92
|
-
} & CarouselLayoutSelection;
|
|
93
|
-
|
|
94
|
-
export interface CarouselRef {
|
|
95
|
-
prev(options?: CarouselStepOptions): void;
|
|
96
|
-
next(options?: CarouselStepOptions): void;
|
|
97
|
-
getCurrentIndex(): number;
|
|
98
|
-
scrollTo(options: CarouselScrollToOptions): void;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
export type CarouselRenderItem<Item> = (info: CarouselRenderItemInfo<Item>) => React.ReactElement;
|
|
102
|
-
|
|
103
|
-
export interface CarouselRenderItemInfo<Item> {
|
|
104
|
-
item: Item;
|
|
105
|
-
index: number;
|
|
106
|
-
relativeProgress: SharedValue<number>;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
export type CarouselProgressChangeHandler = (progress: number) => void;
|
|
110
|
-
|
|
111
|
-
export type CarouselLayout =
|
|
112
|
-
| {
|
|
113
|
-
type: "parallax";
|
|
114
|
-
offset?: number;
|
|
115
|
-
scale?: number;
|
|
116
|
-
adjacentScale?: number;
|
|
117
|
-
}
|
|
118
|
-
| {
|
|
119
|
-
type: "horizontal-stack";
|
|
120
|
-
visibleCount?: number;
|
|
121
|
-
exitDistance?: number;
|
|
122
|
-
spacing?: number;
|
|
123
|
-
scaleStep?: number;
|
|
124
|
-
opacityStep?: number;
|
|
125
|
-
rotation?: number;
|
|
126
|
-
exitDirection?: CarouselExitDirection;
|
|
127
|
-
}
|
|
128
|
-
| {
|
|
129
|
-
type: "vertical-stack";
|
|
130
|
-
visibleCount?: number;
|
|
131
|
-
exitDistance?: number;
|
|
132
|
-
spacing?: number;
|
|
133
|
-
scaleStep?: number;
|
|
134
|
-
opacityStep?: number;
|
|
135
|
-
rotation?: number;
|
|
136
|
-
exitDirection?: CarouselExitDirection;
|
|
137
|
-
};
|
|
138
|
-
|
|
139
|
-
export type CarouselAnimation =
|
|
140
|
-
| ({ type: "timing" } & WithTimingConfig)
|
|
141
|
-
| ({ type: "spring" } & WithSpringConfig);
|
|
142
|
-
|
|
143
|
-
export type CarouselItemAnimation = (relativeProgress: number, index: number) => ViewStyle;
|
|
144
|
-
|
|
145
|
-
/**
|
|
146
|
-
* Supported configuration surface for Carousel's real RNGH pan gesture.
|
|
147
|
-
*
|
|
148
|
-
* Methods return this facade so chaining never exposes ownership-changing RNGH
|
|
149
|
-
* methods such as `enabled`, `runOnJS`, or `manualActivation`.
|
|
150
|
-
*/
|
|
151
|
-
export interface CarouselPanGesture {
|
|
152
|
-
/**
|
|
153
|
-
* Controlled view of the underlying RNGH pan gesture configuration.
|
|
154
|
-
*
|
|
155
|
-
* Exposes the web-only `touchAction` option (e.g. `"pan-y"` so a
|
|
156
|
-
* horizontal carousel nested in a vertically scrollable page keeps native
|
|
157
|
-
* vertical scrolling on mobile web) without casting away the facade.
|
|
158
|
-
* Ownership-changing options such as `enabled`, `runOnJS`, or
|
|
159
|
-
* `manualActivation` intentionally stay hidden.
|
|
160
|
-
*/
|
|
161
|
-
readonly config: Pick<PanGesture["config"], "touchAction">;
|
|
162
|
-
activeOffsetX(offset: number | [start: number, end: number]): this;
|
|
163
|
-
activeOffsetY(offset: number | [start: number, end: number]): this;
|
|
164
|
-
failOffsetX(offset: number | [start: number, end: number]): this;
|
|
165
|
-
failOffsetY(offset: number | [start: number, end: number]): this;
|
|
166
|
-
minPointers(count: number): this;
|
|
167
|
-
maxPointers(count: number): this;
|
|
168
|
-
minDistance(distance: number): this;
|
|
169
|
-
minVelocity(velocity: number): this;
|
|
170
|
-
minVelocityX(velocity: number): this;
|
|
171
|
-
minVelocityY(velocity: number): this;
|
|
172
|
-
averageTouches(value: boolean): this;
|
|
173
|
-
enableTrackpadTwoFingerGesture(value: boolean): this;
|
|
174
|
-
activateAfterLongPress(duration: number): this;
|
|
175
|
-
hitSlop(value: PanGestureHandlerProps["hitSlop"]): this;
|
|
176
|
-
mouseButton(button: MouseButton): this;
|
|
177
|
-
simultaneousWithExternalGesture(...gestures: CarouselExternalGestureRef[]): this;
|
|
178
|
-
requireExternalGestureToFail(...gestures: CarouselExternalGestureRef[]): this;
|
|
179
|
-
blocksExternalGesture(...gestures: CarouselExternalGestureRef[]): this;
|
|
180
|
-
onBegin(callback: (event: CarouselPanStateEvent) => void): this;
|
|
181
|
-
onStart(callback: (event: CarouselPanStateEvent) => void): this;
|
|
182
|
-
onUpdate(callback: (event: CarouselPanUpdateEvent) => void): this;
|
|
183
|
-
onChange(callback: (event: CarouselPanChangeEvent) => void): this;
|
|
184
|
-
onEnd(callback: (event: CarouselPanStateEvent, success: boolean) => void): this;
|
|
185
|
-
onFinalize(callback: (event: CarouselPanStateEvent, success: boolean) => void): this;
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
export interface CarouselStepOptions {
|
|
189
|
-
count?: number;
|
|
190
|
-
animated?: boolean;
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
export interface CarouselScrollToOptions {
|
|
194
|
-
index: number;
|
|
195
|
-
animated?: boolean;
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
export type PaginationProps = PaginationBaseProps &
|
|
199
|
-
(InteractivePaginationProps | DecorativePaginationProps);
|
|
200
|
-
|
|
201
|
-
export interface PaginationDotStyle {
|
|
202
|
-
width?: number;
|
|
203
|
-
height?: number;
|
|
204
|
-
borderRadius?: number;
|
|
205
|
-
borderWidth?: number;
|
|
206
|
-
borderColor?: ColorValue;
|
|
207
|
-
backgroundColor?: ColorValue;
|
|
208
|
-
opacity?: number;
|
|
209
|
-
}
|
package/core/store/index.tsx
DELETED
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
|
|
3
|
-
import { type SharedValue, useSharedValue } from "react-native-reanimated";
|
|
4
|
-
import type { CarouselCommonVariables } from "../hooks/useCommonVariables";
|
|
5
|
-
import type { InitializedCarouselProps } from "../hooks/useInitProps";
|
|
6
|
-
|
|
7
|
-
type ItemDimensions = Record<number, { width: number; height: number }>;
|
|
8
|
-
|
|
9
|
-
export interface CarouselContext {
|
|
10
|
-
props: InitializedCarouselProps<unknown>;
|
|
11
|
-
common: CarouselCommonVariables;
|
|
12
|
-
layout: {
|
|
13
|
-
containerSize: SharedValue<{ width: number; height: number }>;
|
|
14
|
-
updateContainerSize: (dimensions: { width: number; height: number }) => void;
|
|
15
|
-
itemDimensions: SharedValue<ItemDimensions>;
|
|
16
|
-
updateItemDimensions: (index: number, dimensions: { width: number; height: number }) => void;
|
|
17
|
-
};
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export const GlobalStateContext = React.createContext<CarouselContext>({} as CarouselContext);
|
|
21
|
-
|
|
22
|
-
export const GlobalStateProvider = ({
|
|
23
|
-
children,
|
|
24
|
-
value,
|
|
25
|
-
}: {
|
|
26
|
-
children: React.ReactNode;
|
|
27
|
-
value: Pick<CarouselContext, "props" | "common">;
|
|
28
|
-
}) => {
|
|
29
|
-
const containerSize = useSharedValue<{ width: number; height: number }>({ width: 0, height: 0 });
|
|
30
|
-
const itemDimensions = useSharedValue<ItemDimensions>({});
|
|
31
|
-
|
|
32
|
-
const updateItemDimensions = (index: number, dimensions: { width: number; height: number }) => {
|
|
33
|
-
"worklet";
|
|
34
|
-
|
|
35
|
-
itemDimensions.value = { ...itemDimensions.value, [index]: dimensions };
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
const updateContainerSize = (dimensions: { width: number; height: number }) => {
|
|
39
|
-
"worklet";
|
|
40
|
-
containerSize.value = dimensions;
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
return (
|
|
44
|
-
<GlobalStateContext.Provider
|
|
45
|
-
value={{
|
|
46
|
-
...value,
|
|
47
|
-
layout: { containerSize, itemDimensions, updateItemDimensions, updateContainerSize },
|
|
48
|
-
}}
|
|
49
|
-
>
|
|
50
|
-
{children}
|
|
51
|
-
</GlobalStateContext.Provider>
|
|
52
|
-
);
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
export const useGlobalState = () => {
|
|
56
|
-
const context = React.useContext(GlobalStateContext);
|
|
57
|
-
|
|
58
|
-
if (!context) {
|
|
59
|
-
throw new Error("useGlobalState must be used within a GlobalStateProvider");
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
return context;
|
|
63
|
-
};
|
package/core/types.ts
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import type { CarouselProps, CarouselScrollToOptions, CarouselStepOptions } from "./public-types";
|
|
2
|
-
|
|
3
|
-
export type {
|
|
4
|
-
CarouselAnimation,
|
|
5
|
-
CarouselItemAnimation,
|
|
6
|
-
CarouselLayout,
|
|
7
|
-
CarouselPanGesture,
|
|
8
|
-
CarouselProgressChangeHandler,
|
|
9
|
-
CarouselProps,
|
|
10
|
-
CarouselRef,
|
|
11
|
-
CarouselRenderItem,
|
|
12
|
-
CarouselRenderItemInfo,
|
|
13
|
-
CarouselScrollToOptions,
|
|
14
|
-
CarouselStepOptions,
|
|
15
|
-
PaginationDotStyle,
|
|
16
|
-
PaginationProps,
|
|
17
|
-
} from "./public-types";
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Internal command options retain a completion hook so autoplay can schedule
|
|
21
|
-
* the next dwell period after a transition settles. This is never exported
|
|
22
|
-
* from the package root.
|
|
23
|
-
*/
|
|
24
|
-
export type InternalCarouselStepOptions = CarouselStepOptions & {
|
|
25
|
-
onFinished?: () => void;
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
export type InternalCarouselScrollToOptions = CarouselScrollToOptions & {
|
|
29
|
-
onFinished?: () => void;
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
export type InternalCarouselProps<Item> = CarouselProps<Item>;
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
export type CarouselDirectionSign = -1 | 1;
|
|
2
|
-
|
|
3
|
-
export function getCarouselDirectionSign(options: {
|
|
4
|
-
isRTL: boolean;
|
|
5
|
-
orientation: "horizontal" | "vertical";
|
|
6
|
-
}): CarouselDirectionSign {
|
|
7
|
-
"worklet";
|
|
8
|
-
|
|
9
|
-
return options.orientation === "horizontal" && options.isRTL ? -1 : 1;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export function toLogicalGestureValue(
|
|
13
|
-
physicalValue: number,
|
|
14
|
-
directionSign: CarouselDirectionSign
|
|
15
|
-
): number {
|
|
16
|
-
"worklet";
|
|
17
|
-
|
|
18
|
-
return physicalValue * directionSign;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export function toPhysicalHorizontalValue(
|
|
22
|
-
logicalValue: number,
|
|
23
|
-
directionSign: CarouselDirectionSign
|
|
24
|
-
): number {
|
|
25
|
-
"worklet";
|
|
26
|
-
|
|
27
|
-
return logicalValue * directionSign;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export function getHorizontalStackOffsetType(
|
|
31
|
-
exitDirection: "left" | "right",
|
|
32
|
-
directionSign: CarouselDirectionSign
|
|
33
|
-
): "positive" | "negative" {
|
|
34
|
-
"worklet";
|
|
35
|
-
|
|
36
|
-
const ltrType = exitDirection === "right" ? "negative" : "positive";
|
|
37
|
-
if (directionSign === 1) return ltrType;
|
|
38
|
-
return ltrType === "positive" ? "negative" : "positive";
|
|
39
|
-
}
|