react-native-reanimated-carousel 2.1.0 → 2.2.2
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 +25 -4
- package/README.zh-CN.md +26 -3
- package/lib/commonjs/Carousel.js +14 -10
- package/lib/commonjs/Carousel.js.map +1 -1
- package/lib/commonjs/ScrollViewGesture.js +13 -5
- package/lib/commonjs/ScrollViewGesture.js.map +1 -1
- package/lib/commonjs/constants/index.js +9 -1
- package/lib/commonjs/constants/index.js.map +1 -1
- package/lib/commonjs/hooks/useAutoPlay.js +23 -13
- package/lib/commonjs/hooks/useAutoPlay.js.map +1 -1
- package/lib/commonjs/hooks/useCarouselController.js +94 -30
- package/lib/commonjs/hooks/useCarouselController.js.map +1 -1
- package/lib/commonjs/hooks/useInitProps.js +13 -9
- package/lib/commonjs/hooks/useInitProps.js.map +1 -1
- package/lib/commonjs/hooks/useOnProgressChange.js +5 -5
- package/lib/commonjs/hooks/useOnProgressChange.js.map +1 -1
- package/lib/commonjs/layouts/normal.js +1 -1
- package/lib/commonjs/layouts/normal.js.map +1 -1
- package/lib/module/Carousel.js +14 -10
- package/lib/module/Carousel.js.map +1 -1
- package/lib/module/ScrollViewGesture.js +13 -6
- package/lib/module/ScrollViewGesture.js.map +1 -1
- package/lib/module/constants/index.js +5 -0
- package/lib/module/constants/index.js.map +1 -1
- package/lib/module/hooks/useAutoPlay.js +23 -13
- package/lib/module/hooks/useAutoPlay.js.map +1 -1
- package/lib/module/hooks/useCarouselController.js +91 -30
- package/lib/module/hooks/useCarouselController.js.map +1 -1
- package/lib/module/hooks/useInitProps.js +13 -9
- package/lib/module/hooks/useInitProps.js.map +1 -1
- package/lib/module/hooks/useOnProgressChange.js +5 -5
- package/lib/module/hooks/useOnProgressChange.js.map +1 -1
- package/lib/module/layouts/normal.js +2 -2
- package/lib/module/layouts/normal.js.map +1 -1
- package/lib/typescript/constants/index.d.ts +3 -0
- package/lib/typescript/hooks/useAutoPlay.d.ts +1 -1
- package/lib/typescript/hooks/useCarouselController.d.ts +8 -5
- package/lib/typescript/hooks/useInitProps.d.ts +4 -5
- package/lib/typescript/hooks/useOnProgressChange.d.ts +2 -1
- package/lib/typescript/types.d.ts +22 -4
- package/package.json +6 -3
- package/src/Carousel.tsx +15 -9
- package/src/ScrollViewGesture.tsx +12 -5
- package/src/constants/index.ts +6 -0
- package/src/hooks/useAutoPlay.ts +21 -21
- package/src/hooks/useCarouselController.tsx +112 -50
- package/src/hooks/useInitProps.ts +30 -15
- package/src/hooks/useOnProgressChange.ts +7 -6
- package/src/layouts/normal.ts +2 -7
- package/src/types.ts +23 -4
- package/CHANGELOG.md +0 -346
- package/lib/commonjs/hooks/useIndexController.js +0 -65
- package/lib/commonjs/hooks/useIndexController.js.map +0 -1
- package/lib/module/hooks/useIndexController.js +0 -52
- package/lib/module/hooks/useIndexController.js.map +0 -1
- package/lib/typescript/hooks/useIndexController.d.ts +0 -18
- package/src/.DS_Store +0 -0
- package/src/hooks/useIndexController.ts +0 -78
|
@@ -9,31 +9,32 @@ export function useOnProgressChange(
|
|
|
9
9
|
opts: {
|
|
10
10
|
size: number;
|
|
11
11
|
offsetX: Animated.SharedValue<number>;
|
|
12
|
-
|
|
12
|
+
rawData: TCarouselProps['data'];
|
|
13
|
+
} & Pick<TCarouselProps, 'onProgressChange'>
|
|
13
14
|
) {
|
|
14
|
-
const { offsetX,
|
|
15
|
+
const { offsetX, rawData, size, onProgressChange } = opts;
|
|
15
16
|
useAnimatedReaction(
|
|
16
17
|
() => offsetX.value,
|
|
17
18
|
(_value) => {
|
|
18
19
|
let value = _value;
|
|
19
20
|
|
|
20
|
-
if (
|
|
21
|
+
if (rawData.length === DATA_LENGTH.SINGLE_ITEM) {
|
|
21
22
|
value = value % size;
|
|
22
23
|
}
|
|
23
24
|
|
|
24
|
-
if (
|
|
25
|
+
if (rawData.length === DATA_LENGTH.DOUBLE_ITEM) {
|
|
25
26
|
value = value % (size * 2);
|
|
26
27
|
}
|
|
27
28
|
|
|
28
29
|
let absoluteProgress = Math.abs(value / size);
|
|
29
30
|
|
|
30
31
|
if (value > 0) {
|
|
31
|
-
absoluteProgress =
|
|
32
|
+
absoluteProgress = rawData.length - absoluteProgress;
|
|
32
33
|
}
|
|
33
34
|
|
|
34
35
|
!!onProgressChange &&
|
|
35
36
|
runOnJS(onProgressChange)(value, absoluteProgress);
|
|
36
37
|
},
|
|
37
|
-
[onProgressChange,
|
|
38
|
+
[onProgressChange, rawData]
|
|
38
39
|
);
|
|
39
40
|
}
|
package/src/layouts/normal.ts
CHANGED
|
@@ -1,16 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { interpolate } from 'react-native-reanimated';
|
|
2
2
|
|
|
3
3
|
export function normalLayout(opts: { size: number; vertical: boolean }) {
|
|
4
4
|
const { size, vertical } = opts;
|
|
5
5
|
|
|
6
6
|
return (value: number) => {
|
|
7
7
|
'worklet';
|
|
8
|
-
const translate = interpolate(
|
|
9
|
-
value,
|
|
10
|
-
[-1, 0, 1],
|
|
11
|
-
[-size, 0, size],
|
|
12
|
-
Extrapolate.CLAMP
|
|
13
|
-
);
|
|
8
|
+
const translate = interpolate(value, [-1, 0, 1], [-size, 0, size]);
|
|
14
9
|
|
|
15
10
|
return {
|
|
16
11
|
transform: [
|
package/src/types.ts
CHANGED
|
@@ -71,6 +71,11 @@ export type TCarouselProps<T = any> = {
|
|
|
71
71
|
* @description playback interval
|
|
72
72
|
*/
|
|
73
73
|
autoPlayInterval?: number;
|
|
74
|
+
/**
|
|
75
|
+
* Time a scroll animation takes to finish
|
|
76
|
+
* @default 500 (ms)
|
|
77
|
+
*/
|
|
78
|
+
scrollAnimationDuration?: number;
|
|
74
79
|
/**
|
|
75
80
|
* Carousel container style
|
|
76
81
|
*/
|
|
@@ -138,21 +143,29 @@ export type TCarouselProps<T = any> = {
|
|
|
138
143
|
|
|
139
144
|
export interface ICarouselInstance {
|
|
140
145
|
/**
|
|
141
|
-
*
|
|
146
|
+
* Scroll to previous item, it takes one optional argument (count),
|
|
147
|
+
* which allows you to specify how many items to cross
|
|
142
148
|
*/
|
|
143
|
-
prev: () => void;
|
|
149
|
+
prev: (opts?: TCarouselActionOptions) => void;
|
|
144
150
|
/**
|
|
145
|
-
*
|
|
151
|
+
* Scroll to next item, it takes one optional argument (count),
|
|
152
|
+
* which allows you to specify how many items to cross
|
|
146
153
|
*/
|
|
147
|
-
next: () => void;
|
|
154
|
+
next: (opts?: TCarouselActionOptions) => void;
|
|
148
155
|
/**
|
|
149
156
|
* Get current item index
|
|
150
157
|
*/
|
|
151
158
|
getCurrentIndex: () => number;
|
|
152
159
|
/**
|
|
153
160
|
* Go to index
|
|
161
|
+
* @deprecated use scrollTo instead
|
|
154
162
|
*/
|
|
155
163
|
goToIndex: (index: number, animated?: boolean) => void;
|
|
164
|
+
/**
|
|
165
|
+
* Use value to scroll to a position where relative to the current position,
|
|
166
|
+
* scrollTo(-2) is equivalent to prev(2), scrollTo(2) is equivalent to next(2)
|
|
167
|
+
*/
|
|
168
|
+
scrollTo: (opts?: TCarouselActionOptions) => void;
|
|
156
169
|
}
|
|
157
170
|
|
|
158
171
|
export interface CarouselRenderItemInfo<ItemT> {
|
|
@@ -164,3 +177,9 @@ export interface CarouselRenderItemInfo<ItemT> {
|
|
|
164
177
|
export type CarouselRenderItem<ItemT> = (
|
|
165
178
|
info: CarouselRenderItemInfo<ItemT>
|
|
166
179
|
) => React.ReactElement;
|
|
180
|
+
|
|
181
|
+
export interface TCarouselActionOptions {
|
|
182
|
+
count?: number;
|
|
183
|
+
animated?: boolean;
|
|
184
|
+
onFinished?: () => void;
|
|
185
|
+
}
|
package/CHANGELOG.md
DELETED
|
@@ -1,346 +0,0 @@
|
|
|
1
|
-
# [2.1.0](https://github.com/dohooo/react-native-reanimated-carousel/compare/v2.0.0...v2.1.0) (2022-01-08)
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
### Features
|
|
5
|
-
|
|
6
|
-
* pass animation value to renderItem ([bf57233](https://github.com/dohooo/react-native-reanimated-carousel/commit/bf572335a19179aefd52d0bf43e61029ec2f945a)), closes [#89](https://github.com/dohooo/react-native-reanimated-carousel/issues/89)
|
|
7
|
-
* support to custom carousel animations by `customAnimation` `customConfig` props ([eb3082b](https://github.com/dohooo/react-native-reanimated-carousel/commit/eb3082b74d3f08f6205cce47a30435ffc8570145))
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
### BREAKING CHANGES
|
|
11
|
-
|
|
12
|
-
* Remove the parameter of `renderItem` and change it to `info` object
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
## [1.1.1](https://github.com/dohooo/react-native-reanimated-carousel/compare/v2.0.0...v2.1.0) (2022-01-04)
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
### Bug Fixes
|
|
20
|
-
|
|
21
|
-
* fix bug with windowSize props ([8a048df](https://github.com/dohooo/react-native-reanimated-carousel/commit/8a048dfafbf46ba6d4776f82564dea43af026144)), closes [#71](https://github.com/dohooo/react-native-reanimated-carousel/issues/71)
|
|
22
|
-
|
|
23
|
-
# [2.0.0](https://github.com/dohooo/react-native-reanimated-carousel/compare/v1.2.0-beta.4...v2.0.0) (2022-01-07)
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
### Bug Fixes
|
|
27
|
-
|
|
28
|
-
* fix bug from refactoring ([c77f4d8](https://github.com/dohooo/react-native-reanimated-carousel/commit/c77f4d8604e319528f2d15fd288734749615e077))
|
|
29
|
-
|
|
30
|
-
# [1.2.0-beta.4](https://github.com/dohooo/react-native-reanimated-carousel/compare/v1.2.0-beta.3...v1.2.0-beta.4) (2022-01-05)
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
### Bug Fixes
|
|
34
|
-
|
|
35
|
-
* solve a bug caused by Parallax/Normal layout reconstruction ([651bf5e](https://github.com/dohooo/react-native-reanimated-carousel/commit/651bf5ee0572f512dddc01205dbb74d651cfa0ce))
|
|
36
|
-
|
|
37
|
-
# [1.2.0-beta.3](https://github.com/dohooo/react-native-reanimated-carousel/compare/v1.1.0...v1.2.0-beta.3) (2022-01-05)
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
### Bug Fixes
|
|
41
|
-
|
|
42
|
-
* fix bug with windowSize props ([b9637ca](https://github.com/dohooo/react-native-reanimated-carousel/commit/b9637ca4f988851c6f0636e50c8079837eda42f6)), closes [#71](https://github.com/dohooo/react-native-reanimated-carousel/issues/71)
|
|
43
|
-
* onProgressChange/onSnapToItem props wrong calculation ([85de2f4](https://github.com/dohooo/react-native-reanimated-carousel/commit/85de2f41935e299ff7510e5b678e0f37fc29d13e)), closes [#74](https://github.com/dohooo/react-native-reanimated-carousel/issues/74)
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
### Features
|
|
47
|
-
|
|
48
|
-
* support to RTL ([c2c3bcf](https://github.com/dohooo/react-native-reanimated-carousel/commit/c2c3bcfd2fe475b9934962d62e97bc39bf8fdf2d)), closes [#69](https://github.com/dohooo/react-native-reanimated-carousel/issues/69)
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
# [1.1.0](https://github.com/dohooo/react-native-reanimated-carousel/compare/v1.1.0...v1.2.0-beta.3) (2022-01-03)
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
### Bug Fixes
|
|
56
|
-
|
|
57
|
-
* _ ([c8054f1](https://github.com/dohooo/react-native-reanimated-carousel/commit/c8054f17202e7ff33447cd70e83582f4914941ad))
|
|
58
|
-
* fix item blink when scroll active ([96c9b75](https://github.com/dohooo/react-native-reanimated-carousel/commit/96c9b751a7ee4cc0ba013801d098b05705c26bcf))
|
|
59
|
-
* fix with zindex ([f3b28cc](https://github.com/dohooo/react-native-reanimated-carousel/commit/f3b28cc8a83649a885307b82908e714bb2724ab4))
|
|
60
|
-
* item blink ([063f564](https://github.com/dohooo/react-native-reanimated-carousel/commit/063f5644779f37754608972507b10d0cfb87769a))
|
|
61
|
-
* item zIndex ([10e58a8](https://github.com/dohooo/react-native-reanimated-carousel/commit/10e58a876e8cb386a45d17ea8eb8bee79de0e94a))
|
|
62
|
-
* refactor stack layout ([dc975fe](https://github.com/dohooo/react-native-reanimated-carousel/commit/dc975fe8f25b03b59047fd21f596d626f806de2b))
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
### Features
|
|
66
|
-
|
|
67
|
-
* add stack layout ([5a70a23](https://github.com/dohooo/react-native-reanimated-carousel/commit/5a70a230307e0b258e16230d6b21be2c4d8c7497))
|
|
68
|
-
* multiple stack styles are supported ([d4497a7](https://github.com/dohooo/react-native-reanimated-carousel/commit/d4497a785f6da4dae79e812dac1d5515303d0cd3))
|
|
69
|
-
* support pagingEnabled enableSnap ([000658e](https://github.com/dohooo/react-native-reanimated-carousel/commit/000658ed4a97b58d4e2649b6ab816e62919beff9)), closes [#65](https://github.com/dohooo/react-native-reanimated-carousel/issues/65)
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
## [1.0.12](https://github.com/dohooo/react-native-reanimated-carousel/compare/v1.1.0...v1.2.0-beta.3) (2021-12-28)
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
### Bug Fixes
|
|
77
|
-
|
|
78
|
-
* scroll pass the last item ([34a5e57](https://github.com/dohooo/react-native-reanimated-carousel/commit/34a5e5796a35f62374761bf2144a86f69acc8e66)), closes [#63](https://github.com/dohooo/react-native-reanimated-carousel/issues/63)
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
## [1.0.11](https://github.com/dohooo/react-native-reanimated-carousel/compare/v1.1.0...v1.2.0-beta.3) (2021-12-20)
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
### Bug Fixes
|
|
86
|
-
|
|
87
|
-
* fixed useAnimatedReaction wrong import ([7b7a3fc](https://github.com/dohooo/react-native-reanimated-carousel/commit/7b7a3fc4f49b5f3bfff664b2c07306334ac2e509))
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
## [1.0.10](https://github.com/dohooo/react-native-reanimated-carousel/compare/v1.1.0...v1.2.0-beta.3) (2021-12-19)
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
### Bug Fixes
|
|
95
|
-
|
|
96
|
-
* fix ScrollViewGesture callback ([40412fc](https://github.com/dohooo/react-native-reanimated-carousel/commit/40412fcab6c1e6e013ccd8c409c2fb9bffcde926))
|
|
97
|
-
* fixed failure to set default values ([5d02779](https://github.com/dohooo/react-native-reanimated-carousel/commit/5d0277925a0daf00944e7900d86f3ee463f77719))
|
|
98
|
-
* fixed types ([9f3068b](https://github.com/dohooo/react-native-reanimated-carousel/commit/9f3068bbb9dadbdd046ad50cf4437b53f335e4a9))
|
|
99
|
-
* modify useCarouselController params ([c8f2c6a](https://github.com/dohooo/react-native-reanimated-carousel/commit/c8f2c6acb9b578fa38d365c669aaf2beb6694686))
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
### Features
|
|
103
|
-
|
|
104
|
-
* add babel-loader in example,support to web ([1edc9c3](https://github.com/dohooo/react-native-reanimated-carousel/commit/1edc9c34a7a02e35fa6c18927d8b543367bb1c30))
|
|
105
|
-
* add examples ([666ba86](https://github.com/dohooo/react-native-reanimated-carousel/commit/666ba86729105bb825f95a9dbdc4290efbd3dffa))
|
|
106
|
-
* add navigation in example ([1687f1d](https://github.com/dohooo/react-native-reanimated-carousel/commit/1687f1db4c98e583f29326dc1b2a273adb19af4e))
|
|
107
|
-
* add ScrollViewGesture ([a903f12](https://github.com/dohooo/react-native-reanimated-carousel/commit/a903f12d73a18c2774318154544dda17c755f6ff))
|
|
108
|
-
* lazy loading ([ed75232](https://github.com/dohooo/react-native-reanimated-carousel/commit/ed75232eb25a475f994f327e94f9dd717b9cf251))
|
|
109
|
-
* springConfig props has be deprecated ([763c073](https://github.com/dohooo/react-native-reanimated-carousel/commit/763c07398f196391ebf478ebd9c45acd7c6890a3))
|
|
110
|
-
* vertical mode ([7645b75](https://github.com/dohooo/react-native-reanimated-carousel/commit/7645b753f9379cb86bba27764a99cd163a744570)), closes [#41](https://github.com/dohooo/react-native-reanimated-carousel/issues/41)
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
### Performance Improvements
|
|
114
|
-
|
|
115
|
-
* add example ([1684038](https://github.com/dohooo/react-native-reanimated-carousel/commit/16840383712eda31b1a8481fa5498ed9b92504cd))
|
|
116
|
-
* add example ([8527ffb](https://github.com/dohooo/react-native-reanimated-carousel/commit/8527ffbd2b374f880a42d445a24c385c18885859))
|
|
117
|
-
* lazy loading ([39ba773](https://github.com/dohooo/react-native-reanimated-carousel/commit/39ba7735946326c10dd5ec8b6ffe6a8fcf9a8006))
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
## [1.0.9](https://github.com/dohooo/react-native-reanimated-carousel/compare/v1.1.0...v1.2.0-beta.3) (2021-12-07)
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
### Performance Improvements
|
|
125
|
-
|
|
126
|
-
* add props 'windowSize' ([4e066ee](https://github.com/dohooo/react-native-reanimated-carousel/commit/4e066eed5a3d3eb9cc4a9d1173831a44385bac65)), closes [#46](https://github.com/dohooo/react-native-reanimated-carousel/issues/46)
|
|
127
|
-
* reduce the calculation of animation values ([de32274](https://github.com/dohooo/react-native-reanimated-carousel/commit/de322745d900251614e25005fe39dd32fab4e9a7)), closes [#46](https://github.com/dohooo/react-native-reanimated-carousel/issues/46)
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
## [1.0.8](https://github.com/dohooo/react-native-reanimated-carousel/compare/v1.1.0...v1.2.0-beta.3) (2021-12-06)
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
### Bug Fixes
|
|
135
|
-
|
|
136
|
-
* fix items position ([6d36555](https://github.com/dohooo/react-native-reanimated-carousel/commit/6d365550b677513c3b56ed3a401dbf021a0d2856)), closes [#51](https://github.com/dohooo/react-native-reanimated-carousel/issues/51)
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
## [1.0.7](https://github.com/dohooo/react-native-reanimated-carousel/compare/v1.1.0...v1.2.0-beta.3) (2021-12-05)
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
### Bug Fixes
|
|
144
|
-
|
|
145
|
-
* a quick call to the page number switch method causes an offset error ([0c93b86](https://github.com/dohooo/react-native-reanimated-carousel/commit/0c93b867f4e17583b08683404a36590fc267c03c)), closes [#30](https://github.com/dohooo/react-native-reanimated-carousel/issues/30)
|
|
146
|
-
* defaultIndex does not work as expected ([42e4616](https://github.com/dohooo/react-native-reanimated-carousel/commit/42e46166144ceac6b15c6ad4e7d18923a722f91b)), closes [#33](https://github.com/dohooo/react-native-reanimated-carousel/issues/33)
|
|
147
|
-
* fix computed error with MAX/MIN ([e9a3007](https://github.com/dohooo/react-native-reanimated-carousel/commit/e9a30070dbae04a889015be05aff398079f35e84))
|
|
148
|
-
* image flickers within Carousel when state is updated ([094f3af](https://github.com/dohooo/react-native-reanimated-carousel/commit/094f3af65b517f59d2982d3dcfc64dab1404fcc5)), closes [#32](https://github.com/dohooo/react-native-reanimated-carousel/issues/32)
|
|
149
|
-
* modify useOffsetX viewCount default value ([dd30b9c](https://github.com/dohooo/react-native-reanimated-carousel/commit/dd30b9c0ec52917eeb1d0a144e46318a1bae7da8))
|
|
150
|
-
* sliding error with no loop ([955b5ed](https://github.com/dohooo/react-native-reanimated-carousel/commit/955b5ede0d975231feab55258823a9538752c0e2)), closes [#24](https://github.com/dohooo/react-native-reanimated-carousel/issues/24)
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
## [1.0.4](https://github.com/dohooo/react-native-reanimated-carousel/compare/v1.1.0...v1.2.0-beta.3) (2021-11-18)
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
### Bug Fixes
|
|
158
|
-
|
|
159
|
-
* **hooks/usepropserrorboundary.ts:** always be error when data props set null ([2450fe1](https://github.com/dohooo/react-native-reanimated-carousel/commit/2450fe120b22ec561a3bc7c4b687ccfee0bfc080)), closes [#34](https://github.com/dohooo/react-native-reanimated-carousel/issues/34)
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
## [1.0.3](https://github.com/dohooo/react-native-reanimated-carousel/compare/v1.1.0...v1.2.0-beta.3) (2021-11-10)
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
### Features
|
|
167
|
-
|
|
168
|
-
* add defaultIndex props ([e9191f9](https://github.com/dohooo/react-native-reanimated-carousel/commit/e9191f96dab5885ca14bc873b5feeb6fa80ac82a)), closes [#31](https://github.com/dohooo/react-native-reanimated-carousel/issues/31)
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
## [1.0.2](https://github.com/dohooo/react-native-reanimated-carousel/compare/v1.1.0...v1.2.0-beta.3) (2021-11-03)
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
### Features
|
|
176
|
-
|
|
177
|
-
* add onProgressChange props ([a3894ff](https://github.com/dohooo/react-native-reanimated-carousel/commit/a3894ffb64d2541e61683d06c53487dc54af1a47))
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
## [1.0.1](https://github.com/dohooo/react-native-reanimated-carousel/compare/v1.1.0...v1.2.0-beta.3) (2021-11-01)
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
### Bug Fixes
|
|
185
|
-
|
|
186
|
-
* fix bug with reanimated ([6744f74](https://github.com/dohooo/react-native-reanimated-carousel/commit/6744f747424d6ad51e61bca0702eec8e60d00441))
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
# [1.0.0](https://github.com/dohooo/react-native-reanimated-carousel/compare/v1.1.0...v1.2.0-beta.3) (2021-10-31)
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
### Bug Fixes
|
|
194
|
-
|
|
195
|
-
* fix default timeConfig ([0f99500](https://github.com/dohooo/react-native-reanimated-carousel/commit/0f9950005604fa19ff73449a58b3944bd4f1fee2))
|
|
196
|
-
* solve sliding flicker problem ([96678e0](https://github.com/dohooo/react-native-reanimated-carousel/commit/96678e0d3c03ea6f6bc9a40534c1bb732475e102))
|
|
197
|
-
* solve sliding flicker problem ([e26c384](https://github.com/dohooo/react-native-reanimated-carousel/commit/e26c384f25b203a420f7bed2c356586cb1466f65))
|
|
198
|
-
* upgrade expo sdk 40 to 41. fix example error ([11b39b1](https://github.com/dohooo/react-native-reanimated-carousel/commit/11b39b16f682551ad1b2b67e497ea0709d7b7766))
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
### Features
|
|
202
|
-
|
|
203
|
-
* improve sliding experience ([14b62ee](https://github.com/dohooo/react-native-reanimated-carousel/commit/14b62ee3ae63bfff693891c1bfc0fa39278e2ed3))
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
### BREAKING CHANGES
|
|
207
|
-
|
|
208
|
-
* remove props "timingConfig", add "springConfig" with no support of duration
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
## [0.5.4](https://github.com/dohooo/react-native-reanimated-carousel/compare/v1.1.0...v1.2.0-beta.3) (2021-10-27)
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
### Bug Fixes
|
|
216
|
-
|
|
217
|
-
* onSnapToItem gives floating index ([13d6c64](https://github.com/dohooo/react-native-reanimated-carousel/commit/13d6c6485f4fa54bf944b10947f928b2cf88c7b7)), closes [#13](https://github.com/dohooo/react-native-reanimated-carousel/issues/13)
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
## [0.5.3-beta.0](https://github.com/dohooo/react-native-reanimated-carousel/compare/v1.1.0...v1.2.0-beta.3) (2021-10-27)
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
### Bug Fixes
|
|
225
|
-
|
|
226
|
-
* drag issues occur when auto-scrolling ([ebb0ce2](https://github.com/dohooo/react-native-reanimated-carousel/commit/ebb0ce20d35b134755b163ea9ffc0e85daffdb9c)), closes [#13](https://github.com/dohooo/react-native-reanimated-carousel/issues/13)
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
## [0.5.2](https://github.com/dohooo/react-native-reanimated-carousel/compare/v1.1.0...v1.2.0-beta.3) (2021-10-19)
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
## [0.5.1](https://github.com/dohooo/react-native-reanimated-carousel/compare/v1.1.0...v1.2.0-beta.3) (2021-10-09)
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
### Features
|
|
238
|
-
|
|
239
|
-
* add onScrollBegin/onScrollEnd props ([3180696](https://github.com/dohooo/react-native-reanimated-carousel/commit/31806966ca644d086bfea7a872108b1006e50ecf))
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
# [0.5.0](https://github.com/dohooo/react-native-reanimated-carousel/compare/v1.1.0...v1.2.0-beta.3) (2021-10-08)
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
### Bug Fixes
|
|
247
|
-
|
|
248
|
-
* fix onSnapToItem no call when auto playing ([4953b98](https://github.com/dohooo/react-native-reanimated-carousel/commit/4953b9805beb5a591ee0b261c81c7dd623337a75))
|
|
249
|
-
* onSnapToItem not called if loop={false} ([1ce57f4](https://github.com/dohooo/react-native-reanimated-carousel/commit/1ce57f4e0201c2d50a1ce754f08b6afb5661a6a1))
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
### Features
|
|
253
|
-
|
|
254
|
-
* add goToIndex method ([b33bb78](https://github.com/dohooo/react-native-reanimated-carousel/commit/b33bb788e5849615b5c90b122633507ec0f2bfbf))
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
## [0.4.4](https://github.com/dohooo/react-native-reanimated-carousel/compare/v1.1.0...v1.2.0-beta.3) (2021-09-30)
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
### Bug Fixes
|
|
262
|
-
|
|
263
|
-
* fix animation bug ([d3b6831](https://github.com/dohooo/react-native-reanimated-carousel/commit/d3b683169cca9fba3083b52133758a7a39dcf25e))
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
## [0.4.3](https://github.com/dohooo/react-native-reanimated-carousel/compare/v1.1.0...v1.2.0-beta.3) (2021-09-09)
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
### Bug Fixes
|
|
271
|
-
|
|
272
|
-
* sliding causes problems with sliding errors when auto playing ([37f6565](https://github.com/dohooo/react-native-reanimated-carousel/commit/37f656539fed21f5a7d4148af02954b97f95a7f7))
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
## [0.4.2](https://github.com/dohooo/react-native-reanimated-carousel/compare/v1.1.0...v1.2.0-beta.3) (2021-09-09)
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
### Bug Fixes
|
|
280
|
-
|
|
281
|
-
* fixed scrolling on Android ([d253b3c](https://github.com/dohooo/react-native-reanimated-carousel/commit/d253b3cc30538a2702dceeb2be37c99fb2ee2d67))
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
## [0.4.1](https://github.com/dohooo/react-native-reanimated-carousel/compare/v1.1.0...v1.2.0-beta.3) (2021-09-08)
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
### Bug Fixes
|
|
289
|
-
|
|
290
|
-
* handles boundary cases for raw data ([4386bfd](https://github.com/dohooo/react-native-reanimated-carousel/commit/4386bfd59553c2df53c3987c539e299fac52a491))
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
# [0.4.0](https://github.com/dohooo/react-native-reanimated-carousel/compare/v1.1.0...v1.2.0-beta.3) (2021-09-08)
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
### Features
|
|
298
|
-
|
|
299
|
-
* add onSnapToItem props,should get current item info ([6ae05fc](https://github.com/dohooo/react-native-reanimated-carousel/commit/6ae05fcaa382c4b406d135c66bebdaa614c07b67))
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
## [0.3.1](https://github.com/dohooo/react-native-reanimated-carousel/compare/v1.1.0...v1.2.0-beta.3) (2021-09-08)
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
### Bug Fixes
|
|
307
|
-
|
|
308
|
-
* after data props update carousel not be can swipe ([dd00932](https://github.com/dohooo/react-native-reanimated-carousel/commit/dd00932b65df0e7efdc10e4f4e72cf8da5ca8456))
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
# [0.3.0](https://github.com/dohooo/react-native-reanimated-carousel/compare/v1.1.0...v1.2.0-beta.3) (2021-09-08)
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
### Features
|
|
316
|
-
|
|
317
|
-
* add loop props,control wheter loop playback ([97cf2b9](https://github.com/dohooo/react-native-reanimated-carousel/commit/97cf2b99c9279fc65da323e35b3461bc1df64b15))
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
## [0.2.2](https://github.com/dohooo/react-native-reanimated-carousel/compare/v1.1.0...v1.2.0-beta.3) (2021-09-07)
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
## [0.2.1](https://github.com/dohooo/react-native-reanimated-carousel/compare/v1.1.0...v1.2.0-beta.3) (2021-09-07)
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
### Bug Fixes
|
|
329
|
-
|
|
330
|
-
* fix calculation errors ([15b2119](https://github.com/dohooo/react-native-reanimated-carousel/commit/15b21192b510902e833900b5fc44affd78941614))
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
# [0.2.0](https://github.com/dohooo/react-native-reanimated-carousel/compare/v1.1.0...v1.2.0-beta.3) (2021-09-07)
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
### Bug Fixes
|
|
338
|
-
|
|
339
|
-
* fix algorithm errors ([af61df8](https://github.com/dohooo/react-native-reanimated-carousel/commit/af61df8da51c56940449c4f1c50440f567e33c46))
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
### Features
|
|
343
|
-
|
|
344
|
-
* export types ([2dcceb8](https://github.com/dohooo/react-native-reanimated-carousel/commit/2dcceb8001eff1b16c64399a4ca1b372ac9e8026))
|
|
345
|
-
* first commit of carousel component ([af964e3](https://github.com/dohooo/react-native-reanimated-carousel/commit/af964e331ae7b4363a407451344d9ffc1369b91f))
|
|
346
|
-
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.useIndexController = useIndexController;
|
|
7
|
-
|
|
8
|
-
var React = _interopRequireWildcard(require("react"));
|
|
9
|
-
|
|
10
|
-
var _reactNativeReanimated = require("react-native-reanimated");
|
|
11
|
-
|
|
12
|
-
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
13
|
-
|
|
14
|
-
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
15
|
-
|
|
16
|
-
function useIndexController(opts) {
|
|
17
|
-
const {
|
|
18
|
-
originalLength,
|
|
19
|
-
length,
|
|
20
|
-
size,
|
|
21
|
-
loop,
|
|
22
|
-
handlerOffsetX,
|
|
23
|
-
onChange
|
|
24
|
-
} = opts;
|
|
25
|
-
const index = (0, _reactNativeReanimated.useSharedValue)(0); // The Index displayed to the user
|
|
26
|
-
|
|
27
|
-
const sharedIndex = React.useRef(0);
|
|
28
|
-
const sharedPreIndex = React.useRef(0);
|
|
29
|
-
const convertToSharedIndex = React.useCallback(i => {
|
|
30
|
-
if (loop) {
|
|
31
|
-
switch (originalLength) {
|
|
32
|
-
case 1:
|
|
33
|
-
return 0;
|
|
34
|
-
|
|
35
|
-
case 2:
|
|
36
|
-
return i % 2;
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
return i;
|
|
41
|
-
}, [originalLength, loop]);
|
|
42
|
-
const computedIndex = React.useCallback(() => {
|
|
43
|
-
sharedPreIndex.current = sharedIndex.current;
|
|
44
|
-
const toInt = handlerOffsetX.value / size % length;
|
|
45
|
-
const i = handlerOffsetX.value <= 0 ? Math.abs(toInt) : Math.abs(toInt > 0 ? length - toInt : 0);
|
|
46
|
-
index.value = i;
|
|
47
|
-
|
|
48
|
-
const _sharedIndex = convertToSharedIndex(i);
|
|
49
|
-
|
|
50
|
-
sharedIndex.current = _sharedIndex;
|
|
51
|
-
onChange(_sharedIndex);
|
|
52
|
-
}, [length, handlerOffsetX, sharedPreIndex, index, size, sharedIndex, convertToSharedIndex, onChange]);
|
|
53
|
-
const getCurrentIndex = React.useCallback(() => {
|
|
54
|
-
return index.value;
|
|
55
|
-
}, [index]);
|
|
56
|
-
return {
|
|
57
|
-
index,
|
|
58
|
-
length,
|
|
59
|
-
sharedIndex,
|
|
60
|
-
sharedPreIndex,
|
|
61
|
-
computedIndex,
|
|
62
|
-
getCurrentIndex
|
|
63
|
-
};
|
|
64
|
-
}
|
|
65
|
-
//# sourceMappingURL=useIndexController.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["useIndexController.ts"],"names":["useIndexController","opts","originalLength","length","size","loop","handlerOffsetX","onChange","index","sharedIndex","React","useRef","sharedPreIndex","convertToSharedIndex","useCallback","i","computedIndex","current","toInt","value","Math","abs","_sharedIndex","getCurrentIndex"],"mappings":";;;;;;;AAAA;;AACA;;;;;;AAWO,SAASA,kBAAT,CAA4BC,IAA5B,EAQc;AACjB,QAAM;AAAEC,IAAAA,cAAF;AAAkBC,IAAAA,MAAlB;AAA0BC,IAAAA,IAA1B;AAAgCC,IAAAA,IAAhC;AAAsCC,IAAAA,cAAtC;AAAsDC,IAAAA;AAAtD,MACFN,IADJ;AAEA,QAAMO,KAAK,GAAG,2CAAuB,CAAvB,CAAd,CAHiB,CAIjB;;AACA,QAAMC,WAAW,GAAGC,KAAK,CAACC,MAAN,CAAqB,CAArB,CAApB;AACA,QAAMC,cAAc,GAAGF,KAAK,CAACC,MAAN,CAAqB,CAArB,CAAvB;AAEA,QAAME,oBAAoB,GAAGH,KAAK,CAACI,WAAN,CACxBC,CAAD,IAAe;AACX,QAAIV,IAAJ,EAAU;AACN,cAAQH,cAAR;AACI,aAAK,CAAL;AACI,iBAAO,CAAP;;AACJ,aAAK,CAAL;AACI,iBAAOa,CAAC,GAAG,CAAX;AAJR;AAMH;;AACD,WAAOA,CAAP;AACH,GAXwB,EAYzB,CAACb,cAAD,EAAiBG,IAAjB,CAZyB,CAA7B;AAeA,QAAMW,aAAa,GAAGN,KAAK,CAACI,WAAN,CAAkB,MAAM;AAC1CF,IAAAA,cAAc,CAACK,OAAf,GAAyBR,WAAW,CAACQ,OAArC;AACA,UAAMC,KAAK,GAAIZ,cAAc,CAACa,KAAf,GAAuBf,IAAxB,GAAgCD,MAA9C;AACA,UAAMY,CAAC,GACHT,cAAc,CAACa,KAAf,IAAwB,CAAxB,GACMC,IAAI,CAACC,GAAL,CAASH,KAAT,CADN,GAEME,IAAI,CAACC,GAAL,CAASH,KAAK,GAAG,CAAR,GAAYf,MAAM,GAAGe,KAArB,GAA6B,CAAtC,CAHV;AAIAV,IAAAA,KAAK,CAACW,KAAN,GAAcJ,CAAd;;AACA,UAAMO,YAAY,GAAGT,oBAAoB,CAACE,CAAD,CAAzC;;AACAN,IAAAA,WAAW,CAACQ,OAAZ,GAAsBK,YAAtB;AACAf,IAAAA,QAAQ,CAACe,YAAD,CAAR;AACH,GAXqB,EAWnB,CACCnB,MADD,EAECG,cAFD,EAGCM,cAHD,EAICJ,KAJD,EAKCJ,IALD,EAMCK,WAND,EAOCI,oBAPD,EAQCN,QARD,CAXmB,CAAtB;AAsBA,QAAMgB,eAAe,GAAGb,KAAK,CAACI,WAAN,CAAkB,MAAM;AAC5C,WAAON,KAAK,CAACW,KAAb;AACH,GAFuB,EAErB,CAACX,KAAD,CAFqB,CAAxB;AAIA,SAAO;AACHA,IAAAA,KADG;AAEHL,IAAAA,MAFG;AAGHM,IAAAA,WAHG;AAIHG,IAAAA,cAJG;AAKHI,IAAAA,aALG;AAMHO,IAAAA;AANG,GAAP;AAQH","sourcesContent":["import * as React from 'react';\nimport Animated, { useSharedValue } from 'react-native-reanimated';\n\nexport interface IIndexController {\n length: number;\n sharedPreIndex: React.MutableRefObject<number>;\n sharedIndex: React.MutableRefObject<number>;\n index: Animated.SharedValue<number>;\n computedIndex: () => void;\n getCurrentIndex: () => number;\n}\n\nexport function useIndexController(opts: {\n handlerOffsetX: Animated.SharedValue<number>;\n loop: boolean;\n // the length before fill data\n originalLength: number;\n length: number;\n size: number;\n onChange: (index: number) => void;\n}): IIndexController {\n const { originalLength, length, size, loop, handlerOffsetX, onChange } =\n opts;\n const index = useSharedValue<number>(0);\n // The Index displayed to the user\n const sharedIndex = React.useRef<number>(0);\n const sharedPreIndex = React.useRef<number>(0);\n\n const convertToSharedIndex = React.useCallback(\n (i: number) => {\n if (loop) {\n switch (originalLength) {\n case 1:\n return 0;\n case 2:\n return i % 2;\n }\n }\n return i;\n },\n [originalLength, loop]\n );\n\n const computedIndex = React.useCallback(() => {\n sharedPreIndex.current = sharedIndex.current;\n const toInt = (handlerOffsetX.value / size) % length;\n const i =\n handlerOffsetX.value <= 0\n ? Math.abs(toInt)\n : Math.abs(toInt > 0 ? length - toInt : 0);\n index.value = i;\n const _sharedIndex = convertToSharedIndex(i);\n sharedIndex.current = _sharedIndex;\n onChange(_sharedIndex);\n }, [\n length,\n handlerOffsetX,\n sharedPreIndex,\n index,\n size,\n sharedIndex,\n convertToSharedIndex,\n onChange,\n ]);\n\n const getCurrentIndex = React.useCallback(() => {\n return index.value;\n }, [index]);\n\n return {\n index,\n length,\n sharedIndex,\n sharedPreIndex,\n computedIndex,\n getCurrentIndex,\n };\n}\n"]}
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import * as React from 'react';
|
|
2
|
-
import { useSharedValue } from 'react-native-reanimated';
|
|
3
|
-
export function useIndexController(opts) {
|
|
4
|
-
const {
|
|
5
|
-
originalLength,
|
|
6
|
-
length,
|
|
7
|
-
size,
|
|
8
|
-
loop,
|
|
9
|
-
handlerOffsetX,
|
|
10
|
-
onChange
|
|
11
|
-
} = opts;
|
|
12
|
-
const index = useSharedValue(0); // The Index displayed to the user
|
|
13
|
-
|
|
14
|
-
const sharedIndex = React.useRef(0);
|
|
15
|
-
const sharedPreIndex = React.useRef(0);
|
|
16
|
-
const convertToSharedIndex = React.useCallback(i => {
|
|
17
|
-
if (loop) {
|
|
18
|
-
switch (originalLength) {
|
|
19
|
-
case 1:
|
|
20
|
-
return 0;
|
|
21
|
-
|
|
22
|
-
case 2:
|
|
23
|
-
return i % 2;
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
return i;
|
|
28
|
-
}, [originalLength, loop]);
|
|
29
|
-
const computedIndex = React.useCallback(() => {
|
|
30
|
-
sharedPreIndex.current = sharedIndex.current;
|
|
31
|
-
const toInt = handlerOffsetX.value / size % length;
|
|
32
|
-
const i = handlerOffsetX.value <= 0 ? Math.abs(toInt) : Math.abs(toInt > 0 ? length - toInt : 0);
|
|
33
|
-
index.value = i;
|
|
34
|
-
|
|
35
|
-
const _sharedIndex = convertToSharedIndex(i);
|
|
36
|
-
|
|
37
|
-
sharedIndex.current = _sharedIndex;
|
|
38
|
-
onChange(_sharedIndex);
|
|
39
|
-
}, [length, handlerOffsetX, sharedPreIndex, index, size, sharedIndex, convertToSharedIndex, onChange]);
|
|
40
|
-
const getCurrentIndex = React.useCallback(() => {
|
|
41
|
-
return index.value;
|
|
42
|
-
}, [index]);
|
|
43
|
-
return {
|
|
44
|
-
index,
|
|
45
|
-
length,
|
|
46
|
-
sharedIndex,
|
|
47
|
-
sharedPreIndex,
|
|
48
|
-
computedIndex,
|
|
49
|
-
getCurrentIndex
|
|
50
|
-
};
|
|
51
|
-
}
|
|
52
|
-
//# sourceMappingURL=useIndexController.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["useIndexController.ts"],"names":["React","useSharedValue","useIndexController","opts","originalLength","length","size","loop","handlerOffsetX","onChange","index","sharedIndex","useRef","sharedPreIndex","convertToSharedIndex","useCallback","i","computedIndex","current","toInt","value","Math","abs","_sharedIndex","getCurrentIndex"],"mappings":"AAAA,OAAO,KAAKA,KAAZ,MAAuB,OAAvB;AACA,SAAmBC,cAAnB,QAAyC,yBAAzC;AAWA,OAAO,SAASC,kBAAT,CAA4BC,IAA5B,EAQc;AACjB,QAAM;AAAEC,IAAAA,cAAF;AAAkBC,IAAAA,MAAlB;AAA0BC,IAAAA,IAA1B;AAAgCC,IAAAA,IAAhC;AAAsCC,IAAAA,cAAtC;AAAsDC,IAAAA;AAAtD,MACFN,IADJ;AAEA,QAAMO,KAAK,GAAGT,cAAc,CAAS,CAAT,CAA5B,CAHiB,CAIjB;;AACA,QAAMU,WAAW,GAAGX,KAAK,CAACY,MAAN,CAAqB,CAArB,CAApB;AACA,QAAMC,cAAc,GAAGb,KAAK,CAACY,MAAN,CAAqB,CAArB,CAAvB;AAEA,QAAME,oBAAoB,GAAGd,KAAK,CAACe,WAAN,CACxBC,CAAD,IAAe;AACX,QAAIT,IAAJ,EAAU;AACN,cAAQH,cAAR;AACI,aAAK,CAAL;AACI,iBAAO,CAAP;;AACJ,aAAK,CAAL;AACI,iBAAOY,CAAC,GAAG,CAAX;AAJR;AAMH;;AACD,WAAOA,CAAP;AACH,GAXwB,EAYzB,CAACZ,cAAD,EAAiBG,IAAjB,CAZyB,CAA7B;AAeA,QAAMU,aAAa,GAAGjB,KAAK,CAACe,WAAN,CAAkB,MAAM;AAC1CF,IAAAA,cAAc,CAACK,OAAf,GAAyBP,WAAW,CAACO,OAArC;AACA,UAAMC,KAAK,GAAIX,cAAc,CAACY,KAAf,GAAuBd,IAAxB,GAAgCD,MAA9C;AACA,UAAMW,CAAC,GACHR,cAAc,CAACY,KAAf,IAAwB,CAAxB,GACMC,IAAI,CAACC,GAAL,CAASH,KAAT,CADN,GAEME,IAAI,CAACC,GAAL,CAASH,KAAK,GAAG,CAAR,GAAYd,MAAM,GAAGc,KAArB,GAA6B,CAAtC,CAHV;AAIAT,IAAAA,KAAK,CAACU,KAAN,GAAcJ,CAAd;;AACA,UAAMO,YAAY,GAAGT,oBAAoB,CAACE,CAAD,CAAzC;;AACAL,IAAAA,WAAW,CAACO,OAAZ,GAAsBK,YAAtB;AACAd,IAAAA,QAAQ,CAACc,YAAD,CAAR;AACH,GAXqB,EAWnB,CACClB,MADD,EAECG,cAFD,EAGCK,cAHD,EAICH,KAJD,EAKCJ,IALD,EAMCK,WAND,EAOCG,oBAPD,EAQCL,QARD,CAXmB,CAAtB;AAsBA,QAAMe,eAAe,GAAGxB,KAAK,CAACe,WAAN,CAAkB,MAAM;AAC5C,WAAOL,KAAK,CAACU,KAAb;AACH,GAFuB,EAErB,CAACV,KAAD,CAFqB,CAAxB;AAIA,SAAO;AACHA,IAAAA,KADG;AAEHL,IAAAA,MAFG;AAGHM,IAAAA,WAHG;AAIHE,IAAAA,cAJG;AAKHI,IAAAA,aALG;AAMHO,IAAAA;AANG,GAAP;AAQH","sourcesContent":["import * as React from 'react';\nimport Animated, { useSharedValue } from 'react-native-reanimated';\n\nexport interface IIndexController {\n length: number;\n sharedPreIndex: React.MutableRefObject<number>;\n sharedIndex: React.MutableRefObject<number>;\n index: Animated.SharedValue<number>;\n computedIndex: () => void;\n getCurrentIndex: () => number;\n}\n\nexport function useIndexController(opts: {\n handlerOffsetX: Animated.SharedValue<number>;\n loop: boolean;\n // the length before fill data\n originalLength: number;\n length: number;\n size: number;\n onChange: (index: number) => void;\n}): IIndexController {\n const { originalLength, length, size, loop, handlerOffsetX, onChange } =\n opts;\n const index = useSharedValue<number>(0);\n // The Index displayed to the user\n const sharedIndex = React.useRef<number>(0);\n const sharedPreIndex = React.useRef<number>(0);\n\n const convertToSharedIndex = React.useCallback(\n (i: number) => {\n if (loop) {\n switch (originalLength) {\n case 1:\n return 0;\n case 2:\n return i % 2;\n }\n }\n return i;\n },\n [originalLength, loop]\n );\n\n const computedIndex = React.useCallback(() => {\n sharedPreIndex.current = sharedIndex.current;\n const toInt = (handlerOffsetX.value / size) % length;\n const i =\n handlerOffsetX.value <= 0\n ? Math.abs(toInt)\n : Math.abs(toInt > 0 ? length - toInt : 0);\n index.value = i;\n const _sharedIndex = convertToSharedIndex(i);\n sharedIndex.current = _sharedIndex;\n onChange(_sharedIndex);\n }, [\n length,\n handlerOffsetX,\n sharedPreIndex,\n index,\n size,\n sharedIndex,\n convertToSharedIndex,\n onChange,\n ]);\n\n const getCurrentIndex = React.useCallback(() => {\n return index.value;\n }, [index]);\n\n return {\n index,\n length,\n sharedIndex,\n sharedPreIndex,\n computedIndex,\n getCurrentIndex,\n };\n}\n"]}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import * as React from 'react';
|
|
2
|
-
import Animated from 'react-native-reanimated';
|
|
3
|
-
export interface IIndexController {
|
|
4
|
-
length: number;
|
|
5
|
-
sharedPreIndex: React.MutableRefObject<number>;
|
|
6
|
-
sharedIndex: React.MutableRefObject<number>;
|
|
7
|
-
index: Animated.SharedValue<number>;
|
|
8
|
-
computedIndex: () => void;
|
|
9
|
-
getCurrentIndex: () => number;
|
|
10
|
-
}
|
|
11
|
-
export declare function useIndexController(opts: {
|
|
12
|
-
handlerOffsetX: Animated.SharedValue<number>;
|
|
13
|
-
loop: boolean;
|
|
14
|
-
originalLength: number;
|
|
15
|
-
length: number;
|
|
16
|
-
size: number;
|
|
17
|
-
onChange: (index: number) => void;
|
|
18
|
-
}): IIndexController;
|
package/src/.DS_Store
DELETED
|
Binary file
|