Skip to content

Commit 32c8c36

Browse files
committed
chore: add changeset
1 parent c956690 commit 32c8c36

File tree

4 files changed

+87
-65
lines changed

4 files changed

+87
-65
lines changed

.changeset/lazy-tips-wave.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"react-native-reanimated-carousel": patch
3+
---
4+
5+
Add <Pagination.Custom/> dot animation.

.eslintrc.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ module.exports = {
66
"quotes": "off",
77
"@typescript-eslint/quotes": "error",
88
"operator-linebreak": "off",
9+
"@typescript-eslint/indent": "off",
910
},
10-
plugins: ["jest"],
11+
plugins: ["jest", "prettier"],
1112
};

src/components/Pagination/Custom/PaginationItem.tsx

Lines changed: 77 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,44 @@
11
import type { PropsWithChildren } from "react";
22
import React from "react";
33
import type { ViewStyle } from "react-native";
4+
import type { SharedValue } from "react-native-reanimated";
45
import Animated, {
56
Extrapolation,
67
interpolate,
78
interpolateColor,
8-
SharedValue,
99
useAnimatedStyle,
1010
runOnJS,
1111
useSharedValue,
1212
useDerivedValue,
1313
} from "react-native-reanimated";
14+
1415
import type { DefaultStyle } from "react-native-reanimated/lib/typescript/hook/commonTypes";
1516

16-
export type DotStyle = Omit<ViewStyle, "width" | "height"> & {
17-
width?: number
18-
height?: number
17+
export type DotStyle = Omit<
18+
ViewStyle,
19+
"width" | "height" | "backgroundColor" | "borderRadius"
20+
> & {
21+
width?: number;
22+
height?: number;
23+
backgroundColor?: string;
24+
borderRadius?: number;
1925
};
2026

2127
export const PaginationItem: React.FC<
22-
PropsWithChildren<{
23-
index: number
24-
count: number
25-
size?: number
26-
animValue: SharedValue<number>
27-
horizontal?: boolean
28-
dotStyle?: DotStyle
29-
activeDotStyle?: DotStyle
30-
customReanimatedStyle?: (
31-
progress: number,
32-
index: number,
33-
length: number,
34-
) => DefaultStyle
35-
}>
28+
PropsWithChildren<{
29+
index: number;
30+
count: number;
31+
size?: number;
32+
animValue: SharedValue<number>;
33+
horizontal?: boolean;
34+
dotStyle?: DotStyle;
35+
activeDotStyle?: DotStyle;
36+
customReanimatedStyle?: (
37+
progress: number,
38+
index: number,
39+
length: number,
40+
) => DefaultStyle;
41+
}>
3642
> = (props) => {
3743
const defaultDotSize = 10;
3844
const {
@@ -48,8 +54,9 @@ PropsWithChildren<{
4854
} = props;
4955
const customReanimatedStyleRef = useSharedValue<DefaultStyle>({});
5056
const handleCustomAnimation = (progress: number) => {
51-
customReanimatedStyleRef.value = customReanimatedStyle?.(progress, index, count) ?? {};
52-
}
57+
customReanimatedStyleRef.value =
58+
customReanimatedStyle?.(progress, index, count) ?? {};
59+
};
5360

5461
useDerivedValue(() => {
5562
runOnJS(handleCustomAnimation)(animValue?.value);
@@ -71,58 +78,66 @@ PropsWithChildren<{
7178
...restActiveDotStyle
7279
} = activeDotStyle ?? {};
7380
let val = Math.abs(animValue?.value - index);
74-
if (index === 0 && animValue?.value > count - 1) {
81+
if (index === 0 && animValue?.value > count - 1)
7582
val = Math.abs(animValue?.value - count);
76-
}
83+
7784
const inputRange = [0, 1, 2];
7885
const restStyle = (val === 0 ? restActiveDotStyle : restDotStyle) ?? {};
7986

8087
return {
81-
width: interpolate(
82-
val,
83-
inputRange,
84-
[activeWidth, width, width],
85-
Extrapolation.CLAMP,
86-
),
87-
height: interpolate(
88-
val,
89-
inputRange,
90-
[activeHeight, height, height],
91-
Extrapolation.CLAMP,
92-
),
93-
borderRadius: interpolate(
94-
val,
95-
inputRange,
96-
[activeBorderRadius, borderRadius, borderRadius],
97-
Extrapolation.CLAMP,
98-
),
99-
backgroundColor: interpolateColor(
100-
val,
101-
inputRange,
102-
[activeBackgroundColor, backgroundColor, backgroundColor],
103-
),
104-
...restStyle,
105-
...(customReanimatedStyleRef.value ?? {}),
106-
transform: [
107-
...restStyle?.transform ?? [],
108-
...customReanimatedStyleRef.value?.transform ?? [],
109-
]
88+
width: interpolate(
89+
val,
90+
inputRange,
91+
[activeWidth, width, width],
92+
Extrapolation.CLAMP,
93+
),
94+
height: interpolate(
95+
val,
96+
inputRange,
97+
[activeHeight, height, height],
98+
Extrapolation.CLAMP,
99+
),
100+
borderRadius: interpolate(
101+
val,
102+
inputRange,
103+
[activeBorderRadius ?? borderRadius ?? 0, borderRadius ?? 0, borderRadius ?? 0],
104+
Extrapolation.CLAMP,
105+
),
106+
backgroundColor: interpolateColor(val, inputRange, [
107+
activeBackgroundColor,
108+
backgroundColor,
109+
backgroundColor,
110+
]),
111+
...restStyle,
112+
...(customReanimatedStyleRef.value ?? {}),
113+
transform: [
114+
...(restStyle?.transform ?? []),
115+
...(customReanimatedStyleRef.value?.transform ?? []),
116+
],
110117
};
111-
}, [animValue, index, count, horizontal, dotStyle, activeDotStyle, customReanimatedStyle]);
118+
}, [
119+
animValue,
120+
index,
121+
count,
122+
horizontal,
123+
dotStyle,
124+
activeDotStyle,
125+
customReanimatedStyle,
126+
]);
112127

