@r0b0t3d/react-native-carousel 3.4.0 → 3.4.4
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 +4 -1
- package/lib/commonjs/components/Carousel.js +9 -10
- package/lib/commonjs/components/Carousel.js.map +1 -1
- package/lib/commonjs/components/PageItem.js +19 -8
- package/lib/commonjs/components/PageItem.js.map +1 -1
- package/lib/commonjs/components/PaginationIndicator.js +66 -48
- package/lib/commonjs/components/PaginationIndicator.js.map +1 -1
- package/lib/module/components/Carousel.js +10 -11
- package/lib/module/components/Carousel.js.map +1 -1
- package/lib/module/components/PageItem.js +20 -9
- package/lib/module/components/PageItem.js.map +1 -1
- package/lib/module/components/PaginationIndicator.js +68 -46
- package/lib/module/components/PaginationIndicator.js.map +1 -1
- package/package.json +1 -1
- package/src/components/Carousel.tsx +10 -9
- package/src/components/PageItem.tsx +28 -17
- package/src/components/PaginationIndicator.tsx +86 -62
- package/lib/.DS_Store +0 -0
- package/src/.DS_Store +0 -0
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/ban-ts-comment */
|
|
2
|
-
import React, {
|
|
3
|
-
import { View, StyleSheet, ViewStyle } from 'react-native';
|
|
2
|
+
import React, { useMemo } from 'react';
|
|
3
|
+
import { View, StyleSheet, ViewStyle, StyleProp } from 'react-native';
|
|
4
4
|
import Animated, {
|
|
5
5
|
useAnimatedStyle,
|
|
6
6
|
useDerivedValue,
|
|
7
|
-
useSharedValue,
|
|
8
7
|
withSpring,
|
|
9
8
|
} from 'react-native-reanimated';
|
|
10
9
|
import type { IndicatorConfigs, PaginationProps } from '../types';
|
|
@@ -18,20 +17,6 @@ const defaultIndicatorConfigs: IndicatorConfigs = {
|
|
|
18
17
|
spaceBetween: 3,
|
|
19
18
|
};
|
|
20
19
|
|
|
21
|
-
const styles = StyleSheet.create({
|
|
22
|
-
container: {
|
|
23
|
-
flexDirection: 'row',
|
|
24
|
-
alignItems: 'center',
|
|
25
|
-
},
|
|
26
|
-
dotContainer: {
|
|
27
|
-
alignItems: 'center',
|
|
28
|
-
justifyContent: 'center',
|
|
29
|
-
},
|
|
30
|
-
dotSelectedStyle: {
|
|
31
|
-
position: 'absolute',
|
|
32
|
-
},
|
|
33
|
-
});
|
|
34
|
-
|
|
35
20
|
const defaultSpringConfig = {
|
|
36
21
|
stiffness: 1000,
|
|
37
22
|
damping: 500,
|
|
@@ -42,15 +27,12 @@ const defaultSpringConfig = {
|
|
|
42
27
|
};
|
|
43
28
|
|
|
44
29
|
export default function PaginationIndicator({
|
|
45
|
-
// totalPage,
|
|
46
30
|
containerStyle,
|
|
47
31
|
indicatorStyle,
|
|
48
32
|
activeIndicatorStyle,
|
|
49
33
|
indicatorConfigs,
|
|
50
34
|
}: PaginationProps) {
|
|
51
|
-
const
|
|
52
|
-
const page = useSharedValue(0);
|
|
53
|
-
const currentPage = carouselContext.currentPage || page;
|
|
35
|
+
const { currentPage, totalPage } = useCarouselContext();
|
|
54
36
|
|
|
55
37
|
const configs = useMemo(() => {
|
|
56
38
|
return {
|
|
@@ -76,7 +58,7 @@ export default function PaginationIndicator({
|
|
|
76
58
|
};
|
|
77
59
|
}, []);
|
|
78
60
|
|
|
79
|
-
|
|
61
|
+
function renderItem(pageNumber: number) {
|
|
80
62
|
// @ts-ignore
|
|
81
63
|
if (activeIndicatorStyle?.width) {
|
|
82
64
|
console.error(
|
|
@@ -89,52 +71,21 @@ export default function PaginationIndicator({
|
|
|
89
71
|
'Do not use indicatorStyle: { width }. Please use indicatorConfigs: { indicatorWidth } instead'
|
|
90
72
|
);
|
|
91
73
|
}
|
|
92
|
-
const dotContainerStyle: ViewStyle = StyleSheet.flatten([
|
|
93
|
-
styles.dotContainer,
|
|
94
|
-
{
|
|
95
|
-
width: configs.indicatorSelectedWidth,
|
|
96
|
-
height: configs.indicatorWidth,
|
|
97
|
-
marginEnd: configs.spaceBetween,
|
|
98
|
-
},
|
|
99
|
-
activeIndicatorStyle,
|
|
100
|
-
{
|
|
101
|
-
// Disable backgroundColor in activeIndicatorStyle
|
|
102
|
-
backgroundColor: undefined,
|
|
103
|
-
},
|
|
104
|
-
]);
|
|
105
|
-
const dotStyle: ViewStyle = StyleSheet.flatten([
|
|
106
|
-
{
|
|
107
|
-
width: configs.indicatorWidth,
|
|
108
|
-
height: configs.indicatorWidth,
|
|
109
|
-
borderRadius: configs.indicatorWidth! / 2,
|
|
110
|
-
backgroundColor: configs.indicatorColor,
|
|
111
|
-
},
|
|
112
|
-
indicatorStyle,
|
|
113
|
-
]);
|
|
114
|
-
|
|
115
|
-
const aStyle = useAnimatedStyle(() => {
|
|
116
|
-
return {
|
|
117
|
-
width: withSpring(
|
|
118
|
-
currentPage.value === pageNumber
|
|
119
|
-
? configs.indicatorSelectedWidth!
|
|
120
|
-
: configs.indicatorWidth!,
|
|
121
|
-
defaultSpringConfig
|
|
122
|
-
),
|
|
123
|
-
};
|
|
124
|
-
}, []);
|
|
125
74
|
return (
|
|
126
|
-
<
|
|
75
|
+
<IndicatorItem
|
|
127
76
|
key={`index${pageNumber}`}
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
77
|
+
currentPage={currentPage}
|
|
78
|
+
pageNumber={pageNumber}
|
|
79
|
+
configs={configs}
|
|
80
|
+
indicatorStyle={indicatorStyle}
|
|
81
|
+
activeIndicatorStyle={activeIndicatorStyle}
|
|
82
|
+
/>
|
|
132
83
|
);
|
|
133
|
-
}
|
|
84
|
+
}
|
|
134
85
|
|
|
135
86
|
return (
|
|
136
87
|
<View style={[styles.container, containerStyle]}>
|
|
137
|
-
{[...Array(
|
|
88
|
+
{[...Array(totalPage.value).keys()].map(renderItem)}
|
|
138
89
|
<Animated.View
|
|
139
90
|
style={[
|
|
140
91
|
styles.dotSelectedStyle,
|
|
@@ -151,3 +102,76 @@ export default function PaginationIndicator({
|
|
|
151
102
|
</View>
|
|
152
103
|
);
|
|
153
104
|
}
|
|
105
|
+
|
|
106
|
+
function IndicatorItem({
|
|
107
|
+
currentPage,
|
|
108
|
+
pageNumber,
|
|
109
|
+
configs,
|
|
110
|
+
activeIndicatorStyle,
|
|
111
|
+
indicatorStyle,
|
|
112
|
+
}: {
|
|
113
|
+
currentPage: Animated.SharedValue<number>;
|
|
114
|
+
pageNumber: number;
|
|
115
|
+
configs: IndicatorConfigs;
|
|
116
|
+
activeIndicatorStyle?: StyleProp<ViewStyle>;
|
|
117
|
+
indicatorStyle?: StyleProp<ViewStyle>;
|
|
118
|
+
}) {
|
|
119
|
+
const dotContainerStyle: StyleProp<ViewStyle> = useMemo(()=> [
|
|
120
|
+
styles.dotContainer,
|
|
121
|
+
{
|
|
122
|
+
width: configs.indicatorSelectedWidth,
|
|
123
|
+
height: configs.indicatorWidth,
|
|
124
|
+
marginEnd: configs.spaceBetween,
|
|
125
|
+
},
|
|
126
|
+
activeIndicatorStyle,
|
|
127
|
+
{
|
|
128
|
+
// Disable backgroundColor in activeIndicatorStyle
|
|
129
|
+
backgroundColor: undefined,
|
|
130
|
+
},
|
|
131
|
+
], [activeIndicatorStyle]);
|
|
132
|
+
|
|
133
|
+
const dotStyle: StyleProp<ViewStyle> = useMemo(() => [
|
|
134
|
+
{
|
|
135
|
+
width: configs.indicatorWidth,
|
|
136
|
+
height: configs.indicatorWidth,
|
|
137
|
+
borderRadius: configs.indicatorWidth! / 2,
|
|
138
|
+
backgroundColor: configs.indicatorColor,
|
|
139
|
+
},
|
|
140
|
+
indicatorStyle,
|
|
141
|
+
], [indicatorStyle]);
|
|
142
|
+
|
|
143
|
+
const animatedWidth = useDerivedValue(() => {
|
|
144
|
+
return withSpring(
|
|
145
|
+
currentPage.value === pageNumber
|
|
146
|
+
? configs.indicatorSelectedWidth!
|
|
147
|
+
: configs.indicatorWidth!,
|
|
148
|
+
defaultSpringConfig
|
|
149
|
+
);
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
const aStyle = useAnimatedStyle(() => {
|
|
153
|
+
return {
|
|
154
|
+
width: animatedWidth.value,
|
|
155
|
+
};
|
|
156
|
+
}, []);
|
|
157
|
+
|
|
158
|
+
return (
|
|
159
|
+
<Animated.View style={[dotContainerStyle, aStyle]}>
|
|
160
|
+
<View style={dotStyle} />
|
|
161
|
+
</Animated.View>
|
|
162
|
+
);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
const styles = StyleSheet.create({
|
|
166
|
+
container: {
|
|
167
|
+
flexDirection: 'row',
|
|
168
|
+
alignItems: 'center',
|
|
169
|
+
},
|
|
170
|
+
dotContainer: {
|
|
171
|
+
alignItems: 'center',
|
|
172
|
+
justifyContent: 'center',
|
|
173
|
+
},
|
|
174
|
+
dotSelectedStyle: {
|
|
175
|
+
position: 'absolute',
|
|
176
|
+
},
|
|
177
|
+
});
|
package/lib/.DS_Store
DELETED
|
Binary file
|
package/src/.DS_Store
DELETED
|
Binary file
|