react-native-reanimated-carousel 4.0.0-alpha.0 → 4.0.0-alpha.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.
- package/README.md +21 -160
- package/lib/commonjs/components/Carousel.js +231 -0
- package/lib/commonjs/components/Carousel.js.map +1 -0
- package/lib/commonjs/components/LazyView.js +22 -0
- package/lib/commonjs/components/LazyView.js.map +1 -0
- package/lib/commonjs/components/ScrollViewGesture.js +297 -0
- package/lib/commonjs/components/ScrollViewGesture.js.map +1 -0
- package/lib/commonjs/constants/index.js +21 -1
- package/lib/commonjs/constants/index.js.map +1 -1
- package/lib/commonjs/hooks/useAutoPlay.js +56 -1
- package/lib/commonjs/hooks/useAutoPlay.js.map +1 -1
- package/lib/commonjs/hooks/useCarouselController.js +244 -1
- package/lib/commonjs/hooks/useCarouselController.js.map +1 -1
- package/lib/commonjs/hooks/useCheckMounted.js +23 -1
- package/lib/commonjs/hooks/useCheckMounted.js.map +1 -1
- package/lib/commonjs/hooks/useCommonVariables.js +76 -1
- package/lib/commonjs/hooks/useCommonVariables.js.map +1 -1
- package/lib/commonjs/hooks/useInitProps.js +78 -1
- package/lib/commonjs/hooks/useInitProps.js.map +1 -1
- package/lib/commonjs/hooks/useLayoutConfig.js +39 -1
- package/lib/commonjs/hooks/useLayoutConfig.js.map +1 -1
- package/lib/commonjs/hooks/useOffsetX.js +48 -1
- package/lib/commonjs/hooks/useOffsetX.js.map +1 -1
- package/lib/commonjs/hooks/useOnProgressChange.js +38 -1
- package/lib/commonjs/hooks/useOnProgressChange.js.map +1 -1
- package/lib/commonjs/hooks/usePropsErrorBoundary.js +36 -1
- package/lib/commonjs/hooks/usePropsErrorBoundary.js.map +1 -1
- package/lib/commonjs/hooks/useUpdateGestureConfig.js +20 -0
- package/lib/commonjs/hooks/useUpdateGestureConfig.js.map +1 -0
- package/lib/commonjs/hooks/useVisibleRanges.js +42 -1
- package/lib/commonjs/hooks/useVisibleRanges.js.map +1 -1
- package/lib/commonjs/index.js +13 -1
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/layouts/BaseLayout.js +110 -1
- package/lib/commonjs/layouts/BaseLayout.js.map +1 -1
- package/lib/commonjs/layouts/ParallaxLayout.js +83 -1
- package/lib/commonjs/layouts/ParallaxLayout.js.map +1 -1
- package/lib/commonjs/layouts/index.js +20 -1
- package/lib/commonjs/layouts/index.js.map +1 -1
- package/lib/commonjs/layouts/normal.js +27 -1
- package/lib/commonjs/layouts/normal.js.map +1 -1
- package/lib/commonjs/layouts/parallax.js +38 -1
- package/lib/commonjs/layouts/parallax.js.map +1 -1
- package/lib/commonjs/layouts/stack.js +215 -1
- package/lib/commonjs/layouts/stack.js.map +1 -1
- package/lib/commonjs/store/index.js +14 -1
- package/lib/commonjs/store/index.js.map +1 -1
- package/lib/commonjs/types.js +5 -1
- package/lib/commonjs/utils/computeNewIndexWhenDataChanges.js +52 -0
- package/lib/commonjs/utils/computeNewIndexWhenDataChanges.js.map +1 -0
- package/lib/commonjs/utils/computed-with-auto-fill-data.js +124 -0
- package/lib/commonjs/utils/computed-with-auto-fill-data.js.map +1 -0
- package/lib/commonjs/utils/deal-with-animation.js +21 -0
- package/lib/commonjs/utils/deal-with-animation.js.map +1 -0
- package/lib/commonjs/utils/handleroffset-direction.js +16 -0
- package/lib/commonjs/utils/handleroffset-direction.js.map +1 -0
- package/lib/commonjs/utils/index.test.js +74 -0
- package/lib/commonjs/utils/index.test.js.map +1 -0
- package/lib/commonjs/utils/log.js +22 -1
- package/lib/commonjs/utils/log.js.map +1 -1
- package/lib/module/{Carousel.js → components/Carousel.js} +11 -12
- package/lib/module/components/Carousel.js.map +1 -0
- package/lib/module/{ScrollViewGesture.js → components/ScrollViewGesture.js} +14 -6
- package/lib/module/components/ScrollViewGesture.js.map +1 -0
- package/lib/module/hooks/useCarouselController.js +3 -3
- package/lib/module/hooks/useCarouselController.js.map +1 -1
- package/lib/module/hooks/useCommonVariables.js +2 -2
- package/lib/module/hooks/useCommonVariables.js.map +1 -1
- package/lib/module/hooks/useInitProps.js +1 -3
- package/lib/module/hooks/useInitProps.js.map +1 -1
- package/lib/module/hooks/useOnProgressChange.js +1 -1
- package/lib/module/hooks/useOnProgressChange.js.map +1 -1
- package/lib/module/hooks/useUpdateGestureConfig.js +10 -0
- package/lib/module/hooks/useUpdateGestureConfig.js.map +1 -0
- package/lib/module/index.js +1 -2
- package/lib/module/index.js.map +1 -1
- package/lib/module/layouts/BaseLayout.js +1 -1
- package/lib/module/layouts/BaseLayout.js.map +1 -1
- package/lib/module/layouts/ParallaxLayout.js +1 -1
- package/lib/module/layouts/ParallaxLayout.js.map +1 -1
- package/lib/module/utils/{computedWithAutoFillData.js → computed-with-auto-fill-data.js} +1 -1
- package/lib/module/utils/computed-with-auto-fill-data.js.map +1 -0
- package/lib/module/utils/{dealWithAnimation.js → deal-with-animation.js} +1 -1
- package/lib/module/utils/deal-with-animation.js.map +1 -0
- package/lib/module/utils/{handlerOffsetDirection.js → handleroffset-direction.js} +1 -1
- package/lib/module/utils/handleroffset-direction.js.map +1 -0
- package/lib/typescript/{Carousel.d.ts → components/Carousel.d.ts} +1 -1
- package/lib/typescript/hooks/useUpdateGestureConfig.d.ts +4 -0
- package/lib/typescript/index.d.ts +2 -2
- package/lib/typescript/types.d.ts +103 -103
- package/package.json +18 -16
- package/src/{Carousel.tsx → components/Carousel.tsx} +13 -13
- package/src/{ScrollViewGesture.tsx → components/ScrollViewGesture.tsx} +30 -15
- package/src/hooks/useCarouselController.tsx +3 -3
- package/src/hooks/useCommonVariables.ts +2 -2
- package/src/hooks/useInitProps.ts +1 -3
- package/src/hooks/useOnProgressChange.ts +1 -1
- package/src/hooks/useUpdateGestureConfig.ts +13 -0
- package/src/index.tsx +2 -2
- package/src/layouts/BaseLayout.tsx +1 -1
- package/src/layouts/ParallaxLayout.tsx +1 -1
- package/src/types.ts +122 -124
- package/README.zh-CN.md +0 -202
- package/lib/commonjs/Carousel.js +0 -2
- package/lib/commonjs/Carousel.js.map +0 -1
- package/lib/commonjs/LazyView.js +0 -2
- package/lib/commonjs/LazyView.js.map +0 -1
- package/lib/commonjs/ScrollViewGesture.js +0 -2
- package/lib/commonjs/ScrollViewGesture.js.map +0 -1
- package/lib/commonjs/hooks/computeNewIndexWhenDataChanges.js +0 -2
- package/lib/commonjs/hooks/computeNewIndexWhenDataChanges.js.map +0 -1
- package/lib/commonjs/hooks/index.test.js +0 -2
- package/lib/commonjs/hooks/index.test.js.map +0 -1
- package/lib/commonjs/utils/computedWithAutoFillData.js +0 -2
- package/lib/commonjs/utils/computedWithAutoFillData.js.map +0 -1
- package/lib/commonjs/utils/dealWithAnimation.js +0 -2
- package/lib/commonjs/utils/dealWithAnimation.js.map +0 -1
- package/lib/commonjs/utils/handlerOffsetDirection.js +0 -2
- package/lib/commonjs/utils/handlerOffsetDirection.js.map +0 -1
- package/lib/module/Carousel.js.map +0 -1
- package/lib/module/ScrollViewGesture.js.map +0 -1
- package/lib/module/utils/computedWithAutoFillData.js.map +0 -1
- package/lib/module/utils/dealWithAnimation.js.map +0 -1
- package/lib/module/utils/handlerOffsetDirection.js.map +0 -1
- /package/lib/module/{LazyView.js → components/LazyView.js} +0 -0
- /package/lib/module/{LazyView.js.map → components/LazyView.js.map} +0 -0
- /package/lib/module/{hooks → utils}/computeNewIndexWhenDataChanges.js +0 -0
- /package/lib/module/{hooks → utils}/computeNewIndexWhenDataChanges.js.map +0 -0
- /package/lib/module/{hooks → utils}/index.test.js +0 -0
- /package/lib/module/{hooks → utils}/index.test.js.map +0 -0
- /package/lib/typescript/{LazyView.d.ts → components/LazyView.d.ts} +0 -0
- /package/lib/typescript/{ScrollViewGesture.d.ts → components/ScrollViewGesture.d.ts} +0 -0
- /package/lib/typescript/{hooks → utils}/computeNewIndexWhenDataChanges.d.ts +0 -0
- /package/lib/typescript/utils/{computedWithAutoFillData.d.ts → computed-with-auto-fill-data.d.ts} +0 -0
- /package/lib/typescript/utils/{dealWithAnimation.d.ts → deal-with-animation.d.ts} +0 -0
- /package/lib/typescript/utils/{handlerOffsetDirection.d.ts → handleroffset-direction.d.ts} +0 -0
- /package/lib/typescript/{hooks → utils}/index.test.d.ts +0 -0
- /package/src/{LazyView.tsx → components/LazyView.tsx} +0 -0
- /package/src/{hooks → utils}/computeNewIndexWhenDataChanges.ts +0 -0
- /package/src/utils/{computedWithAutoFillData.ts → computed-with-auto-fill-data.ts} +0 -0
- /package/src/utils/{dealWithAnimation.ts → deal-with-animation.ts} +0 -0
- /package/src/utils/{handlerOffsetDirection.ts → handleroffset-direction.ts} +0 -0
- /package/src/{hooks → utils}/index.test.ts +0 -0
package/README.md
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
English | [简体中文](./README.zh-CN.md)
|
|
2
|
-
|
|
3
1
|
# react-native-reanimated-carousel
|
|
4
2
|
|
|
5
3
|
<img src="assets/home-banner.png" width="100%"/>
|
|
@@ -13,186 +11,49 @@ English | [简体中文](./README.zh-CN.md)
|
|
|
13
11
|
[](https://github.com/dohooo/react-native-reanimated-carousel/issues?q=is%3Aissue+is%3Aclosed)
|
|
14
12
|
[](https://discord.gg/KsXRuDs43y)
|
|
15
13
|
|
|
16
|
-
##
|
|
14
|
+
## The best carousel component in React Native community. ⚡️
|
|
15
|
+
|
|
16
|
+
- **It completely solved this** [problem](https://github.com/meliorence/react-native-snap-carousel/issues/632) **for `react-native-snap-carousel`**
|
|
17
|
+
- **Fully implemented using Reanimated 2&3**
|
|
18
|
+
- **[Demo](https://dohooo.github.io/react-native-reanimated-carousel/)**
|
|
17
19
|
|
|
18
|
-
|
|
19
|
-
- **Simple**, **Infinitely scrolling very smooth**, **Fully implemented using Reanimated 2!**
|
|
20
|
+
## Getting Started
|
|
20
21
|
|
|
21
|
-
|
|
22
|
+
Check out [the documentation website](https://reanimated-carousel.dev).
|
|
22
23
|
|
|
23
|
-
|
|
24
|
+
## Examples
|
|
24
25
|
|
|
25
|
-
> Click on the image to see the code snippets
|
|
26
|
+
> Click on the image to see the code snippets [[Try it]](https://snack.expo.dev/@zhaodonghao586/simple-carousel) 🍺
|
|
26
27
|
|
|
27
28
|
| <img src="assets/normal-horizontal.gif"/> | <img src="assets/normal-vertical.gif"/> | <img src="assets/parallax-horizontal.gif"/> |
|
|
28
29
|
| :------------------------------------------------------------------: | :-------------------------------------------------------------------: | :--------------------------------------------------------------------: |
|
|
29
|
-
| <a href="./
|
|
30
|
+
| <a href="./example/app/src/pages/normal/index.tsx">normal-horizontal</a> | <a href="./example/app/src/pages/normal/index.tsx">normal-vertical</a> | <a href="./example/app/src/pages/parallax/index.tsx">parallax-horizontal</a> |
|
|
30
31
|
| <img src="assets/parallax-vertical.gif"/> | <img src="assets/stack-horizontal-left.gif"/> | <img src="assets/stack-horizontal-right.gif"/> |
|
|
31
|
-
| <a href="./
|
|
32
|
+
| <a href="./example/app/src/pages/parallax/index.tsx">parallax-vertical</a> | <a href="./example/app/src/pages/stack/index.tsx">stack-horizontal-left</a> | <a href="./example/app/src/pages/stack/index.tsx">stack-horizontal-right</a> |
|
|
32
33
|
| <img src="assets/stack-vertical-left.gif"/> | <img src="assets/stack-vertical-right.gif"/> | <img src="assets/stack-horizontal-right.gif"/> |
|
|
33
|
-
| <a href="./
|
|
34
|
+
| <a href="./example/app/src/pages/stack/index.tsx">stack-vertical-left</a> | <a href="./example/app/src/pages/stack/index.tsx">stack-vertical-right</a> | <a href="./example/app/src/pages/stack/index.tsx">stack-horizontal-right</a> |
|
|
34
35
|
| <img src="assets/left-align.gif"/> |
|
|
35
|
-
| <a href="./
|
|
36
|
+
| <a href="./example/app/src/pages/left-align/index.tsx">left-align</a> |
|
|
36
37
|
|
|
37
38
|
|
|
38
|
-
>
|
|
39
|
+
> You can make cool animations with custom animation API [[Details]](https://reanimated-carousel.dev/custom-animations)
|
|
39
40
|
|
|
40
41
|
| <img src="assets/advanced-parallax.gif"/> | <img src="assets/pause-advanced-parallax.gif"/> | <img src="assets/scale-fade-in-out.gif"/> |
|
|
41
42
|
| :-----------------------------------------------------------------------------------------: | :---------------------------------------------------------------------------------------: | :---------------------------------------------------------------------------: |
|
|
42
|
-
| <a href="./
|
|
43
|
+
| <a href="./example/app/src/pages/advanced-parallax/index.tsx">advanced-parallax</a> | <a href="./example/app/src/pages/pause-advanced-parallax/index.tsx">pause-advanced-parallax</a> | <a href="./example/app/src/pages/scale-fade-in-out/index.tsx">scale-fade-in-out</a> |
|
|
43
44
|
| <img src="assets/rotate-scale-fade-in-out.gif"/> | <img src="assets/rotate-in-out.gif"/> | <img src="assets/anim-tab-bar.gif"/> |
|
|
44
|
-
| <a href="./
|
|
45
|
+
| <a href="./example/app/src/pages/rotate-scale-fade-in-out/index.tsx">rotate-scale-fade-in-out</a> | <a href="./example/app/src/pages/rotate-in-out/index.tsx">rotate-in-out</a> | <a href="./example/app/src/pages/anim-tab-bar/index.tsx">anim-tab-bar</a> |
|
|
45
46
|
| <img src="assets/marquee.gif"/> | <img src="assets/multiple.gif"/> | <img src="assets/circular.gif"/> |
|
|
46
|
-
| <a href="./
|
|
47
|
+
| <a href="./example/app/src/pages/marquee/index.tsx">marquee</a> | <a href="./example/app/src/pages/multiple/index.tsx">multiple</a> | <a href="./example/app/src/pages/circular/index.tsx">circular</a> |
|
|
47
48
|
| <img src="assets/fold.gif"/> | <img src="assets/tear.gif"/> | <img src="assets/press-swipe.gif"/> |
|
|
48
|
-
| <a href="./
|
|
49
|
+
| <a href="./example/app/src/pages/fold/index.tsx">fold</a> | <a href="./example/app/src/pages/tear/index.tsx">tear</a> | <a href="./example/app/src/pages/press-swipe/index.tsx">press-swipe</a> |
|
|
49
50
|
| <img src="assets/cube-3d.gif"/> | <img src="assets/blur-parallax.gif"/> | <img src="assets/curve.gif"/> |
|
|
50
|
-
| <a href="./
|
|
51
|
+
| <a href="./example/app/src/pages/cube-3d/index.tsx">cube-3d</a> | <a href="./example/app/src/pages/blur-parallax/index.tsx">blur-parallax</a> | <a href="./example/app/src/pages/curve/index.tsx">curve</a> |
|
|
51
52
|
| <img src="assets/parallax-layers.gif"/> | <img src="assets/stack-cards.gif"/> | <img src="assets/flow.gif"/> |
|
|
52
|
-
| <a href="./
|
|
53
|
+
| <a href="./example/app/src/pages/parallax-layers/index.tsx">parallax-layers</a> | <a href="./example/app/src/pages/stack-cards/index.tsx">stack-cards</a> | <a href="./example/app/src/pages/flow/index.tsx">flow</a> |
|
|
53
54
|
| <img src="assets/blur-rotate.gif"/> | ||
|
|
54
|
-
| <a href="./
|
|
55
|
-
|
|
56
|
-
## Table of contents
|
|
57
|
-
|
|
58
|
-
1. [Installation](#Installation)
|
|
59
|
-
1. [Usage](#Usage)
|
|
60
|
-
1. [Props](./docs/props.md)
|
|
61
|
-
1. [Tips](#Tips)
|
|
62
|
-
1. [Reason](#Reason)
|
|
63
|
-
1. [Example](#Example)
|
|
64
|
-
|
|
65
|
-
## Installation
|
|
66
|
-
|
|
67
|
-
Open a Terminal in the project root and run:
|
|
68
|
-
|
|
69
|
-
```sh
|
|
70
|
-
yarn add react-native-reanimated-carousel
|
|
71
|
-
```
|
|
72
|
-
|
|
73
|
-
Or if you use npm:
|
|
74
|
-
|
|
75
|
-
```sh
|
|
76
|
-
npm install react-native-reanimated-carousel
|
|
77
|
-
```
|
|
78
|
-
|
|
79
|
-
Now we need to install [`react-native-gesture-handler`](https://github.com/kmagiera/react-native-gesture-handler) and [`react-native-reanimated`](https://github.com/kmagiera/react-native-reanimated).
|
|
80
|
-
|
|
81
|
-
| | react-native-reanimated | react-native-gesture-handler |
|
|
82
|
-
| -------------------------------------- | ----------------------- | ---------------------------- |
|
|
83
|
-
| react-native-reanimated-carousel v1、v2 | >=2.0 & <2.7.0 | <2.9.0 |
|
|
84
|
-
| react-native-reanimated-carousel v3 | >=2.7.0 & < 3.x | <2.9.0 |
|
|
85
|
-
| react-native-reanimated-carousel v4 | >=3.x | >=2.9.0 |
|
|
86
|
-
|
|
87
|
-
## Usage
|
|
88
|
-
|
|
89
|
-
```tsx
|
|
90
|
-
import * as React from 'react';
|
|
91
|
-
import { Dimensions, Text, View } from 'react-native';
|
|
92
|
-
import Carousel from 'react-native-reanimated-carousel';
|
|
93
|
-
|
|
94
|
-
function Index() {
|
|
95
|
-
const width = Dimensions.get('window').width;
|
|
96
|
-
return (
|
|
97
|
-
<View style={{ flex: 1 }}>
|
|
98
|
-
<Carousel
|
|
99
|
-
loop
|
|
100
|
-
width={width}
|
|
101
|
-
height={width / 2}
|
|
102
|
-
autoPlay={true}
|
|
103
|
-
data={[...new Array(6).keys()]}
|
|
104
|
-
scrollAnimationDuration={1000}
|
|
105
|
-
onSnapToItem={(index) => console.log('current index:', index)}
|
|
106
|
-
renderItem={({ index }) => (
|
|
107
|
-
<View
|
|
108
|
-
style={{
|
|
109
|
-
flex: 1,
|
|
110
|
-
borderWidth: 1,
|
|
111
|
-
justifyContent: 'center',
|
|
112
|
-
}}
|
|
113
|
-
>
|
|
114
|
-
<Text style={{ textAlign: 'center', fontSize: 30 }}>
|
|
115
|
-
{index}
|
|
116
|
-
</Text>
|
|
117
|
-
</View>
|
|
118
|
-
)}
|
|
119
|
-
/>
|
|
120
|
-
</View>
|
|
121
|
-
);
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
export default Index;
|
|
125
|
-
|
|
126
|
-
```
|
|
127
|
-
|
|
128
|
-
## Tips
|
|
129
|
-
|
|
130
|
-
- Optimizing
|
|
131
|
-
|
|
132
|
-
- When rendering a large number of elements, you can use the 'windowSize' property to control how many items of the current element are rendered. The default is full rendering. After testing without this property, frames will drop when rendering 200 empty views. After setting this property, rendering 1000 empty views is still smooth. (The specific number depends on the phone model tested)
|
|
133
|
-
|
|
134
|
-
- Used in `ScrollView/FlatList`
|
|
135
|
-
|
|
136
|
-
- **[#143](https://github.com/dohooo/react-native-reanimated-carousel/issues/143) - Carousel suppresses ScrollView/FlatList scroll gesture handler:** When using a carousel with a layout oriented to only one direction (vertical/horizontal) and inside a ScrollView/FlatList, it is important for the user experience that the unused axis does not impede the scroll of the list. So that, for example, the x-axis is free we can change the [activeOffsetX](https://docs.swmansion.com/react-native-gesture-handler/docs/1.10.3/api/gesture-handlers/pan-gh/#activeoffsetx) of the gesture handler:
|
|
137
|
-
|
|
138
|
-
```tsx
|
|
139
|
-
<Carousel
|
|
140
|
-
{...}
|
|
141
|
-
panGestureHandlerProps={{
|
|
142
|
-
activeOffsetX: [-10, 10],
|
|
143
|
-
}}
|
|
144
|
-
/>
|
|
145
|
-
```
|
|
146
|
-
|
|
147
|
-
- RTL
|
|
148
|
-
- Support to RTL mode with no more configuration needed. But in RTL mode, need to manually set the autoPlayReverse props for autoplay to control scrolling direction.
|
|
149
|
-
- EXPO
|
|
150
|
-
- If use EXPO managed workflow please ensure that the version is greater than 41.Because the old version not support `Reanimated(v2)`.
|
|
151
|
-
- Working principle
|
|
152
|
-
- [About RNRC](./docs/about.md)
|
|
153
|
-
|
|
154
|
-
- How to run tests in `exampleExpo`
|
|
155
|
-
```shell
|
|
156
|
-
$ yarn prepare
|
|
157
|
-
$ yarn link --global
|
|
158
|
-
$ cd ./exampleExpo
|
|
159
|
-
$ yarn link react-native-reanimated-carousel --global
|
|
160
|
-
$ yarn test
|
|
161
|
-
```
|
|
162
|
-
|
|
163
|
-
## Reason
|
|
164
|
-
|
|
165
|
-
<details>
|
|
166
|
-
<summary>The common RN infinite scroll component. It get stuck on a fast slide. Wait for the next element to appear. This component will not have similar problems.Because using a completely different approach so the best performance is achieved.That's why this library was created.</summary>
|
|
167
|
-
<p align="center">
|
|
168
|
-
Use react-native-snap-carousel for quick swiping,you can see caton clearly when you reach the junction.(gif 4.6mb)
|
|
169
|
-
</p>
|
|
170
|
-
<p align="center">
|
|
171
|
-
<img src="assets/react-native-snap-carousel.gif" width="50%"/>
|
|
172
|
-
</p>
|
|
173
|
-
|
|
174
|
-
<p align="center">
|
|
175
|
-
Compared with react-native-reanimated-carousel,The actual test was ten slides per second, but it didn't show up very well in gif.
|
|
176
|
-
</p>
|
|
177
|
-
<p align="center">
|
|
178
|
-
<img src="assets/normal-fast.gif" width="50%"/>
|
|
179
|
-
</p>
|
|
180
|
-
</details>
|
|
181
|
-
|
|
182
|
-
## Example
|
|
183
|
-
|
|
184
|
-
> `:pretty` use pretty images
|
|
185
|
-
|
|
186
|
-
```shell
|
|
187
|
-
yarn ios
|
|
188
|
-
yarn ios:pretty
|
|
189
|
-
|
|
190
|
-
yarn android
|
|
191
|
-
yarn android:pretty
|
|
55
|
+
| <a href="./example/app/src/pages/blur-rotate/index.tsx">blur-rotate</a> | | |
|
|
192
56
|
|
|
193
|
-
yarn web
|
|
194
|
-
yarn web:pretty
|
|
195
|
-
```
|
|
196
57
|
|
|
197
58
|
## Sponsors
|
|
198
59
|
|
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
|
|
8
|
+
var _react = _interopRequireDefault(require("react"));
|
|
9
|
+
|
|
10
|
+
var _reactNative = require("react-native");
|
|
11
|
+
|
|
12
|
+
var _reactNativeGestureHandler = require("react-native-gesture-handler");
|
|
13
|
+
|
|
14
|
+
var _reactNativeReanimated = require("react-native-reanimated");
|
|
15
|
+
|
|
16
|
+
var _ScrollViewGesture = require("./ScrollViewGesture");
|
|
17
|
+
|
|
18
|
+
var _useAutoPlay = require("../hooks/useAutoPlay");
|
|
19
|
+
|
|
20
|
+
var _useCarouselController = require("../hooks/useCarouselController");
|
|
21
|
+
|
|
22
|
+
var _useCommonVariables = require("../hooks/useCommonVariables");
|
|
23
|
+
|
|
24
|
+
var _useInitProps = require("../hooks/useInitProps");
|
|
25
|
+
|
|
26
|
+
var _useLayoutConfig = require("../hooks/useLayoutConfig");
|
|
27
|
+
|
|
28
|
+
var _useOnProgressChange = require("../hooks/useOnProgressChange");
|
|
29
|
+
|
|
30
|
+
var _usePropsErrorBoundary = require("../hooks/usePropsErrorBoundary");
|
|
31
|
+
|
|
32
|
+
var _useVisibleRanges = require("../hooks/useVisibleRanges");
|
|
33
|
+
|
|
34
|
+
var _BaseLayout = require("../layouts/BaseLayout");
|
|
35
|
+
|
|
36
|
+
var _store = require("../store");
|
|
37
|
+
|
|
38
|
+
var _computedWithAutoFillData = require("../utils/computed-with-auto-fill-data");
|
|
39
|
+
|
|
40
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
41
|
+
|
|
42
|
+
const Carousel = /*#__PURE__*/_react.default.forwardRef((_props, ref) => {
|
|
43
|
+
const props = (0, _useInitProps.useInitProps)(_props);
|
|
44
|
+
const {
|
|
45
|
+
testID,
|
|
46
|
+
loop,
|
|
47
|
+
autoFillData,
|
|
48
|
+
// Fill data with autoFillData
|
|
49
|
+
data,
|
|
50
|
+
// Length of fill data
|
|
51
|
+
dataLength,
|
|
52
|
+
// Raw data that has not been processed
|
|
53
|
+
rawData,
|
|
54
|
+
// Length of raw data
|
|
55
|
+
rawDataLength,
|
|
56
|
+
mode,
|
|
57
|
+
style,
|
|
58
|
+
width,
|
|
59
|
+
height,
|
|
60
|
+
vertical,
|
|
61
|
+
autoPlay,
|
|
62
|
+
windowSize,
|
|
63
|
+
autoPlayReverse,
|
|
64
|
+
autoPlayInterval,
|
|
65
|
+
scrollAnimationDuration,
|
|
66
|
+
withAnimation,
|
|
67
|
+
renderItem,
|
|
68
|
+
onScrollEnd,
|
|
69
|
+
onSnapToItem,
|
|
70
|
+
onScrollBegin,
|
|
71
|
+
onProgressChange,
|
|
72
|
+
customAnimation,
|
|
73
|
+
defaultIndex
|
|
74
|
+
} = props;
|
|
75
|
+
const commonVariables = (0, _useCommonVariables.useCommonVariables)(props);
|
|
76
|
+
const {
|
|
77
|
+
size,
|
|
78
|
+
handlerOffset
|
|
79
|
+
} = commonVariables;
|
|
80
|
+
const offsetX = (0, _reactNativeReanimated.useDerivedValue)(() => {
|
|
81
|
+
const totalSize = size * dataLength;
|
|
82
|
+
const x = handlerOffset.value % totalSize;
|
|
83
|
+
if (!loop) return handlerOffset.value;
|
|
84
|
+
return isNaN(x) ? 0 : x;
|
|
85
|
+
}, [loop, size, dataLength]);
|
|
86
|
+
(0, _usePropsErrorBoundary.usePropsErrorBoundary)({ ...props,
|
|
87
|
+
dataLength
|
|
88
|
+
});
|
|
89
|
+
(0, _useOnProgressChange.useOnProgressChange)({
|
|
90
|
+
autoFillData,
|
|
91
|
+
loop,
|
|
92
|
+
size,
|
|
93
|
+
offsetX,
|
|
94
|
+
rawDataLength,
|
|
95
|
+
onProgressChange
|
|
96
|
+
});
|
|
97
|
+
const carouselController = (0, _useCarouselController.useCarouselController)({
|
|
98
|
+
loop,
|
|
99
|
+
size,
|
|
100
|
+
dataLength,
|
|
101
|
+
autoFillData,
|
|
102
|
+
handlerOffset,
|
|
103
|
+
withAnimation,
|
|
104
|
+
defaultIndex,
|
|
105
|
+
onScrollEnd: () => (0, _reactNativeReanimated.runOnJS)(_onScrollEnd)(),
|
|
106
|
+
onScrollBegin: () => !!onScrollBegin && (0, _reactNativeReanimated.runOnJS)(onScrollBegin)(),
|
|
107
|
+
duration: scrollAnimationDuration
|
|
108
|
+
});
|
|
109
|
+
const {
|
|
110
|
+
next,
|
|
111
|
+
prev,
|
|
112
|
+
scrollTo,
|
|
113
|
+
getSharedIndex,
|
|
114
|
+
getCurrentIndex
|
|
115
|
+
} = carouselController;
|
|
116
|
+
const {
|
|
117
|
+
start: startAutoPlay,
|
|
118
|
+
pause: pauseAutoPlay
|
|
119
|
+
} = (0, _useAutoPlay.useAutoPlay)({
|
|
120
|
+
autoPlay,
|
|
121
|
+
autoPlayInterval,
|
|
122
|
+
autoPlayReverse,
|
|
123
|
+
carouselController
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
const _onScrollEnd = _react.default.useCallback(() => {
|
|
127
|
+
const _sharedIndex = Math.round(getSharedIndex());
|
|
128
|
+
|
|
129
|
+
const realIndex = (0, _computedWithAutoFillData.computedRealIndexWithAutoFillData)({
|
|
130
|
+
index: _sharedIndex,
|
|
131
|
+
dataLength: rawDataLength,
|
|
132
|
+
loop,
|
|
133
|
+
autoFillData
|
|
134
|
+
});
|
|
135
|
+
if (onSnapToItem) onSnapToItem(realIndex);
|
|
136
|
+
if (onScrollEnd) onScrollEnd(realIndex);
|
|
137
|
+
}, [loop, autoFillData, rawDataLength, getSharedIndex, onSnapToItem, onScrollEnd]);
|
|
138
|
+
|
|
139
|
+
const scrollViewGestureOnScrollBegin = _react.default.useCallback(() => {
|
|
140
|
+
pauseAutoPlay();
|
|
141
|
+
onScrollBegin === null || onScrollBegin === void 0 ? void 0 : onScrollBegin();
|
|
142
|
+
}, [onScrollBegin, pauseAutoPlay]);
|
|
143
|
+
|
|
144
|
+
const scrollViewGestureOnScrollEnd = _react.default.useCallback(() => {
|
|
145
|
+
startAutoPlay();
|
|
146
|
+
|
|
147
|
+
_onScrollEnd();
|
|
148
|
+
}, [_onScrollEnd, startAutoPlay]);
|
|
149
|
+
|
|
150
|
+
const scrollViewGestureOnTouchBegin = _react.default.useCallback(pauseAutoPlay, [pauseAutoPlay]);
|
|
151
|
+
|
|
152
|
+
const scrollViewGestureOnTouchEnd = _react.default.useCallback(startAutoPlay, [startAutoPlay]);
|
|
153
|
+
|
|
154
|
+
_react.default.useImperativeHandle(ref, () => ({
|
|
155
|
+
next,
|
|
156
|
+
prev,
|
|
157
|
+
getCurrentIndex,
|
|
158
|
+
scrollTo
|
|
159
|
+
}), [getCurrentIndex, next, prev, scrollTo]);
|
|
160
|
+
|
|
161
|
+
const visibleRanges = (0, _useVisibleRanges.useVisibleRanges)({
|
|
162
|
+
total: dataLength,
|
|
163
|
+
viewSize: size,
|
|
164
|
+
translation: handlerOffset,
|
|
165
|
+
windowSize
|
|
166
|
+
});
|
|
167
|
+
const layoutConfig = (0, _useLayoutConfig.useLayoutConfig)({ ...props,
|
|
168
|
+
size
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
const renderLayout = _react.default.useCallback((item, i) => {
|
|
172
|
+
const realIndex = (0, _computedWithAutoFillData.computedRealIndexWithAutoFillData)({
|
|
173
|
+
index: i,
|
|
174
|
+
dataLength: rawDataLength,
|
|
175
|
+
loop,
|
|
176
|
+
autoFillData
|
|
177
|
+
});
|
|
178
|
+
return /*#__PURE__*/_react.default.createElement(_BaseLayout.BaseLayout, {
|
|
179
|
+
key: i,
|
|
180
|
+
index: i,
|
|
181
|
+
handlerOffset: offsetX,
|
|
182
|
+
visibleRanges: visibleRanges,
|
|
183
|
+
animationStyle: customAnimation || layoutConfig
|
|
184
|
+
}, _ref => {
|
|
185
|
+
let {
|
|
186
|
+
animationValue
|
|
187
|
+
} = _ref;
|
|
188
|
+
return renderItem({
|
|
189
|
+
item,
|
|
190
|
+
index: realIndex,
|
|
191
|
+
animationValue
|
|
192
|
+
});
|
|
193
|
+
});
|
|
194
|
+
}, [loop, rawData, offsetX, visibleRanges, autoFillData, renderItem, layoutConfig, customAnimation]);
|
|
195
|
+
|
|
196
|
+
return /*#__PURE__*/_react.default.createElement(_reactNativeGestureHandler.GestureHandlerRootView, null, /*#__PURE__*/_react.default.createElement(_store.CTX.Provider, {
|
|
197
|
+
value: {
|
|
198
|
+
props,
|
|
199
|
+
common: commonVariables
|
|
200
|
+
}
|
|
201
|
+
}, /*#__PURE__*/_react.default.createElement(_ScrollViewGesture.ScrollViewGesture, {
|
|
202
|
+
key: mode,
|
|
203
|
+
size: size,
|
|
204
|
+
translation: handlerOffset,
|
|
205
|
+
style: [styles.container, {
|
|
206
|
+
width: width || "100%",
|
|
207
|
+
height: height || "100%"
|
|
208
|
+
}, style, vertical ? styles.itemsVertical : styles.itemsHorizontal],
|
|
209
|
+
testID: testID,
|
|
210
|
+
onScrollBegin: scrollViewGestureOnScrollBegin,
|
|
211
|
+
onScrollEnd: scrollViewGestureOnScrollEnd,
|
|
212
|
+
onTouchBegin: scrollViewGestureOnTouchBegin,
|
|
213
|
+
onTouchEnd: scrollViewGestureOnTouchEnd
|
|
214
|
+
}, data.map(renderLayout))));
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
var _default = Carousel;
|
|
218
|
+
exports.default = _default;
|
|
219
|
+
|
|
220
|
+
const styles = _reactNative.StyleSheet.create({
|
|
221
|
+
container: {
|
|
222
|
+
overflow: "hidden"
|
|
223
|
+
},
|
|
224
|
+
itemsHorizontal: {
|
|
225
|
+
flexDirection: "row"
|
|
226
|
+
},
|
|
227
|
+
itemsVertical: {
|
|
228
|
+
flexDirection: "column"
|
|
229
|
+
}
|
|
230
|
+
});
|
|
231
|
+
//# sourceMappingURL=Carousel.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["Carousel.tsx"],"names":["Carousel","React","forwardRef","_props","ref","props","testID","loop","autoFillData","data","dataLength","rawData","rawDataLength","mode","style","width","height","vertical","autoPlay","windowSize","autoPlayReverse","autoPlayInterval","scrollAnimationDuration","withAnimation","renderItem","onScrollEnd","onSnapToItem","onScrollBegin","onProgressChange","customAnimation","defaultIndex","commonVariables","size","handlerOffset","offsetX","totalSize","x","value","isNaN","carouselController","_onScrollEnd","duration","next","prev","scrollTo","getSharedIndex","getCurrentIndex","start","startAutoPlay","pause","pauseAutoPlay","useCallback","_sharedIndex","Math","round","realIndex","index","scrollViewGestureOnScrollBegin","scrollViewGestureOnScrollEnd","scrollViewGestureOnTouchBegin","scrollViewGestureOnTouchEnd","useImperativeHandle","visibleRanges","total","viewSize","translation","layoutConfig","renderLayout","item","i","animationValue","common","styles","container","itemsVertical","itemsHorizontal","map","StyleSheet","create","overflow","flexDirection"],"mappings":";;;;;;;AAAA;;AACA;;AACA;;AACA;;AAEA;;AAEA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AAEA;;;;AAEA,MAAMA,QAAQ,gBAAGC,eAAMC,UAAN,CACf,CAACC,MAAD,EAASC,GAAT,KAAiB;AACf,QAAMC,KAAK,GAAG,gCAAaF,MAAb,CAAd;AAEA,QA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AAY,EAAEC,6BAlBhB;AAmBE,IAAA,UAAU,EAAEC;AAnBd,KAqBGnD,IAAI,CAACmE,GAAL,CAAST,YAAT,CArBH,CADF,CADF,CADF;AA6BD,CApNc,CAAjB;;eAuNenE,Q;;;AAIf,MAAMwE,MAAM,GAAGK,wBAAWC,MAAX,CAAkB;AAC/BL,EAAAA,SAAS,EAAE;AACTM,IAAAA,QAAQ,EAAE;AADD,GADoB;AAI/BJ,EAAAA,eAAe,EAAE;AACfK,IAAAA,aAAa,EAAE;AADA,GAJc;AAO/BN,EAAAA,aAAa,EAAE;AACbM,IAAAA,aAAa,EAAE;AADF;AAPgB,CAAlB,CAAf","sourcesContent":["import React from \"react\";\nimport { StyleSheet } from \"react-native\";\nimport { GestureHandlerRootView } from \"react-native-gesture-handler\";\nimport { runOnJS, useDerivedValue } from \"react-native-reanimated\";\n\nimport { ScrollViewGesture } from \"./ScrollViewGesture\";\n\nimport { useAutoPlay } from \"../hooks/useAutoPlay\";\nimport { useCarouselController } from \"../hooks/useCarouselController\";\nimport { useCommonVariables } from \"../hooks/useCommonVariables\";\nimport { useInitProps } from \"../hooks/useInitProps\";\nimport { useLayoutConfig } from \"../hooks/useLayoutConfig\";\nimport { useOnProgressChange } from \"../hooks/useOnProgressChange\";\nimport { usePropsErrorBoundary } from \"../hooks/usePropsErrorBoundary\";\nimport { useVisibleRanges } from \"../hooks/useVisibleRanges\";\nimport { BaseLayout } from \"../layouts/BaseLayout\";\nimport { CTX } from \"../store\";\nimport type { ICarouselInstance, TCarouselProps } from \"../types\";\nimport { computedRealIndexWithAutoFillData } from \"../utils/computed-with-auto-fill-data\";\n\nconst Carousel = React.forwardRef<ICarouselInstance, TCarouselProps<any>>(\n (_props, ref) => {\n const props = useInitProps(_props);\n\n const {\n testID,\n loop,\n autoFillData,\n // Fill data with autoFillData\n data,\n // Length of fill data\n dataLength,\n // Raw data that has not been processed\n rawData,\n // Length of raw data\n rawDataLength,\n mode,\n style,\n width,\n height,\n vertical,\n autoPlay,\n windowSize,\n autoPlayReverse,\n autoPlayInterval,\n scrollAnimationDuration,\n withAnimation,\n renderItem,\n onScrollEnd,\n onSnapToItem,\n onScrollBegin,\n onProgressChange,\n customAnimation,\n defaultIndex,\n } = props;\n\n const commonVariables = useCommonVariables(props);\n const { size, handlerOffset } = commonVariables;\n\n const offsetX = useDerivedValue(() => {\n const totalSize = size * dataLength;\n const x = handlerOffset.value % totalSize;\n\n if (!loop)\n return handlerOffset.value;\n\n return isNaN(x) ? 0 : x;\n }, [loop, size, dataLength]);\n\n usePropsErrorBoundary({ ...props, dataLength });\n useOnProgressChange({\n autoFillData,\n loop,\n size,\n offsetX,\n rawDataLength,\n onProgressChange,\n });\n\n const carouselController = useCarouselController({\n loop,\n size,\n dataLength,\n autoFillData,\n handlerOffset,\n withAnimation,\n defaultIndex,\n onScrollEnd: () => runOnJS(_onScrollEnd)(),\n onScrollBegin: () => !!onScrollBegin && runOnJS(onScrollBegin)(),\n duration: scrollAnimationDuration,\n });\n\n const { next, prev, scrollTo, getSharedIndex, getCurrentIndex }\n = carouselController;\n\n const { start: startAutoPlay, pause: pauseAutoPlay } = useAutoPlay({\n autoPlay,\n autoPlayInterval,\n autoPlayReverse,\n carouselController,\n });\n\n const _onScrollEnd = React.useCallback(() => {\n const _sharedIndex = Math.round(getSharedIndex());\n\n const realIndex = computedRealIndexWithAutoFillData({\n index: _sharedIndex,\n dataLength: rawDataLength,\n loop,\n autoFillData,\n });\n\n if (onSnapToItem)\n onSnapToItem(realIndex);\n\n if (onScrollEnd)\n onScrollEnd(realIndex);\n }, [\n loop,\n autoFillData,\n rawDataLength,\n getSharedIndex,\n onSnapToItem,\n onScrollEnd,\n ]);\n\n const scrollViewGestureOnScrollBegin = React.useCallback(() => {\n pauseAutoPlay();\n onScrollBegin?.();\n }, [onScrollBegin, pauseAutoPlay]);\n\n const scrollViewGestureOnScrollEnd = React.useCallback(() => {\n startAutoPlay();\n _onScrollEnd();\n }, [_onScrollEnd, startAutoPlay]);\n\n const scrollViewGestureOnTouchBegin = React.useCallback(pauseAutoPlay, [\n pauseAutoPlay,\n ]);\n\n const scrollViewGestureOnTouchEnd = React.useCallback(startAutoPlay, [\n startAutoPlay,\n ]);\n\n React.useImperativeHandle(\n ref,\n () => ({\n next,\n prev,\n getCurrentIndex,\n scrollTo,\n }),\n [getCurrentIndex, next, prev, scrollTo],\n );\n\n const visibleRanges = useVisibleRanges({\n total: dataLength,\n viewSize: size,\n translation: handlerOffset,\n windowSize,\n });\n\n const layoutConfig = useLayoutConfig({ ...props, size });\n\n const renderLayout = React.useCallback(\n (item: any, i: number) => {\n const realIndex = computedRealIndexWithAutoFillData({\n index: i,\n dataLength: rawDataLength,\n loop,\n autoFillData,\n });\n\n return (\n <BaseLayout\n key={i}\n index={i}\n handlerOffset={offsetX}\n visibleRanges={visibleRanges}\n animationStyle={customAnimation || layoutConfig}\n >\n {({ animationValue }) =>\n renderItem({\n item,\n index: realIndex,\n animationValue,\n })\n }\n </BaseLayout>\n );\n },\n [\n loop,\n rawData,\n offsetX,\n visibleRanges,\n autoFillData,\n renderItem,\n layoutConfig,\n customAnimation,\n ],\n );\n\n return (\n <GestureHandlerRootView>\n <CTX.Provider value={{ props, common: commonVariables }}>\n <ScrollViewGesture\n key={mode}\n size={size}\n translation={handlerOffset}\n style={[\n styles.container,\n {\n width: width || \"100%\",\n height: height || \"100%\",\n },\n style,\n vertical\n ? styles.itemsVertical\n : styles.itemsHorizontal,\n ]}\n testID={testID}\n onScrollBegin={scrollViewGestureOnScrollBegin}\n onScrollEnd={scrollViewGestureOnScrollEnd}\n onTouchBegin={scrollViewGestureOnTouchBegin}\n onTouchEnd={scrollViewGestureOnTouchEnd}\n >\n {data.map(renderLayout)}\n </ScrollViewGesture>\n </CTX.Provider>\n </GestureHandlerRootView>\n );\n },\n);\n\nexport default Carousel as <T extends any>(\n props: React.PropsWithChildren<TCarouselProps<T>>\n) => React.ReactElement;\n\nconst styles = StyleSheet.create({\n container: {\n overflow: \"hidden\",\n },\n itemsHorizontal: {\n flexDirection: \"row\",\n },\n itemsVertical: {\n flexDirection: \"column\",\n },\n});\n"]}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.LazyView = void 0;
|
|
7
|
+
|
|
8
|
+
var _react = _interopRequireDefault(require("react"));
|
|
9
|
+
|
|
10
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
|
+
|
|
12
|
+
const LazyView = props => {
|
|
13
|
+
const {
|
|
14
|
+
shouldUpdate,
|
|
15
|
+
children
|
|
16
|
+
} = props;
|
|
17
|
+
if (!shouldUpdate) return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null);
|
|
18
|
+
return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, children);
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
exports.LazyView = LazyView;
|
|
22
|
+
//# sourceMappingURL=LazyView.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["LazyView.tsx"],"names":["LazyView","props","shouldUpdate","children"],"mappings":";;;;;;;AACA;;;;AAMO,MAAMA,QAA4C,GAAIC,KAAD,IAAW;AACrE,QAAM;AAAEC,IAAAA,YAAF;AAAgBC,IAAAA;AAAhB,MAA6BF,KAAnC;AAEA,MAAI,CAACC,YAAL,EACE,oBAAO,2DAAP;AAEF,sBAAO,4DAAGC,QAAH,CAAP;AACD,CAPM","sourcesContent":["import type { PropsWithChildren } from \"react\";\nimport React from \"react\";\n\ninterface Props {\n shouldUpdate: boolean\n}\n\nexport const LazyView: React.FC<PropsWithChildren<Props>> = (props) => {\n const { shouldUpdate, children } = props;\n\n if (!shouldUpdate)\n return <></>;\n\n return <>{children}</>;\n};\n"]}
|