113128
return (
114129
<Animated.View
115130
style={[
116-
{
117-
overflow: "hidden",
118-
transform: [
119-
{
120-
rotateZ: horizontal ? "90deg" : "0deg",
121-
},
122-
],
123-
},
124-
dotStyle,
125-
animStyle,
131+
{
132+
overflow: "hidden",
133+
transform: [
134+
{
135+
rotateZ: horizontal ? "90deg" : "0deg",
136+
},
137+
],
138+
},
139+
dotStyle,
140+
animStyle,
126141
]}
127142
>
128143
{children}

src/components/Pagination/Custom/index.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import type { StyleProp, ViewStyle } from "react-native";
33
import { View } from "react-native";
44
import { TouchableWithoutFeedback } from "react-native-gesture-handler";
55
import type { SharedValue } from "react-native-reanimated";
6+
67
import type { DefaultStyle } from "react-native-reanimated/lib/typescript/hook/commonTypes";
78

89
import type { DotStyle } from "./PaginationItem";
@@ -44,10 +45,10 @@ export const Custom = <T extends {}>(props: ShapeProps<T>) => {
4445
typeof dotStyle?.width === "string" ||
4546
typeof dotStyle?.height === "string" ||
4647
typeof activeDotStyle?.width === "string" ||
47-
typeof activeDotStyle?.height === "string"
48+
typeof activeDotStyle?.height === "string"
4849
)
4950
throw new Error("size/width/height must be a number");
50-
51+
5152
const maxItemWidth = Math.max(size ?? 0, dotStyle?.width ?? 0, activeDotStyle?.width ?? 0);
5253
const maxItemHeight = Math.max(size ?? 0, dotStyle?.height ?? 0, activeDotStyle?.height ?? 0);
5354

0 commit comments

Comments
 (0)