react-native-reanimated-carousel 2.0.0 → 2.2.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.
Files changed (68) hide show
  1. package/README.md +40 -10
  2. package/README.zh-CN.md +42 -9
  3. package/lib/commonjs/Carousel.js +20 -10
  4. package/lib/commonjs/Carousel.js.map +1 -1
  5. package/lib/commonjs/ScrollViewGesture.js +13 -5
  6. package/lib/commonjs/ScrollViewGesture.js.map +1 -1
  7. package/lib/commonjs/constants/index.js +9 -1
  8. package/lib/commonjs/constants/index.js.map +1 -1
  9. package/lib/commonjs/hooks/useAutoPlay.js +22 -16
  10. package/lib/commonjs/hooks/useAutoPlay.js.map +1 -1
  11. package/lib/commonjs/hooks/useCarouselController.js +94 -30
  12. package/lib/commonjs/hooks/useCarouselController.js.map +1 -1
  13. package/lib/commonjs/hooks/useInitProps.js +4 -1
  14. package/lib/commonjs/hooks/useInitProps.js.map +1 -1
  15. package/lib/commonjs/layouts/BaseLayout.js +14 -8
  16. package/lib/commonjs/layouts/BaseLayout.js.map +1 -1
  17. package/lib/commonjs/layouts/normal.js +1 -1
  18. package/lib/commonjs/layouts/normal.js.map +1 -1
  19. package/lib/commonjs/layouts/parallax.js.map +1 -1
  20. package/lib/commonjs/layouts/stack.js +15 -0
  21. package/lib/commonjs/layouts/stack.js.map +1 -1
  22. package/lib/module/Carousel.js +20 -10
  23. package/lib/module/Carousel.js.map +1 -1
  24. package/lib/module/ScrollViewGesture.js +13 -6
  25. package/lib/module/ScrollViewGesture.js.map +1 -1
  26. package/lib/module/constants/index.js +5 -0
  27. package/lib/module/constants/index.js.map +1 -1
  28. package/lib/module/hooks/useAutoPlay.js +22 -16
  29. package/lib/module/hooks/useAutoPlay.js.map +1 -1
  30. package/lib/module/hooks/useCarouselController.js +91 -30
  31. package/lib/module/hooks/useCarouselController.js.map +1 -1
  32. package/lib/module/hooks/useInitProps.js +4 -1
  33. package/lib/module/hooks/useInitProps.js.map +1 -1
  34. package/lib/module/layouts/BaseLayout.js +14 -10
  35. package/lib/module/layouts/BaseLayout.js.map +1 -1
  36. package/lib/module/layouts/normal.js +2 -2
  37. package/lib/module/layouts/normal.js.map +1 -1
  38. package/lib/module/layouts/parallax.js.map +1 -1
  39. package/lib/module/layouts/stack.js +12 -0
  40. package/lib/module/layouts/stack.js.map +1 -1
  41. package/lib/typescript/constants/index.d.ts +3 -0
  42. package/lib/typescript/hooks/useAutoPlay.d.ts +1 -1
  43. package/lib/typescript/hooks/useCarouselController.d.ts +8 -5
  44. package/lib/typescript/hooks/useInitProps.d.ts +3 -6
  45. package/lib/typescript/layouts/BaseLayout.d.ts +3 -0
  46. package/lib/typescript/layouts/parallax.d.ts +9 -1
  47. package/lib/typescript/layouts/stack.d.ts +25 -0
  48. package/lib/typescript/types.d.ts +45 -32
  49. package/package.json +11 -4
  50. package/src/Carousel.tsx +27 -8
  51. package/src/ScrollViewGesture.tsx +12 -5
  52. package/src/constants/index.ts +6 -0
  53. package/src/hooks/useAutoPlay.ts +20 -23
  54. package/src/hooks/useCarouselController.tsx +112 -50
  55. package/src/hooks/useInitProps.ts +18 -8
  56. package/src/layouts/BaseLayout.tsx +26 -12
  57. package/src/layouts/normal.ts +2 -7
  58. package/src/layouts/parallax.ts +10 -1
  59. package/src/layouts/stack.ts +42 -0
  60. package/src/types.ts +50 -32
  61. package/CHANGELOG.md +0 -324
  62. package/lib/commonjs/hooks/useIndexController.js +0 -65
  63. package/lib/commonjs/hooks/useIndexController.js.map +0 -1
  64. package/lib/module/hooks/useIndexController.js +0 -52
  65. package/lib/module/hooks/useIndexController.js.map +0 -1
  66. package/lib/typescript/hooks/useIndexController.d.ts +0 -18
  67. package/src/.DS_Store +0 -0
  68. package/src/hooks/useIndexController.ts +0 -78
