Skip to content

Commit ef211e5

Browse files
authored
Merge pull request #114 from dohooo/release/2.2.2
Release/2.2.2
2 parents 207f913 + d0f5626 commit ef211e5

File tree

6 files changed

+39
-22
lines changed

6 files changed

+39
-22
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
## [2.2.2](https://github.com/dohooo/react-native-reanimated-carousel/compare/v2.2.1...v2.2.2) (2022-01-23)
2+
3+
4+
### Bug Fixes
5+
6+
* onProgressChange & onSnapToItem bug when only 2 image ([bdb2d74](https://github.com/dohooo/react-native-reanimated-carousel/commit/bdb2d74245dfdefe024ba11b462dbe29bd7e18d6)), closes [#74](https://github.com/dohooo/react-native-reanimated-carousel/issues/74)
7+
* when autoPlay is false, manual sliding will still autoPlay ([6aa3cc4](https://github.com/dohooo/react-native-reanimated-carousel/commit/6aa3cc4a557efaa9e3262202f4a98ff960255b54)), closes [#111](https://github.com/dohooo/react-native-reanimated-carousel/issues/111)
8+
19
## [2.2.1](https://github.com/dohooo/react-native-reanimated-carousel/compare/v2.1.2...v2.2.1) (2022-01-16)
210

311

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-native-reanimated-carousel",
3-
"version": "2.2.1",
3+
"version": "2.2.2",
44
"description": "Simple carousel component.fully implemented using Reanimated 2.Infinitely scrolling, very smooth.",
55
"main": "lib/commonjs/index",
66
"module": "lib/module/index",
@@ -35,7 +35,7 @@
3535
"android": "yarn --cwd example android",
3636
"android:pretty": "yarn --cwd example android:pretty",
3737
"pods": "cd example && pod-install --quiet",
38-
"bootstrap": "yarn example && yarn && yarn pods",
38+
"bootstrap": "yarn && yarn pods",
3939
"deploy": "cd example && yarn deploy"
4040
},
4141
"keywords": [

src/Carousel.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ function Carousel<T>(
2525

2626
const {
2727
data,
28+
rawData,
2829
loop,
2930
mode,
3031
style,
@@ -58,7 +59,7 @@ function Carousel<T>(
5859
}, [loop, size, data]);
5960

6061
usePropsErrorBoundary(props);
61-
useOnProgressChange({ size, offsetX, data, onProgressChange });
62+
useOnProgressChange({ size, offsetX, rawData, onProgressChange });
6263

6364
const carouselController = useCarouselController({
6465
loop,
@@ -135,11 +136,11 @@ function Carousel<T>(
135136
const renderLayout = React.useCallback(
136137
(item: T, i: number) => {
137138
let realIndex = i;
138-
if (data.length === DATA_LENGTH.SINGLE_ITEM) {
139+
if (rawData.length === DATA_LENGTH.SINGLE_ITEM) {
139140
realIndex = i % 1;
140141
}
141142

142-
if (data.length === DATA_LENGTH.DOUBLE_ITEM) {
143+
if (rawData.length === DATA_LENGTH.DOUBLE_ITEM) {
143144
realIndex = i % 2;
144145
}
145146

@@ -162,7 +163,7 @@ function Carousel<T>(
162163
);
163164
},
164165
[
165-
data,
166+
rawData,
166167
offsetX,
167168
visibleRanges,
168169
renderItem,

src/hooks/useAutoPlay.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,12 @@ export function useAutoPlay(opts: {
3535
}, []);
3636

3737
const start = React.useCallback(() => {
38+
if (!autoPlay) {
39+
return;
40+
}
3841
stopped.current = false;
3942
play();
40-
}, [play]);
43+
}, [play, autoPlay]);
4144

4245
React.useEffect(() => {
4346
if (autoPlay) {

src/hooks/useInitProps.ts

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,17 @@ export type TInitializeCarouselProps<T> = TCarouselProps<T> &
1515
| 'height'
1616
| 'scrollAnimationDuration'
1717
| 'autoPlayInterval'
18-
>;
18+
> & {
19+
// Raw data that has not been processed
20+
rawData: T[];
21+
};
1922

2023
export function useInitProps<T>(
2124
props: TCarouselProps<T>
2225
): TInitializeCarouselProps<T> {
2326
const {
2427
defaultIndex = 0,
25-
data: _data = [],
28+
data: rawData = [],
2629
loop = true,
2730
autoPlayInterval: _autoPlayInterval = 1000,
2831
scrollAnimationDuration = 500,
@@ -39,18 +42,18 @@ export function useInitProps<T>(
3942
const autoPlayInterval = Math.max(_autoPlayInterval, 0);
4043

4144
const data = React.useMemo<T[]>(() => {
42-
if (!loop) return _data;
45+
if (!loop) return rawData;
4346

44-
if (_data.length === DATA_LENGTH.SINGLE_ITEM) {
45-
return [_data[0], _data[0], _data[0]];
47+
if (rawData.length === DATA_LENGTH.SINGLE_ITEM) {
48+
return [rawData[0], rawData[0], rawData[0]];
4649
}
4750

48-
if (_data.length === DATA_LENGTH.DOUBLE_ITEM) {
49-
return [_data[0], _data[1], _data[0], _data[1]];
51+
if (rawData.length === DATA_LENGTH.DOUBLE_ITEM) {
52+
return [rawData[0], rawData[1], rawData[0], rawData[1]];
5053
}
5154

52-
return _data;
53-
}, [_data, loop]);
55+
return rawData;
56+
}, [rawData, loop]);
5457

5558
if (props.mode === 'vertical-stack' || props.mode === 'horizontal-stack') {
5659
if (!props.modeConfig) {
@@ -63,6 +66,7 @@ export function useInitProps<T>(
6366
...props,
6467
defaultIndex,
6568
data,
69+
rawData,
6670
loop,
6771
autoPlayInterval,
6872
scrollAnimationDuration,

src/hooks/useOnProgressChange.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,31 +9,32 @@ export function useOnProgressChange(
99
opts: {
1010
size: number;
1111
offsetX: Animated.SharedValue<number>;
12-
} & Pick<TCarouselProps, 'data' | 'onProgressChange'>
12+
rawData: TCarouselProps['data'];
13+
} & Pick<TCarouselProps, 'onProgressChange'>
1314
) {
14-
const { offsetX, data, size, onProgressChange } = opts;
15+
const { offsetX, rawData, size, onProgressChange } = opts;
1516
useAnimatedReaction(
1617
() => offsetX.value,
1718
(_value) => {
1819
let value = _value;
1920

20-
if (data.length === DATA_LENGTH.SINGLE_ITEM) {
21+
if (rawData.length === DATA_LENGTH.SINGLE_ITEM) {
2122
value = value % size;
2223
}
2324

24-
if (data.length === DATA_LENGTH.DOUBLE_ITEM) {
25+
if (rawData.length === DATA_LENGTH.DOUBLE_ITEM) {
2526
value = value % (size * 2);
2627
}
2728

2829
let absoluteProgress = Math.abs(value / size);
2930

3031
if (value > 0) {
31-
absoluteProgress = data.length - absoluteProgress;
32+
absoluteProgress = rawData.length - absoluteProgress;
3233
}
3334

3435
!!onProgressChange &&
3536
runOnJS(onProgressChange)(value, absoluteProgress);
3637
},
37-
[onProgressChange, data]
38+
[onProgressChange, rawData]
3839
);
3940
}

0 commit comments

Comments
 (0)