package/src/types.ts CHANGED
@@ -1,7 +1,8 @@
1
1
  import type { ViewStyle } from 'react-native';
2
2
  import type { PanGestureHandlerProps } from 'react-native-gesture-handler';
3
- import type { ILayoutConfig as IStackLayoutConfig } from './layouts/stack';
4
- import type { ILayoutConfig as IParallaxLayoutConfig } from './layouts/parallax';
3
+ import type Animated from 'react-native-reanimated';
4
+ import type { TParallaxModeProps } from './layouts/parallax';
5
+ import type { TStackModeProps } from './layouts/stack';
5
6
 
6
7
  export type ComputedDirectionTypes<T, VP = {}, HP = {}> =
7
8
  | (T &
@@ -35,31 +36,10 @@ export type ComputedDirectionTypes<T, VP = {}, HP = {}> =
35
36
  height?: number;
36
37
  });
37
38
 
38
- type TParallaxModeProps = ComputedDirectionTypes<{
39
- /**
40
- * Carousel Animated transitions.
41
- */
42
- mode?: 'parallax';
43
- modeConfig?: IParallaxLayoutConfig;
44
- }>;
45
-
46
- type TStackModeProps = ComputedDirectionTypes<{
47
- /**
48
- * Carousel Animated transitions.
49
- */
50
- mode?: 'horizontal-stack' | 'vertical-stack';
51
- /**
52
- * Stack animation style.
53
- * @default
54
- * mode: 'vertical',
55
- * snapDirection: 'right',
56
- * moveSize: window.width,
57
- * stackInterval: 30,
58
- * scaleInterval: 0.08,
59
- * rotateZDeg: 135,
60
- */
61
- modeConfig?: IStackLayoutConfig;
62
- }>;
39
+ export type CustomConfig = {
40
+ type?: 'negative' | 'positive';
41
+ viewCount?: number;
42
+ };
63
43
 
64
44
  export type TCarouselProps<T = any> = {
65
45
  ref?: React.Ref<ICarouselInstance>;
@@ -91,6 +71,11 @@ export type TCarouselProps<T = any> = {
91
71
  * @description playback interval
92
72
  */
93
73
  autoPlayInterval?: number;
74
+ /**
75
+ * Time a scroll animation takes to finish
76
+ * @default 500 (ms)
77
+ */
78
+ scrollAnimationDuration?: number;
94
79
  /**
95
80
  * Carousel container style
96
81
  */
@@ -120,10 +105,19 @@ export type TCarouselProps<T = any> = {
120
105
  * @default true
121
106
  */
122
107
  enableSnap?: boolean;
108
+ /**
109
+ * Custom carousel config.
110
+ */
111
+ customConfig?: () => CustomConfig;
112
+ /**
113
+ * Custom animations.
114
+ * Must use `worklet`, Details: https://docs.swmansion.com/react-native-reanimated/docs/2.2.0/worklets/
115
+ */
116
+ customAnimation?: (value: number) => Animated.AnimatedStyleProp<ViewStyle>;
123
117
  /**
124
118
  * Render carousel item.
125
119
  */
126
- renderItem: (data: T, index: number) => React.ReactNode;
120
+ renderItem: CarouselRenderItem<T>;
127
121
  /**
128
122
  * Callback fired when navigating to an item
129
123
  */
@@ -149,19 +143,43 @@ export type TCarouselProps<T = any> = {
149
143
 
150
144
  export interface ICarouselInstance {
151
145
  /**
152
- * Play the last one
146
+ * Scroll to previous item, it takes one optional argument (count),
147
+ * which allows you to specify how many items to cross
153
148
  */
154
- prev: () => void;
149
+ prev: (opts?: TCarouselActionOptions) => void;
155
150
  /**
156
- * Play the next one
151
+ * Scroll to next item, it takes one optional argument (count),
152
+ * which allows you to specify how many items to cross
157
153
  */
158
- next: () => void;
154
+ next: (opts?: TCarouselActionOptions) => void;
159
155
  /**
160
156
  * Get current item index
161
157
  */
162
158
  getCurrentIndex: () => number;
163
159
  /**
164
160
  * Go to index
161
+ * @deprecated use scrollTo instead
165
162
  */
166
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;
169
+ }
170
+
171
+ export interface CarouselRenderItemInfo<ItemT> {
172
+ item: ItemT;
173
+ index: number;
174
+ animationValue: Animated.SharedValue<number>;
175
+ }
176
+
177
+ export type CarouselRenderItem<ItemT> = (
178
+ info: CarouselRenderItemInfo<ItemT>
179
+ ) => React.ReactElement;
180
+
181
+ export interface TCarouselActionOptions {
182
+ count?: number;
183
+ animated?: boolean;
184
+ onFinished?: () => void;
167
185
  }
package/CHANGELOG.md DELETED
@@ -1,324 +0,0 @@
1
- # [2.0.0](https://github.com/dohooo/react-native-reanimated-carousel/compare/v1.2.0-beta.4...v2.0.0) (2022-01-07)
2
-
3
-
4
- ### Bug Fixes
5
-
6
- * fix bug from refactoring ([c77f4d8](https://github.com/dohooo/react-native-reanimated-carousel/commit/c77f4d8604e319528f2d15fd288734749615e077))
7
-
8
- # [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)
9
-
10
-
11
- ### Bug Fixes
12
-
13
- * solve a bug caused by Parallax/Normal layout reconstruction ([651bf5e](https://github.com/dohooo/react-native-reanimated-carousel/commit/651bf5ee0572f512dddc01205dbb74d651cfa0ce))
14
-
15
- # [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)
16
-
17
-
18
- ### Bug Fixes
19
-
20
- * 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)
21
- * 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)
22
-
23
-
24
- ### Features
25
-
26
- * 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)
27
-
28
-
29
-
30
- # [1.1.0](https://github.com/dohooo/react-native-reanimated-carousel/compare/v1.1.0...v1.2.0-beta.3) (2022-01-03)
31
-
32
-
33
- ### Bug Fixes
34
-
35
- * _ ([c8054f1](https://github.com/dohooo/react-native-reanimated-carousel/commit/c8054f17202e7ff33447cd70e83582f4914941ad))
36
- * fix item blink when scroll active ([96c9b75](https://github.com/dohooo/react-native-reanimated-carousel/commit/96c9b751a7ee4cc0ba013801d098b05705c26bcf))
37
- * fix with zindex ([f3b28cc](https://github.com/dohooo/react-native-reanimated-carousel/commit/f3b28cc8a83649a885307b82908e714bb2724ab4))
38
- * item blink ([063f564](https://github.com/dohooo/react-native-reanimated-carousel/commit/063f5644779f37754608972507b10d0cfb87769a))
39
- * item zIndex ([10e58a8](https://github.com/dohooo/react-native-reanimated-carousel/commit/10e58a876e8cb386a45d17ea8eb8bee79de0e94a))
40
- * refactor stack layout ([dc975fe](https://github.com/dohooo/react-native-reanimated-carousel/commit/dc975fe8f25b03b59047fd21f596d626f806de2b))
41
-
42
-
43
- ### Features
44
-
45
- * add stack layout ([5a70a23](https://github.com/dohooo/react-native-reanimated-carousel/commit/5a70a230307e0b258e16230d6b21be2c4d8c7497))
46
- * multiple stack styles are supported ([d4497a7](https://github.com/dohooo/react-native-reanimated-carousel/commit/d4497a785f6da4dae79e812dac1d5515303d0cd3))
47
- * 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)
48
-
49
-
50
-
51
- ## [1.0.12](https://github.com/dohooo/react-native-reanimated-carousel/compare/v1.1.0...v1.2.0-beta.3) (2021-12-28)
52
-
53
-
54
- ### Bug Fixes
55
-
56
- * 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)
57
-
58
-
59
-
60
- ## [1.0.11](https://github.com/dohooo/react-native-reanimated-carousel/compare/v1.1.0...v1.2.0-beta.3) (2021-12-20)
61
-
62
-
63
- ### Bug Fixes
64
-
65
- * fixed useAnimatedReaction wrong import ([7b7a3fc](https://github.com/dohooo/react-native-reanimated-carousel/commit/7b7a3fc4f49b5f3bfff664b2c07306334ac2e509))
66
-
67
-
68
-
69
- ## [1.0.10](https://github.com/dohooo/react-native-reanimated-carousel/compare/v1.1.0...v1.2.0-beta.3) (2021-12-19)
70
-
71
-
72
- ### Bug Fixes
73
-
74
- * fix ScrollViewGesture callback ([40412fc](https://github.com/dohooo/react-native-reanimated-carousel/commit/40412fcab6c1e6e013ccd8c409c2fb9bffcde926))
75
- * fixed failure to set default values ([5d02779](https://github.com/dohooo/react-native-reanimated-carousel/commit/5d0277925a0daf00944e7900d86f3ee463f77719))
76
- * fixed types ([9f3068b](https://github.com/dohooo/react-native-reanimated-carousel/commit/9f3068bbb9dadbdd046ad50cf4437b53f335e4a9))
77
- * modify useCarouselController params ([c8f2c6a](https://github.com/dohooo/react-native-reanimated-carousel/commit/c8f2c6acb9b578fa38d365c669aaf2beb6694686))
78
-
79
-
80
- ### Features
81
-
82
- * add babel-loader in example,support to web ([1edc9c3](https://github.com/dohooo/react-native-reanimated-carousel/commit/1edc9c34a7a02e35fa6c18927d8b543367bb1c30))
83
- * add examples ([666ba86](https://github.com/dohooo/react-native-reanimated-carousel/commit/666ba86729105bb825f95a9dbdc4290efbd3dffa))
84
- * add navigation in example ([1687f1d](https://github.com/dohooo/react-native-reanimated-carousel/commit/1687f1db4c98e583f29326dc1b2a273adb19af4e))
85
- * add ScrollViewGesture ([a903f12](https://github.com/dohooo/react-native-reanimated-carousel/commit/a903f12d73a18c2774318154544dda17c755f6ff))
86
- * lazy loading ([ed75232](https://github.com/dohooo/react-native-reanimated-carousel/commit/ed75232eb25a475f994f327e94f9dd717b9cf251))
87
- * springConfig props has be deprecated ([763c073](https://github.com/dohooo/react-native-reanimated-carousel/commit/763c07398f196391ebf478ebd9c45acd7c6890a3))
88
- * 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)
89
-
90
-
91
- ### Performance Improvements
92
-
93
- * add example ([1684038](https://github.com/dohooo/react-native-reanimated-carousel/commit/16840383712eda31b1a8481fa5498ed9b92504cd))
94
- * add example ([8527ffb](https://github.com/dohooo/react-native-reanimated-carousel/commit/8527ffbd2b374f880a42d445a24c385c18885859))
95
- * lazy loading ([39ba773](https://github.com/dohooo/react-native-reanimated-carousel/commit/39ba7735946326c10dd5ec8b6ffe6a8fcf9a8006))
96
-
97
-
98
-
99
- ## [1.0.9](https://github.com/dohooo/react-native-reanimated-carousel/compare/v1.1.0...v1.2.0-beta.3) (2021-12-07)
100
-
101
-
102
- ### Performance Improvements
103
-
104
- * 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)
105
- * 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)
106
-
107
-
108
-
109
- ## [1.0.8](https://github.com/dohooo/react-native-reanimated-carousel/compare/v1.1.0...v1.2.0-beta.3) (2021-12-06)
110
-
111
-
112
- ### Bug Fixes
113
-
114
- * 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)
115
-
116
-
117
-
118
- ## [1.0.7](https://github.com/dohooo/react-native-reanimated-carousel/compare/v1.1.0...v1.2.0-beta.3) (2021-12-05)
119
-
120
-
121
- ### Bug Fixes
122
-
123
- * 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)
124
- * 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)
125
- * fix computed error with MAX/MIN ([e9a3007](https://github.com/dohooo/react-native-reanimated-carousel/commit/e9a30070dbae04a889015be05aff398079f35e84))
126
- * 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)
127
- * modify useOffsetX viewCount default value ([dd30b9c](https://github.com/dohooo/react-native-reanimated-carousel/commit/dd30b9c0ec52917eeb1d0a144e46318a1bae7da8))
128
- * 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)
129
-
130
-
131
-
132
- ## [1.0.4](https://github.com/dohooo/react-native-reanimated-carousel/compare/v1.1.0...v1.2.0-beta.3) (2021-11-18)
133
-
134
-
135
- ### Bug Fixes
136
-
137
- * **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)
138
-
139
-
140
-
141
- ## [1.0.3](https://github.com/dohooo/react-native-reanimated-carousel/compare/v1.1.0...v1.2.0-beta.3) (2021-11-10)
142
-
143
-
144
- ### Features
145
-
146
- * 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)
147
-
148
-
149
-
150
- ## [1.0.2](https://github.com/dohooo/react-native-reanimated-carousel/compare/v1.1.0...v1.2.0-beta.3) (2021-11-03)
151
-
152
-
153
- ### Features
154
-
155
- * add onProgressChange props ([a3894ff](https://github.com/dohooo/react-native-reanimated-carousel/commit/a3894ffb64d2541e61683d06c53487dc54af1a47))
156
-
157
-
158
-
159
- ## [1.0.1](https://github.com/dohooo/react-native-reanimated-carousel/compare/v1.1.0...v1.2.0-beta.3) (2021-11-01)
160
-
161
-
162
- ### Bug Fixes
163
-
164
- * fix bug with reanimated ([6744f74](https://github.com/dohooo/react-native-reanimated-carousel/commit/6744f747424d6ad51e61bca0702eec8e60d00441))
165
-
166
-
167
-
168
- # [1.0.0](https://github.com/dohooo/react-native-reanimated-carousel/compare/v1.1.0...v1.2.0-beta.3) (2021-10-31)
169
-
170
-
171
- ### Bug Fixes
172
-
173
- * fix default timeConfig ([0f99500](https://github.com/dohooo/react-native-reanimated-carousel/commit/0f9950005604fa19ff73449a58b3944bd4f1fee2))
174
- * solve sliding flicker problem ([96678e0](https://github.com/dohooo/react-native-reanimated-carousel/commit/96678e0d3c03ea6f6bc9a40534c1bb732475e102))
175
- * solve sliding flicker problem ([e26c384](https://github.com/dohooo/react-native-reanimated-carousel/commit/e26c384f25b203a420f7bed2c356586cb1466f65))
176
- * upgrade expo sdk 40 to 41. fix example error ([11b39b1](https://github.com/dohooo/react-native-reanimated-carousel/commit/11b39b16f682551ad1b2b67e497ea0709d7b7766))
177
-
178
-
179
- ### Features
180
-
181
- * improve sliding experience ([14b62ee](https://github.com/dohooo/react-native-reanimated-carousel/commit/14b62ee3ae63bfff693891c1bfc0fa39278e2ed3))
182
-
183
-
184
- ### BREAKING CHANGES
185
-
186
- * remove props "timingConfig", add "springConfig" with no support of duration
187
-
188
-
189
-
190
- ## [0.5.4](https://github.com/dohooo/react-native-reanimated-carousel/compare/v1.1.0...v1.2.0-beta.3) (2021-10-27)
191
-
192
-
193
- ### Bug Fixes
194
-
195
- * 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)
196
-
197
-
198
-
199
- ## [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)
200
-
201
-
202
- ### Bug Fixes
203
-
204
- * 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)
205
-
206
-
207
-
208
- ## [0.5.2](https://github.com/dohooo/react-native-reanimated-carousel/compare/v1.1.0...v1.2.0-beta.3) (2021-10-19)
209
-
210
-
211
-
212
- ## [0.5.1](https://github.com/dohooo/react-native-reanimated-carousel/compare/v1.1.0...v1.2.0-beta.3) (2021-10-09)
213
-
214
-
215
- ### Features
216
-
217
- * add onScrollBegin/onScrollEnd props ([3180696](https://github.com/dohooo/react-native-reanimated-carousel/commit/31806966ca644d086bfea7a872108b1006e50ecf))
218
-
219
-
220
-
221
- # [0.5.0](https://github.com/dohooo/react-native-reanimated-carousel/compare/v1.1.0...v1.2.0-beta.3) (2021-10-08)
222
-
223
-
224
- ### Bug Fixes
225
-
226
- * fix onSnapToItem no call when auto playing ([4953b98](https://github.com/dohooo/react-native-reanimated-carousel/commit/4953b9805beb5a591ee0b261c81c7dd623337a75))
227
- * onSnapToItem not called if loop={false} ([1ce57f4](https://github.com/dohooo/react-native-reanimated-carousel/commit/1ce57f4e0201c2d50a1ce754f08b6afb5661a6a1))
228
-
229
-
230
- ### Features
231
-
232
- * add goToIndex method ([b33bb78](https://github.com/dohooo/react-native-reanimated-carousel/commit/b33bb788e5849615b5c90b122633507ec0f2bfbf))
233
-
234
-
235
-
236
- ## [0.4.4](https://github.com/dohooo/react-native-reanimated-carousel/compare/v1.1.0...v1.2.0-beta.3) (2021-09-30)
237
-
238
-
239
- ### Bug Fixes
240
-
241
- * fix animation bug ([d3b6831](https://github.com/dohooo/react-native-reanimated-carousel/commit/d3b683169cca9fba3083b52133758a7a39dcf25e))
242
-
243
-
244
-
245
- ## [0.4.3](https://github.com/dohooo/react-native-reanimated-carousel/compare/v1.1.0...v1.2.0-beta.3) (2021-09-09)
246
-
247
-
248
- ### Bug Fixes
249
-
250
- * sliding causes problems with sliding errors when auto playing ([37f6565](https://github.com/dohooo/react-native-reanimated-carousel/commit/37f656539fed21f5a7d4148af02954b97f95a7f7))
251
-
252
-
253
-
254
- ## [0.4.2](https://github.com/dohooo/react-native-reanimated-carousel/compare/v1.1.0...v1.2.0-beta.3) (2021-09-09)
255
-
256
-
257
- ### Bug Fixes
258
-
259
- * fixed scrolling on Android ([d253b3c](https://github.com/dohooo/react-native-reanimated-carousel/commit/d253b3cc30538a2702dceeb2be37c99fb2ee2d67))
260
-
261
-
262
-
263
- ## [0.4.1](https://github.com/dohooo/react-native-reanimated-carousel/compare/v1.1.0...v1.2.0-beta.3) (2021-09-08)
264
-
265
-
266
- ### Bug Fixes
267
-
268
- * handles boundary cases for raw data ([4386bfd](https://github.com/dohooo/react-native-reanimated-carousel/commit/4386bfd59553c2df53c3987c539e299fac52a491))
269
-
270
-
271
-
272
- # [0.4.0](https://github.com/dohooo/react-native-reanimated-carousel/compare/v1.1.0...v1.2.0-beta.3) (2021-09-08)
273
-
274
-
275
- ### Features
276
-
277
- * add onSnapToItem props,should get current item info ([6ae05fc](https://github.com/dohooo/react-native-reanimated-carousel/commit/6ae05fcaa382c4b406d135c66bebdaa614c07b67))
278
-
279
-
280
-
281
- ## [0.3.1](https://github.com/dohooo/react-native-reanimated-carousel/compare/v1.1.0...v1.2.0-beta.3) (2021-09-08)
282
-
283
-
284
- ### Bug Fixes
285
-
286
- * after data props update carousel not be can swipe ([dd00932](https://github.com/dohooo/react-native-reanimated-carousel/commit/dd00932b65df0e7efdc10e4f4e72cf8da5ca8456))
287
-
288
-
289
-
290
- # [0.3.0](https://github.com/dohooo/react-native-reanimated-carousel/compare/v1.1.0...v1.2.0-beta.3) (2021-09-08)
291
-
292
-
293
- ### Features
294
-
295
- * add loop props,control wheter loop playback ([97cf2b9](https://github.com/dohooo/react-native-reanimated-carousel/commit/97cf2b99c9279fc65da323e35b3461bc1df64b15))
296
-
297
-
298
-
299
- ## [0.2.2](https://github.com/dohooo/react-native-reanimated-carousel/compare/v1.1.0...v1.2.0-beta.3) (2021-09-07)
300
-
301
-
302
-
303
- ## [0.2.1](https://github.com/dohooo/react-native-reanimated-carousel/compare/v1.1.0...v1.2.0-beta.3) (2021-09-07)
304
-
305
-
306
- ### Bug Fixes
307
-
308
- * fix calculation errors ([15b2119](https://github.com/dohooo/react-native-reanimated-carousel/commit/15b21192b510902e833900b5fc44affd78941614))
309
-
310
-
311
-
312
- # [0.2.0](https://github.com/dohooo/react-native-reanimated-carousel/compare/v1.1.0...v1.2.0-beta.3) (2021-09-07)
313
-
314
-
315
- ### Bug Fixes
316
-
317
- * fix algorithm errors ([af61df8](https://github.com/dohooo/react-native-reanimated-carousel/commit/af61df8da51c56940449c4f1c50440f567e33c46))
318
-
319
-
320
- ### Features
321
-
322
- * export types ([2dcceb8](https://github.com/dohooo/react-native-reanimated-carousel/commit/2dcceb8001eff1b16c64399a4ca1b372ac9e8026))
323
- * first commit of carousel component ([af964e3](https://github.com/dohooo/react-native-reanimated-carousel/commit/af964e331ae7b4363a407451344d9ffc1369b91f))
324
-
@@ -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