react-native-reanimated-carousel 3.0.0 → 3.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +65 -23
- package/README.zh-CN.md +62 -23
- package/lib/commonjs/ScrollViewGesture.js +1 -1
- package/lib/commonjs/ScrollViewGesture.js.map +1 -1
- package/lib/commonjs/hooks/useCarouselController.js +1 -1
- package/lib/commonjs/hooks/useCarouselController.js.map +1 -1
- package/lib/commonjs/hooks/useInitProps.js.map +1 -1
- package/lib/commonjs/hooks/useLayoutConfig.js.map +1 -1
- package/lib/commonjs/hooks/useOnProgressChange.js.map +1 -1
- package/lib/commonjs/hooks/usePropsErrorBoundary.js +1 -1
- package/lib/commonjs/hooks/usePropsErrorBoundary.js.map +1 -1
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/layouts/BaseLayout.js.map +1 -1
- package/lib/commonjs/layouts/ParallaxLayout.js.map +1 -1
- package/lib/commonjs/layouts/parallax.js.map +1 -1
- package/lib/commonjs/layouts/stack.js.map +1 -1
- package/lib/commonjs/store/index.js.map +1 -1
- package/lib/commonjs/utils/computedWithAutoFillData.js.map +1 -1
- package/lib/module/ScrollViewGesture.js +9 -4
- package/lib/module/ScrollViewGesture.js.map +1 -1
- package/lib/module/hooks/useCarouselController.js +20 -8
- package/lib/module/hooks/useCarouselController.js.map +1 -1
- package/lib/module/hooks/useInitProps.js +1 -1
- package/lib/module/hooks/useInitProps.js.map +1 -1
- package/lib/module/hooks/useLayoutConfig.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/usePropsErrorBoundary.js +1 -1
- package/lib/module/hooks/usePropsErrorBoundary.js.map +1 -1
- 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.map +1 -1
- package/lib/module/layouts/parallax.js.map +1 -1
- package/lib/module/layouts/stack.js.map +1 -1
- package/lib/module/store/index.js.map +1 -1
- package/lib/module/utils/computedWithAutoFillData.js +1 -1
- package/lib/module/utils/computedWithAutoFillData.js.map +1 -1
- package/lib/typescript/hooks/useLayoutConfig.d.ts +1 -1
- package/lib/typescript/hooks/usePropsErrorBoundary.d.ts +1 -1
- package/lib/typescript/index.d.ts +1 -1
- package/lib/typescript/layouts/ParallaxLayout.d.ts +2 -2
- package/lib/typescript/layouts/parallax.d.ts +2 -2
- package/lib/typescript/layouts/stack.d.ts +2 -2
- package/lib/typescript/store/index.d.ts +1 -1
- package/lib/typescript/types.d.ts +1 -1
- package/package.json +16 -13
- package/src/ScrollViewGesture.tsx +17 -13
- package/src/hooks/useCarouselController.tsx +31 -7
- package/src/hooks/useInitProps.ts +1 -1
- package/src/hooks/useLayoutConfig.ts +1 -1
- package/src/hooks/useOnProgressChange.ts +1 -1
- package/src/hooks/usePropsErrorBoundary.ts +2 -2
- package/src/index.tsx +5 -1
- package/src/layouts/BaseLayout.tsx +1 -1
- package/src/layouts/ParallaxLayout.tsx +2 -2
- package/src/layouts/parallax.ts +2 -2
- package/src/layouts/stack.ts +2 -2
- package/src/store/index.ts +1 -1
- package/src/types.ts +1 -1
- package/src/utils/computedWithAutoFillData.ts +1 -1
package/README.md
CHANGED
|
@@ -23,25 +23,32 @@ English | [简体中文](./README.zh-CN.md)
|
|
|
23
23
|
|
|
24
24
|
> Click on the image to see the code snippets. [[Try it]](https://snack.expo.dev/@zhaodonghao586/simple-carousel) 🍺
|
|
25
25
|
|
|
26
|
-
|
|
|
27
|
-
|
|
|
28
|
-
| <a href="./
|
|
29
|
-
|
|
|
30
|
-
| <a href="./
|
|
31
|
-
|
|
|
32
|
-
| <a href="./
|
|
26
|
+
| <img src="assets/normal-horizontal.gif"/> | <img src="assets/normal-vertical.gif"/> | <img src="assets/parallax-horizontal.gif"/> |
|
|
27
|
+
| :------------------------------------------------------------------: | :-------------------------------------------------------------------: | :--------------------------------------------------------------------: |
|
|
28
|
+
| <a href="./exampleExpo/src/normal/index.tsx">normal-horizontal</a> | <a href="./exampleExpo/src/normal/index.tsx">normal-vertical</a> | <a href="./exampleExpo/src/parallax/index.tsx">parallax-horizontal</a> |
|
|
29
|
+
| <img src="assets/parallax-vertical.gif"/> | <img src="assets/stack-horizontal-left.gif"/> | <img src="assets/stack-horizontal-right.gif"/> |
|
|
30
|
+
| <a href="./exampleExpo/src/parallax/index.tsx">parallax-vertical</a> | <a href="./exampleExpo/src/stack/index.tsx">stack-horizontal-left</a> | <a href="./exampleExpo/src/stack/index.tsx">stack-horizontal-right</a> |
|
|
31
|
+
| <img src="assets/stack-vertical-left.gif"/> | <img src="assets/stack-vertical-right.gif"/> | <img src="assets/stack-horizontal-right.gif"/> |
|
|
32
|
+
| <a href="./exampleExpo/src/stack/index.tsx">stack-vertical-left</a> | <a href="./exampleExpo/src/stack/index.tsx">stack-vertical-right</a> | <a href="./exampleExpo/src/stack/index.tsx">stack-horizontal-right</a> |
|
|
33
|
+
| <img src="assets/left-align.gif"/> |
|
|
34
|
+
| <a href="./exampleExpo/src/left-align/index.tsx">left-align</a> |
|
|
35
|
+
|
|
33
36
|
|
|
34
37
|
> Now you can make cool animations with us! Very easy! [[Details]](./docs/custom-animation.md)
|
|
35
38
|
|
|
36
|
-
|
|
|
37
|
-
|
|
|
38
|
-
| <a href="./
|
|
39
|
-
|
|
|
40
|
-
| <a href="./
|
|
41
|
-
|
|
|
42
|
-
| <a href="./
|
|
43
|
-
|
|
|
44
|
-
|
|
|
39
|
+
| <img src="assets/advanced-parallax.gif"/> | <img src="assets/pause-advanced-parallax.gif"/> | <img src="assets/scale-fade-in-out.gif"/> |
|
|
40
|
+
| :-----------------------------------------------------------------------------------------: | :---------------------------------------------------------------------------------------: | :---------------------------------------------------------------------------: |
|
|
41
|
+
| <a href="./exampleExpo/src/advanced-parallax/index.tsx">advanced-parallax</a> | <a href="./exampleExpo/src/pause-advanced-parallax/index.tsx">pause-advanced-parallax</a> | <a href="./exampleExpo/src/scale-fade-in-out/index.tsx">scale-fade-in-out</a> |
|
|
42
|
+
| <img src="assets/rotate-scale-fade-in-out.gif"/> | <img src="assets/rotate-in-out.gif"/> | <img src="assets/anim-tab-bar.gif"/> |
|
|
43
|
+
| <a href="./exampleExpo/src/rotate-scale-fade-in-out/index.tsx">rotate-scale-fade-in-out</a> | <a href="./exampleExpo/src/rotate-in-out/index.tsx">rotate-in-out</a> | <a href="./exampleExpo/src/anim-tab-bar/index.tsx">anim-tab-bar</a> |
|
|
44
|
+
| <img src="assets/marquee.gif"/> | <img src="assets/multiple.gif"/> | <img src="assets/circular.gif"/> |
|
|
45
|
+
| <a href="./exampleExpo/src/marquee/index.tsx">marquee</a> | <a href="./exampleExpo/src/multiple/index.tsx">multiple</a> | <a href="./exampleExpo/src/circular/index.tsx">circular</a> |
|
|
46
|
+
| <img src="assets/fold.gif"/> | <img src="assets/tear.gif"/> | <img src="assets/press-swipe.gif"/> |
|
|
47
|
+
| <a href="./exampleExpo/src/fold/index.tsx">fold</a> | <a href="./exampleExpo/src/tear/index.tsx">tear</a> | <a href="./exampleExpo/src/press-swipe/index.tsx">press-swipe</a> |
|
|
48
|
+
| <img src="assets/cube-3d.gif"/> | <img src="assets/blur-parallax.gif"/> | <img src="assets/curve.gif"/> |
|
|
49
|
+
| <a href="./exampleExpo/src/cube-3d/index.tsx">cube-3d</a> | <a href="./exampleExpo/src/blur-parallax/index.tsx">blur-parallax</a> | <a href="./exampleExpo/src/curve/index.tsx">curve</a> |
|
|
50
|
+
| <img src="assets/parallax-layers.gif"/> | <img src="assets/stack-cards.gif"/> | <img src="assets/flow.gif"/> |
|
|
51
|
+
| <a href="./exampleExpo/src/parallax-layers/index.tsx">parallax-layers</a> | <a href="./exampleExpo/src/stack-cards/index.tsx">stack-cards</a> | <a href="./exampleExpo/src/flow/index.tsx">flow</a> |
|
|
45
52
|
|
|
46
53
|
## Table of contents
|
|
47
54
|
|
|
@@ -68,17 +75,50 @@ npm install react-native-reanimated-carousel
|
|
|
68
75
|
|
|
69
76
|
Now we need to install [`react-native-gesture-handler`](https://github.com/kmagiera/react-native-gesture-handler) and [`react-native-reanimated(>=2.0.0)`](https://github.com/kmagiera/react-native-reanimated).
|
|
70
77
|
|
|
78
|
+
| | react-native-reanimated | react-native-gesture-handler |
|
|
79
|
+
| -------------------------------------- | ----------------------- | ---------------------------- |
|
|
80
|
+
| react-native-reanimated-carousel < v3 | <2.7.0 | \* |
|
|
81
|
+
| react-native-reanimated-carousel >= v3 | >=2.7.0 | \* |
|
|
82
|
+
|
|
71
83
|
## Usage
|
|
72
84
|
|
|
73
85
|
```tsx
|
|
86
|
+
import * as React from 'react';
|
|
87
|
+
import { Dimensions, Text, View } from 'react-native';
|
|
74
88
|
import Carousel from 'react-native-reanimated-carousel';
|
|
75
89
|
|
|
76
|
-
|
|
77
|
-
width=
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
90
|
+
function Index() {
|
|
91
|
+
const width = Dimensions.get('window').width;
|
|
92
|
+
return (
|
|
93
|
+
<View style={{ flex: 1 }}>
|
|
94
|
+
<Carousel
|
|
95
|
+
loop
|
|
96
|
+
width={width}
|
|
97
|
+
height={width / 2}
|
|
98
|
+
autoPlay={true}
|
|
99
|
+
data={[...new Array(6).keys()]}
|
|
100
|
+
scrollAnimationDuration={1000}
|
|
101
|
+
onSnapToItem={(index) => console.log('current index:', index)}
|
|
102
|
+
renderItem={({ index }) => (
|
|
103
|
+
<View
|
|
104
|
+
style={{
|
|
105
|
+
flex: 1,
|
|
106
|
+
borderWidth: 1,
|
|
107
|
+
justifyContent: 'center',
|
|
108
|
+
}}
|
|
109
|
+
>
|
|
110
|
+
<Text style={{ textAlign: 'center', fontSize: 30 }}>
|
|
111
|
+
{index}
|
|
112
|
+
</Text>
|
|
113
|
+
</View>
|
|
114
|
+
)}
|
|
115
|
+
/>
|
|
116
|
+
</View>
|
|
117
|
+
);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
export default Index;
|
|
121
|
+
|
|
82
122
|
```
|
|
83
123
|
|
|
84
124
|
## Tips
|
|
@@ -104,6 +144,8 @@ import Carousel from 'react-native-reanimated-carousel';
|
|
|
104
144
|
- 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.
|
|
105
145
|
- EXPO
|
|
106
146
|
- If use EXPO managed workflow please ensure that the version is greater than 41.Because the old version not support `Reanimated(v2)`.
|
|
147
|
+
- Working principle
|
|
148
|
+
- [About RNRC](./docs/about.md)
|
|
107
149
|
|
|
108
150
|
## Reason
|
|
109
151
|
|
|
@@ -142,7 +184,7 @@ yarn web:pretty
|
|
|
142
184
|
## Sponsors
|
|
143
185
|
|
|
144
186
|
<p align="center">
|
|
145
|
-
<img src='
|
|
187
|
+
<img src='https://github.com/dohooo/sponsors/blob/master/sponsors.png?raw=true'/>
|
|
146
188
|
</p>
|
|
147
189
|
|
|
148
190
|
## License
|
package/README.zh-CN.md
CHANGED
|
@@ -23,25 +23,31 @@
|
|
|
23
23
|
|
|
24
24
|
> 点击图片,查看代码 [[试一下]](https://snack.expo.dev/@zhaodonghao586/simple-carousel) 🍺
|
|
25
25
|
|
|
26
|
-
|
|
|
27
|
-
|
|
|
28
|
-
| <a href="./
|
|
29
|
-
|
|
|
30
|
-
| <a href="./
|
|
31
|
-
|
|
|
32
|
-
| <a href="./
|
|
26
|
+
| <img src="assets/normal-horizontal.gif"/> | <img src="assets/normal-vertical.gif"/> | <img src="assets/parallax-horizontal.gif"/> |
|
|
27
|
+
| :------------------------------------------------------------------: | :-------------------------------------------------------------------: | :--------------------------------------------------------------------: |
|
|
28
|
+
| <a href="./exampleExpo/src/normal/index.tsx">normal-horizontal</a> | <a href="./exampleExpo/src/normal/index.tsx">normal-vertical</a> | <a href="./exampleExpo/src/parallax/index.tsx">parallax-horizontal</a> |
|
|
29
|
+
| <img src="assets/parallax-vertical.gif"/> | <img src="assets/stack-horizontal-left.gif"/> | <img src="assets/stack-horizontal-right.gif"/> |
|
|
30
|
+
| <a href="./exampleExpo/src/parallax/index.tsx">parallax-vertical</a> | <a href="./exampleExpo/src/stack/index.tsx">stack-horizontal-left</a> | <a href="./exampleExpo/src/stack/index.tsx">stack-horizontal-right</a> |
|
|
31
|
+
| <img src="assets/stack-vertical-left.gif"/> | <img src="assets/stack-vertical-right.gif"/> | <img src="assets/stack-horizontal-right.gif"/> |
|
|
32
|
+
| <a href="./exampleExpo/src/stack/index.tsx">stack-vertical-left</a> | <a href="./exampleExpo/src/stack/index.tsx">stack-vertical-right</a> | <a href="./exampleExpo/src/stack/index.tsx">stack-horizontal-right</a> |
|
|
33
|
+
| <img src="assets/left-align.gif"/> |
|
|
34
|
+
| <a href="./exampleExpo/src/left-align/index.tsx">left-align</a> |
|
|
33
35
|
|
|
34
36
|
> 现在你可以和我们一起来制作酷炫的动画了! 非常简单! [[详情]](./docs/custom-animation.zh-CN.md)
|
|
35
37
|
|
|
36
|
-
|
|
|
37
|
-
|
|
|
38
|
-
| <a href="./
|
|
39
|
-
|
|
|
40
|
-
| <a href="./
|
|
41
|
-
|
|
|
42
|
-
| <a href="./
|
|
43
|
-
|
|
|
44
|
-
|
|
|
38
|
+
| <img src="assets/advanced-parallax.gif"/> | <img src="assets/pause-advanced-parallax.gif"/> | <img src="assets/scale-fade-in-out.gif"/> |
|
|
39
|
+
| :-----------------------------------------------------------------------------------------: | :---------------------------------------------------------------------------------------: | :---------------------------------------------------------------------------: |
|
|
40
|
+
| <a href="./exampleExpo/src/advanced-parallax/index.tsx">advanced-parallax</a> | <a href="./exampleExpo/src/pause-advanced-parallax/index.tsx">pause-advanced-parallax</a> | <a href="./exampleExpo/src/scale-fade-in-out/index.tsx">scale-fade-in-out</a> |
|
|
41
|
+
| <img src="assets/rotate-scale-fade-in-out.gif"/> | <img src="assets/rotate-in-out.gif"/> | <img src="assets/anim-tab-bar.gif"/> |
|
|
42
|
+
| <a href="./exampleExpo/src/rotate-scale-fade-in-out/index.tsx">rotate-scale-fade-in-out</a> | <a href="./exampleExpo/src/rotate-in-out/index.tsx">rotate-in-out</a> | <a href="./exampleExpo/src/anim-tab-bar/index.tsx">anim-tab-bar</a> |
|
|
43
|
+
| <img src="assets/marquee.gif"/> | <img src="assets/multiple.gif"/> | <img src="assets/circular.gif"/> |
|
|
44
|
+
| <a href="./exampleExpo/src/marquee/index.tsx">marquee</a> | <a href="./exampleExpo/src/multiple/index.tsx">multiple</a> | <a href="./exampleExpo/src/circular/index.tsx">circular</a> |
|
|
45
|
+
| <img src="assets/fold.gif"/> | <img src="assets/tear.gif"/> | <img src="assets/press-swipe.gif"/> |
|
|
46
|
+
| <a href="./exampleExpo/src/fold/index.tsx">fold</a> | <a href="./exampleExpo/src/tear/index.tsx">tear</a> | <a href="./exampleExpo/src/press-swipe/index.tsx">press-swipe</a> |
|
|
47
|
+
| <img src="assets/cube-3d.gif"/> | <img src="assets/blur-parallax.gif"/> | <img src="assets/curve.gif"/> |
|
|
48
|
+
| <a href="./exampleExpo/src/cube-3d/index.tsx">cube-3d</a> | <a href="./exampleExpo/src/blur-parallax/index.tsx">blur-parallax</a> | <a href="./exampleExpo/src/curve/index.tsx">curve</a> |
|
|
49
|
+
| <img src="assets/parallax-layers.gif"/> | <img src="assets/stack-cards.gif"/> | <img src="assets/flow.gif"/> |
|
|
50
|
+
| <a href="./exampleExpo/src/parallax-layers/index.tsx">parallax-layers</a> | <a href="./exampleExpo/src/stack-cards/index.tsx">stack-cards</a> | <a href="./exampleExpo/src/flow/index.tsx">flow</a> |
|
|
45
51
|
|
|
46
52
|
## 目录
|
|
47
53
|
|
|
@@ -69,18 +75,49 @@ npm install react-native-reanimated-carousel
|
|
|
69
75
|
```
|
|
70
76
|
|
|
71
77
|
并且我们需要安装 [`react-native-gesture-handler`](https://github.com/kmagiera/react-native-gesture-handler) 、[`react-native-reanimated(>=2.0.0)`](https://github.com/kmagiera/react-native-reanimated),安装步骤可参考各自文档。
|
|
78
|
+
| | react-native-reanimated | react-native-gesture-handler |
|
|
79
|
+
| -------------------------------------- | ----------------------- | ---------------------------- |
|
|
80
|
+
| react-native-reanimated-carousel < v3 | <2.7.0 | \* |
|
|
81
|
+
| react-native-reanimated-carousel >= v3 | >=2.7.0 | \* |
|
|
72
82
|
|
|
73
83
|
## 使用
|
|
74
84
|
|
|
75
85
|
```tsx
|
|
86
|
+
import * as React from 'react';
|
|
87
|
+
import { Dimensions, Text, View } from 'react-native';
|
|
76
88
|
import Carousel from 'react-native-reanimated-carousel';
|
|
77
89
|
|
|
78
|
-
|
|
79
|
-
width=
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
90
|
+
function Index() {
|
|
91
|
+
const width = Dimensions.get('window').width;
|
|
92
|
+
return (
|
|
93
|
+
<View style={{ flex: 1 }}>
|
|
94
|
+
<Carousel
|
|
95
|
+
loop
|
|
96
|
+
width={width}
|
|
97
|
+
height={width / 2}
|
|
98
|
+
autoPlay={true}
|
|
99
|
+
data={[...new Array(6).keys()]}
|
|
100
|
+
scrollAnimationDuration={1000}
|
|
101
|
+
onSnapToItem={(index) => console.log('current index:', index)}
|
|
102
|
+
renderItem={({ index }) => (
|
|
103
|
+
<View
|
|
104
|
+
style={{
|
|
105
|
+
flex: 1,
|
|
106
|
+
borderWidth: 1,
|
|
107
|
+
justifyContent: 'center',
|
|
108
|
+
}}
|
|
109
|
+
>
|
|
110
|
+
<Text style={{ textAlign: 'center', fontSize: 30 }}>
|
|
111
|
+
{index}
|
|
112
|
+
</Text>
|
|
113
|
+
</View>
|
|
114
|
+
)}
|
|
115
|
+
/>
|
|
116
|
+
</View>
|
|
117
|
+
);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
export default Index;
|
|
84
121
|
```
|
|
85
122
|
|
|
86
123
|
## 提示
|
|
@@ -104,6 +141,8 @@ import Carousel from 'react-native-reanimated-carousel';
|
|
|
104
141
|
- 所有 layout 均完美支持 RTL 模式,并且无需再做任何配置。但在 RTL 模式下使用自动播放时,默认不会自动转换方向,需要结合 autoPlayReverse 来手动控制方向。
|
|
105
142
|
- EXPO
|
|
106
143
|
- 如果你使用 EXPO 托管工作流,请确定你的 EXPO SDK 版本大于 41,因为旧的版本并不支持`Reanimated(v2)`。
|
|
144
|
+
- 工作原理
|
|
145
|
+
- [关于RNRC](./docs/about.zh-CN.md)
|
|
107
146
|
|
|
108
147
|
## 原因
|
|
109
148
|
|
|
@@ -142,7 +181,7 @@ yarn web:pretty
|
|
|
142
181
|
## 赞助商
|
|
143
182
|
|
|
144
183
|
<p align="center">
|
|
145
|
-
<img src='
|
|
184
|
+
<img src='https://github.com/dohooo/sponsors/blob/master/sponsors.png?raw=true'/>
|
|
146
185
|
</p>
|
|
147
186
|
|
|
148
187
|
## 许可
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports,"__esModule",{value:true});exports.ScrollViewGesture=void 0;var _extends2=_interopRequireDefault(require("@babel/runtime/helpers/extends"));var _react=_interopRequireDefault(require("react"));var _reactNative=require("react-native");var _reactNativeGestureHandler=require("react-native-gesture-handler");var _reactNativeReanimated=_interopRequireWildcard(require("react-native-reanimated"));var _constants=require("./constants");var _store=require("./store");var _dealWithAnimation=require("./utils/dealWithAnimation");var _this=this,_jsxFileName="/Users/zhaodonghao/code/github/react-native-reanimated-carousel/src/ScrollViewGesture.tsx";function _getRequireWildcardCache(nodeInterop){if(typeof WeakMap!=="function")return null;var cacheBabelInterop=new WeakMap();var cacheNodeInterop=new WeakMap();return(_getRequireWildcardCache=function _getRequireWildcardCache(nodeInterop){return nodeInterop?cacheNodeInterop:cacheBabelInterop;})(nodeInterop);}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;}var IScrollViewGesture=function IScrollViewGesture(props){var _React$useContext=_react.default.useContext(_store.CTX),_React$useContext$pro=_React$useContext.props,vertical=_React$useContext$pro.vertical,data=_React$useContext$pro.data,pagingEnabled=_React$useContext$pro.pagingEnabled,snapEnabled=_React$useContext$pro.snapEnabled,panGestureHandlerProps=_React$useContext$pro.panGestureHandlerProps,infinite=_React$useContext$pro.loop,scrollAnimationDuration=_React$useContext$pro.scrollAnimationDuration,withAnimation=_React$useContext$pro.withAnimation,enabled=_React$useContext$pro.enabled;var translation=props.translation,size=props.size,onScrollBegin=props.onScrollBegin,onScrollEnd=props.onScrollEnd,onTouchBegin=props.onTouchBegin,onTouchEnd=props.onTouchEnd;var maxPage=data.length;var isHorizontal=(0,_reactNativeReanimated.useDerivedValue)(function(){var _f=function _f(){return!vertical;};_f._closure={vertical:vertical};_f.asString="function _f(){const{vertical}=jsThis._closure;{return!vertical;}}";_f.__workletHash=14495821007639;_f.__location="/Users/zhaodonghao/code/github/react-native-reanimated-carousel/src/ScrollViewGesture.tsx (63:41)";return _f;}(),[vertical]);var touching=(0,_reactNativeReanimated.useSharedValue)(false);var scrollEndTranslation=(0,_reactNativeReanimated.useSharedValue)(0);var scrollEndVelocity=(0,_reactNativeReanimated.useSharedValue)(0);var _withSpring=_react.default.useCallback(function(){var _f=function _f(toValue,onFinished){var defaultWithAnimation={type:'timing',config:{duration:scrollAnimationDuration+100,easing:_constants.Easing.easeOutQuart}};return(0,_dealWithAnimation.dealWithAnimation)(withAnimation!=null?withAnimation:defaultWithAnimation)(toValue,function(){var _f=function _f(isFinished){if(isFinished){onFinished&&(0,_reactNativeReanimated.runOnJS)(onFinished)();}};_f._closure={onFinished:onFinished,runOnJS:_reactNativeReanimated.runOnJS};_f.asString="function _f(isFinished){const{onFinished,runOnJS}=jsThis._closure;{if(isFinished){onFinished&&runOnJS(onFinished)();}}}";_f.__workletHash=9122154549195;_f.__location="/Users/zhaodonghao/code/github/react-native-reanimated-carousel/src/ScrollViewGesture.tsx (81:16)";return _f;}());};_f._closure={scrollAnimationDuration:scrollAnimationDuration,Easing:{easeOutQuart:_constants.Easing.easeOutQuart},dealWithAnimation:_dealWithAnimation.dealWithAnimation,withAnimation:withAnimation,runOnJS:_reactNativeReanimated.runOnJS};_f.asString="function _f(toValue,onFinished){const{scrollAnimationDuration,Easing,dealWithAnimation,withAnimation,runOnJS}=jsThis._closure;{var _withAnimation;const defaultWithAnimation={type:'timing',config:{duration:scrollAnimationDuration+100,easing:Easing.easeOutQuart}};return dealWithAnimation((_withAnimation=withAnimation)!==null&&_withAnimation!==void 0?_withAnimation:defaultWithAnimation)(toValue,function(isFinished){'worklet';if(isFinished){onFinished&&runOnJS(onFinished)();}});}}";_f.__workletHash=16303945491727;_f.__location="/Users/zhaodonghao/code/github/react-native-reanimated-carousel/src/ScrollViewGesture.tsx (69:8)";return _f;}(),[scrollAnimationDuration,withAnimation]);var endWithSpring=_react.default.useCallback(function(){var _f=function _f(onFinished){var origin=translation.value;var velocity=scrollEndVelocity.value;if(!pagingEnabled){if(snapEnabled){var nextPage=Math.round((origin+velocity*0.4)/size)*size;translation.value=_withSpring(nextPage,onFinished);return;}translation.value=(0,_reactNativeReanimated.withDecay)({velocity:velocity,deceleration:0.999});return;}var page=Math.round(-translation.value/size);var velocityPage=Math.round(-(translation.value+scrollEndVelocity.value)/size);var finalPage=Math.min(page+1,Math.max(page-1,velocityPage));if(!infinite){finalPage=Math.min(maxPage-1,Math.max(0,finalPage));}translation.value=_withSpring(-finalPage*size,onFinished);};_f._closure={translation:translation,scrollEndVelocity:scrollEndVelocity,pagingEnabled:pagingEnabled,snapEnabled:snapEnabled,size:size,_withSpring:_withSpring,withDecay:_reactNativeReanimated.withDecay,infinite:infinite,maxPage:maxPage};_f.asString="function _f(onFinished){const{translation,scrollEndVelocity,pagingEnabled,snapEnabled,size,_withSpring,withDecay,infinite,maxPage}=jsThis._closure;{const origin=translation.value;const velocity=scrollEndVelocity.value;if(!pagingEnabled){if(snapEnabled){const nextPage=Math.round((origin+velocity*0.4)/size)*size;translation.value=_withSpring(nextPage,onFinished);return;}translation.value=withDecay({velocity:velocity,deceleration:0.999});return;}const page=Math.round(-translation.value/size);const velocityPage=Math.round(-(translation.value+scrollEndVelocity.value)/size);let finalPage=Math.min(page+1,Math.max(page-1,velocityPage));if(!infinite){finalPage=Math.min(maxPage-1,Math.max(0,finalPage));}translation.value=_withSpring(-finalPage*size,onFinished);}}";_f.__workletHash=6617882707805;_f.__location="/Users/zhaodonghao/code/github/react-native-reanimated-carousel/src/ScrollViewGesture.tsx (93:8)";return _f;}(),[infinite,_withSpring,translation,scrollEndVelocity,size,maxPage,pagingEnabled,snapEnabled]);var onFinish=_react.default.useCallback(function(){var _f=function _f(isFinished){if(isFinished){touching.value=false;onScrollEnd&&(0,_reactNativeReanimated.runOnJS)(onScrollEnd)();}};_f._closure={touching:touching,onScrollEnd:onScrollEnd,runOnJS:_reactNativeReanimated.runOnJS};_f.asString="function _f(isFinished){const{touching,onScrollEnd,runOnJS}=jsThis._closure;{if(isFinished){touching.value=false;onScrollEnd&&runOnJS(onScrollEnd)();}}}";_f.__workletHash=12308424749737;_f.__location="/Users/zhaodonghao/code/github/react-native-reanimated-carousel/src/ScrollViewGesture.tsx (137:8)";return _f;}(),[onScrollEnd,touching]);var activeDecay=_react.default.useCallback(function(){var _f=function _f(){touching.value=true;translation.value=(0,_reactNativeReanimated.withDecay)({velocity:scrollEndVelocity.value},function(){var _f=function _f(isFinished){return onFinish(isFinished);};_f._closure={onFinish:onFinish};_f.asString="function _f(isFinished){const{onFinish}=jsThis._closure;{return onFinish(isFinished);}}";_f.__workletHash=12004837605207;_f.__location="/Users/zhaodonghao/code/github/react-native-reanimated-carousel/src/ScrollViewGesture.tsx (152:12)";return _f;}());};_f._closure={touching:touching,translation:translation,withDecay:_reactNativeReanimated.withDecay,scrollEndVelocity:scrollEndVelocity,onFinish:onFinish};_f.asString="function _f(){const{touching,translation,withDecay,scrollEndVelocity,onFinish}=jsThis._closure;{touching.value=true;translation.value=withDecay({velocity:scrollEndVelocity.value},function(isFinished){return onFinish(isFinished);});}}";_f.__workletHash=1701548878343;_f.__location="/Users/zhaodonghao/code/github/react-native-reanimated-carousel/src/ScrollViewGesture.tsx (147:42)";return _f;}(),[onFinish,scrollEndVelocity.value,touching,translation]);var resetBoundary=_react.default.useCallback(function(){var _f=function _f(){if(touching.value){return;}if(translation.value>0){if(scrollEndTranslation.value<0){activeDecay();return;}if(!infinite){translation.value=_withSpring(0);return;}}if(translation.value<-((maxPage-1)*size)){if(scrollEndTranslation.value>0){activeDecay();return;}if(!infinite){translation.value=_withSpring(-((maxPage-1)*size));return;}}};_f._closure={touching:touching,translation:translation,scrollEndTranslation:scrollEndTranslation,activeDecay:activeDecay,infinite:infinite,_withSpring:_withSpring,maxPage:maxPage,size:size};_f.asString="function _f(){const{touching,translation,scrollEndTranslation,activeDecay,infinite,_withSpring,maxPage,size}=jsThis._closure;{if(touching.value){return;}if(translation.value>0){if(scrollEndTranslation.value<0){activeDecay();return;}if(!infinite){translation.value=_withSpring(0);return;}}if(translation.value<-((maxPage-1)*size)){if(scrollEndTranslation.value>0){activeDecay();return;}if(!infinite){translation.value=_withSpring(-((maxPage-1)*size));return;}}}}";_f.__workletHash=3458376770899;_f.__location="/Users/zhaodonghao/code/github/react-native-reanimated-carousel/src/ScrollViewGesture.tsx (156:44)";return _f;}(),[touching.value,translation,maxPage,size,scrollEndTranslation.value,infinite,activeDecay,_withSpring]);(0,_reactNativeReanimated.useAnimatedReaction)(function(){var _f=function _f(){return translation.value;};_f._closure={translation:translation};_f.asString="function _f(){const{translation}=jsThis._closure;{return translation.value;}}";_f.__workletHash=9829368032147;_f.__location="/Users/zhaodonghao/code/github/react-native-reanimated-carousel/src/ScrollViewGesture.tsx (195:8)";return _f;}(),function(){var _f=function _f(){if(!pagingEnabled){resetBoundary();}};_f._closure={pagingEnabled:pagingEnabled,resetBoundary:resetBoundary};_f.asString="function _f(){const{pagingEnabled,resetBoundary}=jsThis._closure;{if(!pagingEnabled){resetBoundary();}}}";_f.__workletHash=10686939088248;_f.__location="/Users/zhaodonghao/code/github/react-native-reanimated-carousel/src/ScrollViewGesture.tsx (196:8)";return _f;}(),[pagingEnabled,resetBoundary]);var panGestureEventHandler=(0,_reactNativeReanimated.useAnimatedGestureHandler)({onStart:function(){var _f=function _f(_,ctx){touching.value=true;ctx.validStart=true;onScrollBegin&&(0,_reactNativeReanimated.runOnJS)(onScrollBegin)();ctx.max=(maxPage-1)*size;ctx.panOffset=translation.value;};_f._closure={touching:touching,onScrollBegin:onScrollBegin,runOnJS:_reactNativeReanimated.runOnJS,maxPage:maxPage,size:size,translation:translation};_f.asString="function _f(_,ctx){const{touching,onScrollBegin,runOnJS,maxPage,size,translation}=jsThis._closure;{touching.value=true;ctx.validStart=true;onScrollBegin&&runOnJS(onScrollBegin)();ctx.max=(maxPage-1)*size;ctx.panOffset=translation.value;}}";_f.__workletHash=1789833551681;_f.__location="/Users/zhaodonghao/code/github/react-native-reanimated-carousel/src/ScrollViewGesture.tsx (209:21)";return _f;}(),onActive:function(){var _f=function _f(e,ctx){if(ctx.validStart){ctx.validStart=false;(0,_reactNativeReanimated.cancelAnimation)(translation);}touching.value=true;var translationX=e.translationX,translationY=e.translationY;var panTranslation=isHorizontal.value?translationX:translationY;if(!infinite&&(translation.value>0||translation.value<-ctx.max)){var boundary=translation.value>0?0:-ctx.max;var fixed=boundary-ctx.panOffset;var dynamic=panTranslation-fixed;translation.value=boundary+dynamic*0.5;return;}translation.value=ctx.panOffset+panTranslation;};_f._closure={cancelAnimation:_reactNativeReanimated.cancelAnimation,translation:translation,touching:touching,isHorizontal:isHorizontal,infinite:infinite};_f.asString="function _f(e,ctx){const{cancelAnimation,translation,touching,isHorizontal,infinite}=jsThis._closure;{if(ctx.validStart){ctx.validStart=false;cancelAnimation(translation);}touching.value=true;const{translationX:translationX,translationY:translationY}=e;let panTranslation=isHorizontal.value?translationX:translationY;if(!infinite&&(translation.value>0||translation.value<-ctx.max)){const boundary=translation.value>0?0:-ctx.max;const fixed=boundary-ctx.panOffset;const dynamic=panTranslation-fixed;translation.value=boundary+dynamic*0.5;return;}translation.value=ctx.panOffset+panTranslation;}}";_f.__workletHash=10275621069851;_f.__location="/Users/zhaodonghao/code/github/react-native-reanimated-carousel/src/ScrollViewGesture.tsx (216:22)";return _f;}(),onEnd:function(){var _f=function _f(e){var velocityX=e.velocityX,velocityY=e.velocityY,translationX=e.translationX,translationY=e.translationY;scrollEndVelocity.value=isHorizontal.value?velocityX:velocityY;scrollEndTranslation.value=isHorizontal.value?translationX:translationY;endWithSpring(onScrollEnd);if(!infinite){touching.value=false;}};_f._closure={scrollEndVelocity:scrollEndVelocity,isHorizontal:isHorizontal,scrollEndTranslation:scrollEndTranslation,endWithSpring:endWithSpring,onScrollEnd:onScrollEnd,infinite:infinite,touching:touching};_f.asString="function _f(e){const{scrollEndVelocity,isHorizontal,scrollEndTranslation,endWithSpring,onScrollEnd,infinite,touching}=jsThis._closure;{const{velocityX:velocityX,velocityY:velocityY,translationX:translationX,translationY:translationY}=e;scrollEndVelocity.value=isHorizontal.value?velocityX:velocityY;scrollEndTranslation.value=isHorizontal.value?translationX:translationY;endWithSpring(onScrollEnd);if(!infinite){touching.value=false;}}}";_f.__workletHash=8095479445863;_f.__location="/Users/zhaodonghao/code/github/react-native-reanimated-carousel/src/ScrollViewGesture.tsx (240:19)";return _f;}()},[pagingEnabled,isHorizontal.value,infinite,maxPage,size,snapEnabled,onScrollBegin,onScrollEnd]);var directionStyle=_react.default.useMemo(function(){return vertical?styles.contentHorizontal:styles.contentVertical;},[vertical]);return _react.default.createElement(_reactNativeReanimated.default.View,{style:[styles.container,directionStyle,{width:'100%',height:'100%'}],onTouchStart:onTouchBegin,onTouchEnd:onTouchEnd,__self:_this,__source:{fileName:_jsxFileName,lineNumber:273,columnNumber:9}},_react.default.createElement(_reactNativeGestureHandler.PanGestureHandler,(0,_extends2.default)({},panGestureHandlerProps,{enabled:enabled,onGestureEvent:panGestureEventHandler,__self:_this,__source:{fileName:_jsxFileName,lineNumber:282,columnNumber:13}}),props.children));};var ScrollViewGesture=IScrollViewGesture;exports.ScrollViewGesture=ScrollViewGesture;var styles=_reactNative.StyleSheet.create({container:{flex:1,overflow:'hidden'},contentVertical:{flexDirection:'column'},contentHorizontal:{flexDirection:'row'}});
|
|
1
|
+
var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports,"__esModule",{value:true});exports.ScrollViewGesture=void 0;var _extends2=_interopRequireDefault(require("@babel/runtime/helpers/extends"));var _react=_interopRequireDefault(require("react"));var _reactNative=require("react-native");var _reactNativeGestureHandler=require("react-native-gesture-handler");var _reactNativeReanimated=_interopRequireWildcard(require("react-native-reanimated"));var _constants=require("./constants");var _store=require("./store");var _dealWithAnimation=require("./utils/dealWithAnimation");var _this=this,_jsxFileName="/Users/zhaodonghao/code/github/react-native-reanimated-carousel/src/ScrollViewGesture.tsx";function _getRequireWildcardCache(nodeInterop){if(typeof WeakMap!=="function")return null;var cacheBabelInterop=new WeakMap();var cacheNodeInterop=new WeakMap();return(_getRequireWildcardCache=function _getRequireWildcardCache(nodeInterop){return nodeInterop?cacheNodeInterop:cacheBabelInterop;})(nodeInterop);}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;}var IScrollViewGesture=function IScrollViewGesture(props){var _React$useContext=_react.default.useContext(_store.CTX),_React$useContext$pro=_React$useContext.props,vertical=_React$useContext$pro.vertical,data=_React$useContext$pro.data,pagingEnabled=_React$useContext$pro.pagingEnabled,snapEnabled=_React$useContext$pro.snapEnabled,panGestureHandlerProps=_React$useContext$pro.panGestureHandlerProps,infinite=_React$useContext$pro.loop,scrollAnimationDuration=_React$useContext$pro.scrollAnimationDuration,withAnimation=_React$useContext$pro.withAnimation,enabled=_React$useContext$pro.enabled;var translation=props.translation,size=props.size,onScrollBegin=props.onScrollBegin,onScrollEnd=props.onScrollEnd,onTouchBegin=props.onTouchBegin,onTouchEnd=props.onTouchEnd;var maxPage=data.length;var isHorizontal=(0,_reactNativeReanimated.useDerivedValue)(function(){var _f=function _f(){return!vertical;};_f._closure={vertical:vertical};_f.asString="function _f(){const{vertical}=jsThis._closure;{return!vertical;}}";_f.__workletHash=14495821007639;_f.__location="/Users/zhaodonghao/code/github/react-native-reanimated-carousel/src/ScrollViewGesture.tsx (63:41)";return _f;}(),[vertical]);var touching=(0,_reactNativeReanimated.useSharedValue)(false);var scrollEndTranslation=(0,_reactNativeReanimated.useSharedValue)(0);var scrollEndVelocity=(0,_reactNativeReanimated.useSharedValue)(0);var _withSpring=_react.default.useCallback(function(){var _f=function _f(toValue,onFinished){var defaultWithAnimation={type:'timing',config:{duration:scrollAnimationDuration+100,easing:_constants.Easing.easeOutQuart}};return(0,_dealWithAnimation.dealWithAnimation)(withAnimation!=null?withAnimation:defaultWithAnimation)(toValue,function(){var _f=function _f(isFinished){if(isFinished){onFinished&&(0,_reactNativeReanimated.runOnJS)(onFinished)();}};_f._closure={onFinished:onFinished,runOnJS:_reactNativeReanimated.runOnJS};_f.asString="function _f(isFinished){const{onFinished,runOnJS}=jsThis._closure;{if(isFinished){onFinished&&runOnJS(onFinished)();}}}";_f.__workletHash=9122154549195;_f.__location="/Users/zhaodonghao/code/github/react-native-reanimated-carousel/src/ScrollViewGesture.tsx (81:16)";return _f;}());};_f._closure={scrollAnimationDuration:scrollAnimationDuration,Easing:{easeOutQuart:_constants.Easing.easeOutQuart},dealWithAnimation:_dealWithAnimation.dealWithAnimation,withAnimation:withAnimation,runOnJS:_reactNativeReanimated.runOnJS};_f.asString="function _f(toValue,onFinished){const{scrollAnimationDuration,Easing,dealWithAnimation,withAnimation,runOnJS}=jsThis._closure;{var _withAnimation;const defaultWithAnimation={type:'timing',config:{duration:scrollAnimationDuration+100,easing:Easing.easeOutQuart}};return dealWithAnimation((_withAnimation=withAnimation)!==null&&_withAnimation!==void 0?_withAnimation:defaultWithAnimation)(toValue,function(isFinished){'worklet';if(isFinished){onFinished&&runOnJS(onFinished)();}});}}";_f.__workletHash=16303945491727;_f.__location="/Users/zhaodonghao/code/github/react-native-reanimated-carousel/src/ScrollViewGesture.tsx (69:8)";return _f;}(),[scrollAnimationDuration,withAnimation]);var endWithSpring=_react.default.useCallback(function(){var _f=function _f(onFinished){var origin=translation.value;var velocity=scrollEndVelocity.value;if(!pagingEnabled){if(snapEnabled){var nextPage=Math.round((origin+velocity*0.4)/size)*size;translation.value=_withSpring(nextPage,onFinished);return;}translation.value=(0,_reactNativeReanimated.withDecay)({velocity:velocity,deceleration:0.999});return;}var direction=-(scrollEndTranslation.value>=0?1:-1);var computed=direction<0?Math.ceil:Math.floor;var page=computed(-translation.value/size);var finalPage=page+direction;if(!infinite){finalPage=Math.min(maxPage-1,Math.max(0,finalPage));}translation.value=_withSpring(-finalPage*size,onFinished);};_f._closure={translation:translation,scrollEndVelocity:scrollEndVelocity,pagingEnabled:pagingEnabled,snapEnabled:snapEnabled,size:size,_withSpring:_withSpring,withDecay:_reactNativeReanimated.withDecay,scrollEndTranslation:scrollEndTranslation,infinite:infinite,maxPage:maxPage};_f.asString="function _f(onFinished){const{translation,scrollEndVelocity,pagingEnabled,snapEnabled,size,_withSpring,withDecay,scrollEndTranslation,infinite,maxPage}=jsThis._closure;{const origin=translation.value;const velocity=scrollEndVelocity.value;if(!pagingEnabled){if(snapEnabled){const nextPage=Math.round((origin+velocity*0.4)/size)*size;translation.value=_withSpring(nextPage,onFinished);return;}translation.value=withDecay({velocity:velocity,deceleration:0.999});return;}const direction=-(scrollEndTranslation.value>=0?1:-1);const computed=direction<0?Math.ceil:Math.floor;const page=computed(-translation.value/size);let finalPage=page+direction;if(!infinite){finalPage=Math.min(maxPage-1,Math.max(0,finalPage));}translation.value=_withSpring(-finalPage*size,onFinished);}}";_f.__workletHash=7553383763877;_f.__location="/Users/zhaodonghao/code/github/react-native-reanimated-carousel/src/ScrollViewGesture.tsx (93:8)";return _f;}(),[translation,scrollEndVelocity.value,pagingEnabled,size,scrollEndTranslation.value,infinite,_withSpring,snapEnabled,maxPage]);var onFinish=_react.default.useCallback(function(){var _f=function _f(isFinished){if(isFinished){touching.value=false;onScrollEnd&&(0,_reactNativeReanimated.runOnJS)(onScrollEnd)();}};_f._closure={touching:touching,onScrollEnd:onScrollEnd,runOnJS:_reactNativeReanimated.runOnJS};_f.asString="function _f(isFinished){const{touching,onScrollEnd,runOnJS}=jsThis._closure;{if(isFinished){touching.value=false;onScrollEnd&&runOnJS(onScrollEnd)();}}}";_f.__workletHash=12308424749737;_f.__location="/Users/zhaodonghao/code/github/react-native-reanimated-carousel/src/ScrollViewGesture.tsx (141:8)";return _f;}(),[onScrollEnd,touching]);var activeDecay=_react.default.useCallback(function(){var _f=function _f(){touching.value=true;translation.value=(0,_reactNativeReanimated.withDecay)({velocity:scrollEndVelocity.value},function(){var _f=function _f(isFinished){return onFinish(isFinished);};_f._closure={onFinish:onFinish};_f.asString="function _f(isFinished){const{onFinish}=jsThis._closure;{return onFinish(isFinished);}}";_f.__workletHash=12004837605207;_f.__location="/Users/zhaodonghao/code/github/react-native-reanimated-carousel/src/ScrollViewGesture.tsx (156:12)";return _f;}());};_f._closure={touching:touching,translation:translation,withDecay:_reactNativeReanimated.withDecay,scrollEndVelocity:scrollEndVelocity,onFinish:onFinish};_f.asString="function _f(){const{touching,translation,withDecay,scrollEndVelocity,onFinish}=jsThis._closure;{touching.value=true;translation.value=withDecay({velocity:scrollEndVelocity.value},function(isFinished){return onFinish(isFinished);});}}";_f.__workletHash=1701548878343;_f.__location="/Users/zhaodonghao/code/github/react-native-reanimated-carousel/src/ScrollViewGesture.tsx (151:42)";return _f;}(),[onFinish,scrollEndVelocity.value,touching,translation]);var resetBoundary=_react.default.useCallback(function(){var _f=function _f(){if(touching.value){return;}if(translation.value>0){if(scrollEndTranslation.value<0){activeDecay();return;}if(!infinite){translation.value=_withSpring(0);return;}}if(translation.value<-((maxPage-1)*size)){if(scrollEndTranslation.value>0){activeDecay();return;}if(!infinite){translation.value=_withSpring(-((maxPage-1)*size));return;}}};_f._closure={touching:touching,translation:translation,scrollEndTranslation:scrollEndTranslation,activeDecay:activeDecay,infinite:infinite,_withSpring:_withSpring,maxPage:maxPage,size:size};_f.asString="function _f(){const{touching,translation,scrollEndTranslation,activeDecay,infinite,_withSpring,maxPage,size}=jsThis._closure;{if(touching.value){return;}if(translation.value>0){if(scrollEndTranslation.value<0){activeDecay();return;}if(!infinite){translation.value=_withSpring(0);return;}}if(translation.value<-((maxPage-1)*size)){if(scrollEndTranslation.value>0){activeDecay();return;}if(!infinite){translation.value=_withSpring(-((maxPage-1)*size));return;}}}}";_f.__workletHash=3458376770899;_f.__location="/Users/zhaodonghao/code/github/react-native-reanimated-carousel/src/ScrollViewGesture.tsx (160:44)";return _f;}(),[touching.value,translation,maxPage,size,scrollEndTranslation.value,infinite,activeDecay,_withSpring]);(0,_reactNativeReanimated.useAnimatedReaction)(function(){var _f=function _f(){return translation.value;};_f._closure={translation:translation};_f.asString="function _f(){const{translation}=jsThis._closure;{return translation.value;}}";_f.__workletHash=9829368032147;_f.__location="/Users/zhaodonghao/code/github/react-native-reanimated-carousel/src/ScrollViewGesture.tsx (199:8)";return _f;}(),function(){var _f=function _f(){if(!pagingEnabled){resetBoundary();}};_f._closure={pagingEnabled:pagingEnabled,resetBoundary:resetBoundary};_f.asString="function _f(){const{pagingEnabled,resetBoundary}=jsThis._closure;{if(!pagingEnabled){resetBoundary();}}}";_f.__workletHash=10686939088248;_f.__location="/Users/zhaodonghao/code/github/react-native-reanimated-carousel/src/ScrollViewGesture.tsx (200:8)";return _f;}(),[pagingEnabled,resetBoundary]);var panGestureEventHandler=(0,_reactNativeReanimated.useAnimatedGestureHandler)({onStart:function(){var _f=function _f(_,ctx){touching.value=true;ctx.validStart=true;onScrollBegin&&(0,_reactNativeReanimated.runOnJS)(onScrollBegin)();ctx.max=(maxPage-1)*size;ctx.panOffset=translation.value;};_f._closure={touching:touching,onScrollBegin:onScrollBegin,runOnJS:_reactNativeReanimated.runOnJS,maxPage:maxPage,size:size,translation:translation};_f.asString="function _f(_,ctx){const{touching,onScrollBegin,runOnJS,maxPage,size,translation}=jsThis._closure;{touching.value=true;ctx.validStart=true;onScrollBegin&&runOnJS(onScrollBegin)();ctx.max=(maxPage-1)*size;ctx.panOffset=translation.value;}}";_f.__workletHash=1789833551681;_f.__location="/Users/zhaodonghao/code/github/react-native-reanimated-carousel/src/ScrollViewGesture.tsx (213:21)";return _f;}(),onActive:function(){var _f=function _f(e,ctx){if(ctx.validStart){ctx.validStart=false;(0,_reactNativeReanimated.cancelAnimation)(translation);}touching.value=true;var translationX=e.translationX,translationY=e.translationY;var panTranslation=isHorizontal.value?translationX:translationY;if(!infinite&&(translation.value>0||translation.value<-ctx.max)){var boundary=translation.value>0?0:-ctx.max;var fixed=boundary-ctx.panOffset;var dynamic=panTranslation-fixed;translation.value=boundary+dynamic*0.5;return;}translation.value=ctx.panOffset+panTranslation;};_f._closure={cancelAnimation:_reactNativeReanimated.cancelAnimation,translation:translation,touching:touching,isHorizontal:isHorizontal,infinite:infinite};_f.asString="function _f(e,ctx){const{cancelAnimation,translation,touching,isHorizontal,infinite}=jsThis._closure;{if(ctx.validStart){ctx.validStart=false;cancelAnimation(translation);}touching.value=true;const{translationX:translationX,translationY:translationY}=e;let panTranslation=isHorizontal.value?translationX:translationY;if(!infinite&&(translation.value>0||translation.value<-ctx.max)){const boundary=translation.value>0?0:-ctx.max;const fixed=boundary-ctx.panOffset;const dynamic=panTranslation-fixed;translation.value=boundary+dynamic*0.5;return;}translation.value=ctx.panOffset+panTranslation;}}";_f.__workletHash=10275621069851;_f.__location="/Users/zhaodonghao/code/github/react-native-reanimated-carousel/src/ScrollViewGesture.tsx (220:22)";return _f;}(),onEnd:function(){var _f=function _f(e){var velocityX=e.velocityX,velocityY=e.velocityY,translationX=e.translationX,translationY=e.translationY;scrollEndVelocity.value=isHorizontal.value?velocityX:velocityY;scrollEndTranslation.value=isHorizontal.value?translationX:translationY;endWithSpring(onScrollEnd);if(!infinite){touching.value=false;}};_f._closure={scrollEndVelocity:scrollEndVelocity,isHorizontal:isHorizontal,scrollEndTranslation:scrollEndTranslation,endWithSpring:endWithSpring,onScrollEnd:onScrollEnd,infinite:infinite,touching:touching};_f.asString="function _f(e){const{scrollEndVelocity,isHorizontal,scrollEndTranslation,endWithSpring,onScrollEnd,infinite,touching}=jsThis._closure;{const{velocityX:velocityX,velocityY:velocityY,translationX:translationX,translationY:translationY}=e;scrollEndVelocity.value=isHorizontal.value?velocityX:velocityY;scrollEndTranslation.value=isHorizontal.value?translationX:translationY;endWithSpring(onScrollEnd);if(!infinite){touching.value=false;}}}";_f.__workletHash=8095479445863;_f.__location="/Users/zhaodonghao/code/github/react-native-reanimated-carousel/src/ScrollViewGesture.tsx (244:19)";return _f;}()},[pagingEnabled,isHorizontal.value,infinite,maxPage,size,snapEnabled,onScrollBegin,onScrollEnd]);var directionStyle=_react.default.useMemo(function(){return vertical?styles.contentHorizontal:styles.contentVertical;},[vertical]);return _react.default.createElement(_reactNativeReanimated.default.View,{style:[styles.container,directionStyle,{width:'100%',height:'100%'}],onTouchStart:onTouchBegin,onTouchEnd:onTouchEnd,__self:_this,__source:{fileName:_jsxFileName,lineNumber:277,columnNumber:9}},_react.default.createElement(_reactNativeGestureHandler.PanGestureHandler,(0,_extends2.default)({},panGestureHandlerProps,{enabled:enabled,onGestureEvent:panGestureEventHandler,__self:_this,__source:{fileName:_jsxFileName,lineNumber:286,columnNumber:13}}),props.children));};var ScrollViewGesture=IScrollViewGesture;exports.ScrollViewGesture=ScrollViewGesture;var styles=_reactNative.StyleSheet.create({container:{flex:1,overflow:'hidden'},contentVertical:{flexDirection:'column'},contentHorizontal:{flexDirection:'row'}});
|
|
2
2
|
//# sourceMappingURL=ScrollViewGesture.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["ScrollViewGesture.tsx"],"names":["IScrollViewGesture","props","React","useContext","CTX","vertical","data","pagingEnabled","snapEnabled","panGestureHandlerProps","infinite","loop","scrollAnimationDuration","withAnimation","enabled","translation","size","onScrollBegin","onScrollEnd","onTouchBegin","onTouchEnd","maxPage","length","isHorizontal","touching","scrollEndTranslation","scrollEndVelocity","_withSpring","useCallback","toValue","onFinished","defaultWithAnimation","type","config","duration","easing","Easing","easeOutQuart","isFinished","runOnJS","dealWithAnimation","endWithSpring","origin","value","velocity","nextPage","Math","round","deceleration","page","velocityPage","finalPage","min","max","withDecay","onFinish","activeDecay","resetBoundary","panGestureEventHandler","onStart","_","ctx","validStart","panOffset","onActive","e","translationX","translationY","panTranslation","boundary","fixed","dynamic","cancelAnimation","onEnd","velocityX","velocityY","directionStyle","useMemo","styles","contentHorizontal","contentVertical","container","width","height","children","ScrollViewGesture","StyleSheet","create","flex","overflow","flexDirection"],"mappings":"6PAAA,oDACA,yCACA,uEAIA,uFASA,sCACA,8BAEA,4D,knCAmBA,GAAMA,CAAAA,kBAAm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KAFjB,CAGIjC,QAHJ,CAIIW,OAJJ,CAKIL,IALJ,CAMIR,WANJ,CAOIS,aAPJ,CAQIC,WARJ,CApD2B,CAA/B,CAgEA,GAAM0D,CAAAA,cAAc,CAAG1E,eAAM2E,OAAN,CAAc,UAAM,CACvC,MAAOxE,CAAAA,QAAQ,CAAGyE,MAAM,CAACC,iBAAV,CAA8BD,MAAM,CAACE,eAApD,CACH,CAFsB,CAEpB,CAAC3E,QAAD,CAFoB,CAAvB,CAIA,MACI,8BAAC,8BAAD,CAAU,IAAV,EACI,KAAK,CAAE,CACHyE,MAAM,CAACG,SADJ,CAEHL,cAFG,CAGH,CAAEM,KAAK,CAAE,MAAT,CAAiBC,MAAM,CAAE,MAAzB,CAHG,CADX,CAMI,YAAY,CAAEhE,YANlB,CAOI,UAAU,CAAEC,UAPhB,8EASI,6BAAC,4CAAD,0BACQX,sBADR,EAEI,OAAO,CAAEK,OAFb,CAGI,cAAc,CAAE4C,sBAHpB,gFAKKzD,KAAK,CAACmF,QALX,CATJ,CADJ,CAmBH,CA7PD,CA+PO,GAAMC,CAAAA,iBAAiB,CAAGrF,kBAA1B,C,4CAEP,GAAM8E,CAAAA,MAAM,CAAGQ,wBAAWC,MAAX,CAAkB,CAC7BN,SAAS,CAAE,CACPO,IAAI,CAAE,CADC,CAEPC,QAAQ,CAAE,QAFH,CADkB,CAK7BT,eAAe,CAAE,CACbU,aAAa,CAAE,QADF,CALY,CAQ7BX,iBAAiB,CAAE,CACfW,aAAa,CAAE,KADA,CARU,CAAlB,CAAf","sourcesContent":["import React from 'react';\nimport { StyleProp, StyleSheet, ViewStyle } from 'react-native';\nimport {\n PanGestureHandler,\n PanGestureHandlerGestureEvent,\n} from 'react-native-gesture-handler';\nimport Animated, {\n cancelAnimation,\n runOnJS,\n useAnimatedGestureHandler,\n useAnimatedReaction,\n useDerivedValue,\n useSharedValue,\n withDecay,\n} from 'react-native-reanimated';\nimport { Easing } from './constants';\nimport { CTX } from './store';\nimport type { WithTimingAnimation } from './types';\nimport { dealWithAnimation } from './utils/dealWithAnimation';\n\ntype GestureContext = {\n validStart: boolean;\n panOffset: number;\n max: number;\n};\n\ninterface Props {\n size: number;\n infinite?: boolean;\n onScrollBegin?: () => void;\n onScrollEnd?: () => void;\n onTouchBegin?: () => void;\n onTouchEnd?: () => void;\n style?: StyleProp<ViewStyle>;\n translation: Animated.SharedValue<number>;\n}\n\nconst IScrollViewGesture: React.FC<Props> = (props) => {\n const {\n props: {\n vertical,\n data,\n pagingEnabled,\n snapEnabled,\n panGestureHandlerProps,\n loop: infinite,\n scrollAnimationDuration,\n withAnimation,\n enabled,\n },\n } = React.useContext(CTX);\n\n const {\n translation,\n size,\n onScrollBegin,\n onScrollEnd,\n onTouchBegin,\n onTouchEnd,\n } = props;\n\n const maxPage = data.length;\n const isHorizontal = useDerivedValue(() => !vertical, [vertical]);\n const touching = useSharedValue(false);\n const scrollEndTranslation = useSharedValue(0);\n const scrollEndVelocity = useSharedValue(0);\n\n const _withSpring = React.useCallback(\n (toValue: number, onFinished?: () => void) => {\n 'worklet';\n const defaultWithAnimation: WithTimingAnimation = {\n type: 'timing',\n config: {\n duration: scrollAnimationDuration + 100,\n easing: Easing.easeOutQuart,\n },\n };\n\n return dealWithAnimation(withAnimation ?? defaultWithAnimation)(\n toValue,\n (isFinished: boolean) => {\n 'worklet';\n if (isFinished) {\n onFinished && runOnJS(onFinished)();\n }\n }\n );\n },\n [scrollAnimationDuration, withAnimation]\n );\n\n const endWithSpring = React.useCallback(\n (onFinished?: () => void) => {\n 'worklet';\n const origin = translation.value;\n const velocity = scrollEndVelocity.value;\n if (!pagingEnabled) {\n if (snapEnabled) {\n const nextPage =\n Math.round((origin + velocity * 0.4) / size) * size;\n translation.value = _withSpring(nextPage, onFinished);\n return;\n }\n translation.value = withDecay({\n velocity,\n deceleration: 0.999,\n });\n return;\n }\n const page = Math.round(-translation.value / size);\n const velocityPage = Math.round(\n -(translation.value + scrollEndVelocity.value) / size\n );\n let finalPage = Math.min(\n page + 1,\n Math.max(page - 1, velocityPage)\n );\n if (!infinite) {\n finalPage = Math.min(maxPage - 1, Math.max(0, finalPage));\n }\n\n translation.value = _withSpring(-finalPage * size, onFinished);\n },\n [\n infinite,\n _withSpring,\n translation,\n scrollEndVelocity,\n size,\n maxPage,\n pagingEnabled,\n snapEnabled,\n ]\n );\n\n const onFinish = React.useCallback(\n (isFinished: boolean) => {\n 'worklet';\n if (isFinished) {\n touching.value = false;\n onScrollEnd && runOnJS(onScrollEnd)();\n }\n },\n [onScrollEnd, touching]\n );\n\n const activeDecay = React.useCallback(() => {\n 'worklet';\n touching.value = true;\n translation.value = withDecay(\n { velocity: scrollEndVelocity.value },\n (isFinished) => onFinish(isFinished as boolean)\n );\n }, [onFinish, scrollEndVelocity.value, touching, translation]);\n\n const resetBoundary = React.useCallback(() => {\n 'worklet';\n if (touching.value) {\n return;\n }\n\n if (translation.value > 0) {\n if (scrollEndTranslation.value < 0) {\n activeDecay();\n return;\n }\n if (!infinite) {\n translation.value = _withSpring(0);\n return;\n }\n }\n\n if (translation.value < -((maxPage - 1) * size)) {\n if (scrollEndTranslation.value > 0) {\n activeDecay();\n return;\n }\n if (!infinite) {\n translation.value = _withSpring(-((maxPage - 1) * size));\n return;\n }\n }\n }, [\n touching.value,\n translation,\n maxPage,\n size,\n scrollEndTranslation.value,\n infinite,\n activeDecay,\n _withSpring,\n ]);\n\n useAnimatedReaction(\n () => translation.value,\n () => {\n if (!pagingEnabled) {\n resetBoundary();\n }\n },\n [pagingEnabled, resetBoundary]\n );\n\n const panGestureEventHandler = useAnimatedGestureHandler<\n PanGestureHandlerGestureEvent,\n GestureContext\n >(\n {\n onStart: (_, ctx) => {\n touching.value = true;\n ctx.validStart = true;\n onScrollBegin && runOnJS(onScrollBegin)();\n ctx.max = (maxPage - 1) * size;\n ctx.panOffset = translation.value;\n },\n onActive: (e, ctx) => {\n if (ctx.validStart) {\n ctx.validStart = false;\n cancelAnimation(translation);\n }\n touching.value = true;\n const { translationX, translationY } = e;\n let panTranslation = isHorizontal.value\n ? translationX\n : translationY;\n\n if (\n !infinite &&\n (translation.value > 0 || translation.value < -ctx.max)\n ) {\n const boundary = translation.value > 0 ? 0 : -ctx.max;\n const fixed = boundary - ctx.panOffset;\n const dynamic = panTranslation - fixed;\n translation.value = boundary + dynamic * 0.5;\n return;\n }\n\n translation.value = ctx.panOffset + panTranslation;\n },\n onEnd: (e) => {\n const { velocityX, velocityY, translationX, translationY } = e;\n scrollEndVelocity.value = isHorizontal.value\n ? velocityX\n : velocityY;\n scrollEndTranslation.value = isHorizontal.value\n ? translationX\n : translationY;\n\n endWithSpring(onScrollEnd);\n\n if (!infinite) {\n touching.value = false;\n }\n },\n },\n [\n pagingEnabled,\n isHorizontal.value,\n infinite,\n maxPage,\n size,\n snapEnabled,\n onScrollBegin,\n onScrollEnd,\n ]\n );\n\n const directionStyle = React.useMemo(() => {\n return vertical ? styles.contentHorizontal : styles.contentVertical;\n }, [vertical]);\n\n return (\n <Animated.View\n style={[\n styles.container,\n directionStyle,\n { width: '100%', height: '100%' },\n ]}\n onTouchStart={onTouchBegin}\n onTouchEnd={onTouchEnd}\n >\n <PanGestureHandler\n {...panGestureHandlerProps}\n enabled={enabled}\n onGestureEvent={panGestureEventHandler}\n >\n {props.children}\n </PanGestureHandler>\n </Animated.View>\n );\n};\n\nexport const ScrollViewGesture = IScrollViewGesture;\n\nconst styles = StyleSheet.create({\n container: {\n flex: 1,\n overflow: 'hidden',\n },\n contentVertical: {\n flexDirection: 'column',\n },\n contentHorizontal: {\n flexDirection: 'row',\n },\n});\n"]}
|
|
1
|
+
{"version":3,"sources":["ScrollViewGesture.tsx"],"names":["IScrollViewGesture","props","React","useContext","CTX","vertical","data","pagingEnabled","snapEnabled","panGestureHandlerProps","infinite","loop","scrollAnimationDuration","withAnimation","enabled","translation","size","onScrollBegin","onScrollEnd","onTouchBegin","onTouchEnd","maxPage","length","isHorizontal","touching","scrollEndTranslation","scrollEndVelocity","_withSpring","useCallback","toValue","onFinished","defaultWithAnimation","type","config","duration","easing","Easing","easeOutQuart","isFinished","runOnJS","dealWithAnimation","endWithSpring","origin","value","velocity","nextPage","Math","round","deceleration","direction","computed","ceil","floor","page","finalPage","min","max","withDecay","onFinish","activeDecay","resetBoundary","panGestureEventHandler","onStart","_","ctx","validStart","panOffset","onActive","e","translationX","translationY","panTranslation","boundary","fixed","dynamic","cancelAnimation","onEnd","velocityX","velocityY","directionStyle","useMemo","styles","contentHorizontal","contentVertical","container","width","height","children","ScrollViewGesture","StyleSheet","create","flex","overflow","flexDirection"],"mappings":"6PAAA,oDACA,yCACA,uEAIA,uFASA,sCACA,8BAEA,4D,knCAmBA,GAAMA,CAAAA,kBAAmC,CAAG,QAAtCA,CAAAA,kBAAsC,CAACC,KAAD,CAAW,CACnD,sBAYIC,eAAMC,UAAN,CAAiBC,UAAjB,CAZJ,yCACIH,KADJ,CAEQI,QAFR,uBAEQA,QAFR,CAGQC,IAHR,uBAGQA,IAHR,CAIQC,aAJR,uBAIQA,aAJR,CAKQC,WALR,uBAKQA,WALR,CAMQC,sBANR,uBAMQA,sBANR,CAOcC,QAPd,uBAOQC,IAPR,CAQQC,uBARR,uBAQQA,uBARR,CASQC,aATR,uBASQA,aATR,CAUQC,OAVR,uBAUQA,OAVR,CAcA,GACIC,CAAAA,WADJ,CAOId,KAPJ,CACIc,WADJ,CAEIC,IAFJ,CAOIf,KAPJ,CAEIe,IAFJ,CAGIC,aAHJ,CAOIhB,KAPJ,CAGIgB,aAHJ,CAIIC,WAJJ,CAOIjB,KAPJ,CAIIiB,WAJJ,CAKIC,YALJ,CAOIlB,KAPJ,CAKIkB,YALJ,CAMIC,UANJ,CAOInB,KAPJ,CAMImB,UANJ,CASA,GAAMC,CAAAA,OAAO,CAAGf,IAAI,CAACgB,MAArB,CACA,GAAMC,CAAAA,YAAY,CAAG,6DAAgB,oBAAM,CAAClB,QAAP,EAAhB,uBA7DjBA,QA6DiB,kPAAiC,CAACA,QAAD,CAAj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C,MAAX,CAAkB,CAC7BN,SAAS,CAAE,CACPO,IAAI,CAAE,CADC,CAEPC,QAAQ,CAAE,QAFH,CADkB,CAK7BT,eAAe,CAAE,CACbU,aAAa,CAAE,QADF,CALY,CAQ7BX,iBAAiB,CAAE,CACfW,aAAa,CAAE,KADA,CARU,CAAlB,CAAf","sourcesContent":["import React from 'react';\nimport { StyleProp, StyleSheet, ViewStyle } from 'react-native';\nimport {\n PanGestureHandler,\n PanGestureHandlerGestureEvent,\n} from 'react-native-gesture-handler';\nimport Animated, {\n cancelAnimation,\n runOnJS,\n useAnimatedGestureHandler,\n useAnimatedReaction,\n useDerivedValue,\n useSharedValue,\n withDecay,\n} from 'react-native-reanimated';\nimport { Easing } from './constants';\nimport { CTX } from './store';\nimport type { WithTimingAnimation } from './types';\nimport { dealWithAnimation } from './utils/dealWithAnimation';\n\ntype GestureContext = {\n validStart: boolean;\n panOffset: number;\n max: number;\n};\n\ninterface Props {\n size: number;\n infinite?: boolean;\n onScrollBegin?: () => void;\n onScrollEnd?: () => void;\n onTouchBegin?: () => void;\n onTouchEnd?: () => void;\n style?: StyleProp<ViewStyle>;\n translation: Animated.SharedValue<number>;\n}\n\nconst IScrollViewGesture: React.FC<Props> = (props) => {\n const {\n props: {\n vertical,\n data,\n pagingEnabled,\n snapEnabled,\n panGestureHandlerProps,\n loop: infinite,\n scrollAnimationDuration,\n withAnimation,\n enabled,\n },\n } = React.useContext(CTX);\n\n const {\n translation,\n size,\n onScrollBegin,\n onScrollEnd,\n onTouchBegin,\n onTouchEnd,\n } = props;\n\n const maxPage = data.length;\n const isHorizontal = useDerivedValue(() => !vertical, [vertical]);\n const touching = useSharedValue(false);\n const scrollEndTranslation = useSharedValue(0);\n const scrollEndVelocity = useSharedValue(0);\n\n const _withSpring = React.useCallback(\n (toValue: number, onFinished?: () => void) => {\n 'worklet';\n const defaultWithAnimation: WithTimingAnimation = {\n type: 'timing',\n config: {\n duration: scrollAnimationDuration + 100,\n easing: Easing.easeOutQuart,\n },\n };\n\n return dealWithAnimation(withAnimation ?? defaultWithAnimation)(\n toValue,\n (isFinished: boolean) => {\n 'worklet';\n if (isFinished) {\n onFinished && runOnJS(onFinished)();\n }\n }\n );\n },\n [scrollAnimationDuration, withAnimation]\n );\n\n const endWithSpring = React.useCallback(\n (onFinished?: () => void) => {\n 'worklet';\n const origin = translation.value;\n const velocity = scrollEndVelocity.value;\n if (!pagingEnabled) {\n /**\n * If enabled, releasing the touch will scroll to the nearest item.\n * valid when pagingEnabled=false\n */\n if (snapEnabled) {\n const nextPage =\n Math.round((origin + velocity * 0.4) / size) * size;\n\n translation.value = _withSpring(nextPage, onFinished);\n return;\n }\n translation.value = withDecay({\n velocity,\n deceleration: 0.999,\n });\n return;\n }\n\n const direction = -(scrollEndTranslation.value >= 0 ? 1 : -1);\n const computed = direction < 0 ? Math.ceil : Math.floor;\n const page = computed(-translation.value / size);\n let finalPage = page + direction;\n\n if (!infinite) {\n finalPage = Math.min(maxPage - 1, Math.max(0, finalPage));\n }\n\n translation.value = _withSpring(-finalPage * size, onFinished);\n },\n [\n translation,\n scrollEndVelocity.value,\n pagingEnabled,\n size,\n scrollEndTranslation.value,\n infinite,\n _withSpring,\n snapEnabled,\n maxPage,\n ]\n );\n\n const onFinish = React.useCallback(\n (isFinished: boolean) => {\n 'worklet';\n if (isFinished) {\n touching.value = false;\n onScrollEnd && runOnJS(onScrollEnd)();\n }\n },\n [onScrollEnd, touching]\n );\n\n const activeDecay = React.useCallback(() => {\n 'worklet';\n touching.value = true;\n translation.value = withDecay(\n { velocity: scrollEndVelocity.value },\n (isFinished) => onFinish(isFinished as boolean)\n );\n }, [onFinish, scrollEndVelocity.value, touching, translation]);\n\n const resetBoundary = React.useCallback(() => {\n 'worklet';\n if (touching.value) {\n return;\n }\n\n if (translation.value > 0) {\n if (scrollEndTranslation.value < 0) {\n activeDecay();\n return;\n }\n if (!infinite) {\n translation.value = _withSpring(0);\n return;\n }\n }\n\n if (translation.value < -((maxPage - 1) * size)) {\n if (scrollEndTranslation.value > 0) {\n activeDecay();\n return;\n }\n if (!infinite) {\n translation.value = _withSpring(-((maxPage - 1) * size));\n return;\n }\n }\n }, [\n touching.value,\n translation,\n maxPage,\n size,\n scrollEndTranslation.value,\n infinite,\n activeDecay,\n _withSpring,\n ]);\n\n useAnimatedReaction(\n () => translation.value,\n () => {\n if (!pagingEnabled) {\n resetBoundary();\n }\n },\n [pagingEnabled, resetBoundary]\n );\n\n const panGestureEventHandler = useAnimatedGestureHandler<\n PanGestureHandlerGestureEvent,\n GestureContext\n >(\n {\n onStart: (_, ctx) => {\n touching.value = true;\n ctx.validStart = true;\n onScrollBegin && runOnJS(onScrollBegin)();\n ctx.max = (maxPage - 1) * size;\n ctx.panOffset = translation.value;\n },\n onActive: (e, ctx) => {\n if (ctx.validStart) {\n ctx.validStart = false;\n cancelAnimation(translation);\n }\n touching.value = true;\n const { translationX, translationY } = e;\n let panTranslation = isHorizontal.value\n ? translationX\n : translationY;\n\n if (\n !infinite &&\n (translation.value > 0 || translation.value < -ctx.max)\n ) {\n const boundary = translation.value > 0 ? 0 : -ctx.max;\n const fixed = boundary - ctx.panOffset;\n const dynamic = panTranslation - fixed;\n translation.value = boundary + dynamic * 0.5;\n return;\n }\n\n translation.value = ctx.panOffset + panTranslation;\n },\n onEnd: (e) => {\n const { velocityX, velocityY, translationX, translationY } = e;\n scrollEndVelocity.value = isHorizontal.value\n ? velocityX\n : velocityY;\n scrollEndTranslation.value = isHorizontal.value\n ? translationX\n : translationY;\n\n endWithSpring(onScrollEnd);\n\n if (!infinite) {\n touching.value = false;\n }\n },\n },\n [\n pagingEnabled,\n isHorizontal.value,\n infinite,\n maxPage,\n size,\n snapEnabled,\n onScrollBegin,\n onScrollEnd,\n ]\n );\n\n const directionStyle = React.useMemo(() => {\n return vertical ? styles.contentHorizontal : styles.contentVertical;\n }, [vertical]);\n\n return (\n <Animated.View\n style={[\n styles.container,\n directionStyle,\n { width: '100%', height: '100%' },\n ]}\n onTouchStart={onTouchBegin}\n onTouchEnd={onTouchEnd}\n >\n <PanGestureHandler\n {...panGestureHandlerProps}\n enabled={enabled}\n onGestureEvent={panGestureEventHandler}\n >\n {props.children}\n </PanGestureHandler>\n </Animated.View>\n );\n};\n\nexport const ScrollViewGesture = IScrollViewGesture;\n\nconst styles = StyleSheet.create({\n container: {\n flex: 1,\n overflow: 'hidden',\n },\n contentVertical: {\n flexDirection: 'column',\n },\n contentHorizontal: {\n flexDirection: 'row',\n },\n});\n"]}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
Object.defineProperty(exports,"__esModule",{value:true});exports.useCarouselController=useCarouselController;var _react=_interopRequireWildcard(require("react"));var _constants=require("../constants");var _reactNativeReanimated=require("react-native-reanimated");var _dealWithAnimation=require("../utils/dealWithAnimation");var _computedWithAutoFillData=require("../utils/computedWithAutoFillData");var _log=require("../utils/log");function _getRequireWildcardCache(nodeInterop){if(typeof WeakMap!=="function")return null;var cacheBabelInterop=new WeakMap();var cacheNodeInterop=new WeakMap();return(_getRequireWildcardCache=function _getRequireWildcardCache(nodeInterop){return nodeInterop?cacheNodeInterop:cacheBabelInterop;})(nodeInterop);}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;}function useCarouselController(options){var size=options.size,data=options.data,loop=options.loop,handlerOffsetX=options.handlerOffsetX,withAnimation=options.withAnimation,_options$defaultIndex=options.defaultIndex,defaultIndex=_options$defaultIndex===void 0?0:_options$defaultIndex,duration=options.duration,autoFillData=options.autoFillData;var dataInfo=_react.default.useMemo(function(){return{length:data.length,disable:!data.length,originalLength:data.length};},[data]);var index=(0,_reactNativeReanimated.useSharedValue)(defaultIndex);var sharedIndex=(0,_react.useRef)(defaultIndex);var sharedPreIndex=(0,_react.useRef)(defaultIndex);var currentFixedPage=_react.default.useCallback(function(){if(loop){return-Math.round(handlerOffsetX.value/size);}var fixed=handlerOffsetX.value/size%dataInfo.length;return Math.round(handlerOffsetX.value<=0?Math.abs(fixed):Math.abs(fixed>0?dataInfo.length-fixed:0));},[handlerOffsetX,dataInfo,size,loop]);function setSharedIndex(newSharedIndex){sharedIndex.current=newSharedIndex;}(0,_reactNativeReanimated.useAnimatedReaction)(function(){var _f=function _f(){var handlerOffsetXValue=handlerOffsetX.value;var toInt=(0,_log.round)(handlerOffsetXValue/size)%dataInfo.length;var isPositive=handlerOffsetXValue<=0;var i=isPositive?Math.abs(toInt):Math.abs(toInt>0?dataInfo.length-toInt:0);var newSharedIndexValue=(0,_computedWithAutoFillData.convertToSharedIndex)({loop:loop,rawDataLength:dataInfo.originalLength,autoFillData:autoFillData,index:i});return{i:i,newSharedIndexValue:newSharedIndexValue};};_f._closure={handlerOffsetX:handlerOffsetX,round:_log.round,size:size,dataInfo:dataInfo,convertToSharedIndex:_computedWithAutoFillData.convertToSharedIndex,loop:loop,autoFillData:autoFillData};_f.asString="function _f(){const{handlerOffsetX,round,size,dataInfo,convertToSharedIndex,loop,autoFillData}=jsThis._closure;{const handlerOffsetXValue=handlerOffsetX.value;const toInt=round(handlerOffsetXValue/size)%dataInfo.length;const isPositive=handlerOffsetXValue<=0;const i=isPositive?Math.abs(toInt):Math.abs(toInt>0?dataInfo.length-toInt:0);const newSharedIndexValue=convertToSharedIndex({loop:loop,rawDataLength:dataInfo.originalLength,autoFillData:autoFillData,index:i});return{i:i,newSharedIndexValue:newSharedIndexValue};}}";_f.__workletHash=14011541648783;_f.__location="/Users/zhaodonghao/code/github/react-native-reanimated-carousel/src/hooks/useCarouselController.tsx (83:8)";return _f;}(),function(){var _f=function _f(_ref){var i=_ref.i,newSharedIndexValue=_ref.newSharedIndexValue;index.value=i;(0,_reactNativeReanimated.runOnJS)(setSharedIndex)(newSharedIndexValue);};_f._closure={index:index,runOnJS:_reactNativeReanimated.runOnJS,setSharedIndex:setSharedIndex};_f.asString="function _f({i:i,newSharedIndexValue:newSharedIndexValue}){const{index,runOnJS,setSharedIndex}=jsThis._closure;{index.value=i;runOnJS(setSharedIndex)(newSharedIndexValue);}}";_f.__workletHash=16638491076412;_f.__location="/Users/zhaodonghao/code/github/react-native-reanimated-carousel/src/hooks/useCarouselController.tsx (103:8)";return _f;}(),[sharedPreIndex,sharedIndex,size,dataInfo,index,loop,autoFillData,handlerOffsetX]);var getCurrentIndex=_react.default.useCallback(function(){return index.value;},[index]);var canSliding=_react.default.useCallback(function(){return!dataInfo.disable;},[dataInfo]);var onScrollEnd=_react.default.useCallback(function(){options.onScrollEnd==null?void 0:options.onScrollEnd();},[options]);var onScrollBegin=_react.default.useCallback(function(){options.onScrollBegin==null?void 0:options.onScrollBegin();},[options]);var scrollWithTiming=_react.default.useCallback(function(){var _f=function _f(toValue,onFinished){var callback=function(){var _f=function _f(isFinished){if(isFinished){(0,_reactNativeReanimated.runOnJS)(onScrollEnd)();onFinished&&(0,_reactNativeReanimated.runOnJS)(onFinished)();}};_f._closure={runOnJS:_reactNativeReanimated.runOnJS,onScrollEnd:onScrollEnd,onFinished:onFinished};_f.asString="function _f(isFinished){const{runOnJS,onScrollEnd,onFinished}=jsThis._closure;{if(isFinished){runOnJS(onScrollEnd)();onFinished&&runOnJS(onFinished)();}}}";_f.__workletHash=7767198641261;_f.__location="/Users/zhaodonghao/code/github/react-native-reanimated-carousel/src/hooks/useCarouselController.tsx (138:29)";return _f;}();var defaultWithAnimation={type:'timing',config:{duration:duration,easing:_constants.Easing.easeOutQuart}};return(0,_dealWithAnimation.dealWithAnimation)(withAnimation!=null?withAnimation:defaultWithAnimation)(toValue,callback);};_f._closure={runOnJS:_reactNativeReanimated.runOnJS,onScrollEnd:onScrollEnd,duration:duration,Easing:{easeOutQuart:_constants.Easing.easeOutQuart},dealWithAnimation:_dealWithAnimation.dealWithAnimation,withAnimation:withAnimation};_f.asString="function _f(toValue,onFinished){const{runOnJS,onScrollEnd,duration,Easing,dealWithAnimation,withAnimation}=jsThis._closure;{var _withAnimation;const callback=function(isFinished){'worklet';if(isFinished){runOnJS(onScrollEnd)();onFinished&&runOnJS(onFinished)();}};const defaultWithAnimation={type:'timing',config:{duration:duration,easing:Easing.easeOutQuart}};return dealWithAnimation((_withAnimation=withAnimation)!==null&&_withAnimation!==void 0?_withAnimation:defaultWithAnimation)(toValue,callback);}}";_f.__workletHash=15006680124176;_f.__location="/Users/zhaodonghao/code/github/react-native-reanimated-carousel/src/hooks/useCarouselController.tsx (136:8)";return _f;}(),[duration,withAnimation,onScrollEnd]);var next=_react.default.useCallback(function(){var _f=function _f(){var opts=arguments.length>0&&arguments[0]!==undefined?arguments[0]:{};var _opts$count=opts.count,count=_opts$count===void 0?1:_opts$count,_opts$animated=opts.animated,animated=_opts$animated===void 0?true:_opts$animated,onFinished=opts.onFinished;if(!canSliding()||!loop&&index.value>=dataInfo.length-1)return;onScrollBegin==null?void 0:onScrollBegin();var nextPage=currentFixedPage()+count;index.value=nextPage;if(animated){handlerOffsetX.value=scrollWithTiming(-nextPage*size,onFinished);}else{handlerOffsetX.value=-nextPage*size;onFinished==null?void 0:onFinished();}};_f._closure={canSliding:canSliding,loop:loop,index:index,dataInfo:dataInfo,onScrollBegin:onScrollBegin,currentFixedPage:currentFixedPage,handlerOffsetX:handlerOffsetX,scrollWithTiming:scrollWithTiming,size:size};_f.asString="function _f(opts={}){const{canSliding,loop,index,dataInfo,onScrollBegin,currentFixedPage,handlerOffsetX,scrollWithTiming,size}=jsThis._closure;{var _onScrollBegin;const{count=1,animated=true,onFinished:onFinished}=opts;if(!canSliding()||!loop&&index.value>=dataInfo.length-1)return;(_onScrollBegin=onScrollBegin)===null||_onScrollBegin===void 0?void 0:_onScrollBegin();const nextPage=currentFixedPage()+count;index.value=nextPage;if(animated){handlerOffsetX.value=scrollWithTiming(-nextPage*size,onFinished);}else{handlerOffsetX.value=-nextPage*size;onFinished===null||onFinished===void 0?void 0:onFinished();}}}";_f.__workletHash=1734401141936;_f.__location="/Users/zhaodonghao/code/github/react-native-reanimated-carousel/src/hooks/useCarouselController.tsx (160:8)";return _f;}(),[canSliding,loop,index,dataInfo,onScrollBegin,handlerOffsetX,size,scrollWithTiming,currentFixedPage]);var prev=_react.default.useCallback(function(){var opts=arguments.length>0&&arguments[0]!==undefined?arguments[0]:{};var _opts$count2=opts.count,count=_opts$count2===void 0?1:_opts$count2,_opts$animated2=opts.animated,animated=_opts$animated2===void 0?true:_opts$animated2,onFinished=opts.onFinished;if(!canSliding()||!loop&&index.value<=0)return;onScrollBegin==null?void 0:onScrollBegin();var prevPage=currentFixedPage()-count;index.value=prevPage;if(animated){handlerOffsetX.value=scrollWithTiming(-prevPage*size,onFinished);}else{handlerOffsetX.value=-prevPage*size;onFinished==null?void 0:onFinished();}},[canSliding,loop,index,onScrollBegin,handlerOffsetX,size,scrollWithTiming,currentFixedPage]);var to=_react.default.useCallback(function(opts){var i=opts.i,_opts$animated3=opts.animated,animated=_opts$animated3===void 0?false:_opts$animated3,onFinished=opts.onFinished;if(i===index.value)return;if(!canSliding())return;onScrollBegin==null?void 0:onScrollBegin();var offset=handlerOffsetX.value+(index.value-i)*size;if(animated){index.value=i;handlerOffsetX.value=scrollWithTiming(offset,onFinished);}else{handlerOffsetX.value=offset;index.value=i;onFinished==null?void 0:onFinished();}},[index,canSliding,onScrollBegin,handlerOffsetX,size,scrollWithTiming]);var scrollTo=_react.default.useCallback(function(){var opts=arguments.length>0&&arguments[0]!==undefined?arguments[0]:{};var i=opts.index,count=opts.count,_opts$animated4=opts.animated,animated=_opts$animated4===void 0?false:_opts$animated4,onFinished=opts.onFinished;if(typeof i==='number'&&i>-1){to({i:i,animated:animated,onFinished:onFinished});return;}if(!count){return;}var n=Math.round(count);if(n<0){prev({count:Math.abs(n),animated:animated,onFinished:onFinished});}else{next({count:n,animated:animated,onFinished:onFinished});}},[prev,next,to]);return{next:next,prev:prev,scrollTo:scrollTo,getCurrentIndex:getCurrentIndex,getSharedIndex:function getSharedIndex(){return sharedIndex.current;}};}
|
|
1
|
+
Object.defineProperty(exports,"__esModule",{value:true});exports.useCarouselController=useCarouselController;var _react=_interopRequireWildcard(require("react"));var _constants=require("../constants");var _reactNativeReanimated=require("react-native-reanimated");var _dealWithAnimation=require("../utils/dealWithAnimation");var _computedWithAutoFillData=require("../utils/computedWithAutoFillData");var _log=require("../utils/log");function _getRequireWildcardCache(nodeInterop){if(typeof WeakMap!=="function")return null;var cacheBabelInterop=new WeakMap();var cacheNodeInterop=new WeakMap();return(_getRequireWildcardCache=function _getRequireWildcardCache(nodeInterop){return nodeInterop?cacheNodeInterop:cacheBabelInterop;})(nodeInterop);}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;}function useCarouselController(options){var size=options.size,data=options.data,loop=options.loop,handlerOffsetX=options.handlerOffsetX,withAnimation=options.withAnimation,_options$defaultIndex=options.defaultIndex,defaultIndex=_options$defaultIndex===void 0?0:_options$defaultIndex,duration=options.duration,autoFillData=options.autoFillData;var dataInfo=_react.default.useMemo(function(){return{length:data.length,disable:!data.length,originalLength:data.length};},[data]);var index=(0,_reactNativeReanimated.useSharedValue)(defaultIndex);var sharedIndex=(0,_react.useRef)(defaultIndex);var sharedPreIndex=(0,_react.useRef)(defaultIndex);var currentFixedPage=_react.default.useCallback(function(){if(loop){return-Math.round(handlerOffsetX.value/size);}var fixed=handlerOffsetX.value/size%dataInfo.length;return Math.round(handlerOffsetX.value<=0?Math.abs(fixed):Math.abs(fixed>0?dataInfo.length-fixed:0));},[handlerOffsetX,dataInfo,size,loop]);function setSharedIndex(newSharedIndex){sharedIndex.current=newSharedIndex;}(0,_reactNativeReanimated.useAnimatedReaction)(function(){var _f=function _f(){var handlerOffsetXValue=handlerOffsetX.value;var toInt=(0,_log.round)(handlerOffsetXValue/size)%dataInfo.length;var isPositive=handlerOffsetXValue<=0;var i=isPositive?Math.abs(toInt):Math.abs(toInt>0?dataInfo.length-toInt:0);var newSharedIndexValue=(0,_computedWithAutoFillData.convertToSharedIndex)({loop:loop,rawDataLength:dataInfo.originalLength,autoFillData:autoFillData,index:i});return{i:i,newSharedIndexValue:newSharedIndexValue};};_f._closure={handlerOffsetX:handlerOffsetX,round:_log.round,size:size,dataInfo:dataInfo,convertToSharedIndex:_computedWithAutoFillData.convertToSharedIndex,loop:loop,autoFillData:autoFillData};_f.asString="function _f(){const{handlerOffsetX,round,size,dataInfo,convertToSharedIndex,loop,autoFillData}=jsThis._closure;{const handlerOffsetXValue=handlerOffsetX.value;const toInt=round(handlerOffsetXValue/size)%dataInfo.length;const isPositive=handlerOffsetXValue<=0;const i=isPositive?Math.abs(toInt):Math.abs(toInt>0?dataInfo.length-toInt:0);const newSharedIndexValue=convertToSharedIndex({loop:loop,rawDataLength:dataInfo.originalLength,autoFillData:autoFillData,index:i});return{i:i,newSharedIndexValue:newSharedIndexValue};}}";_f.__workletHash=14011541648783;_f.__location="/Users/zhaodonghao/code/github/react-native-reanimated-carousel/src/hooks/useCarouselController.tsx (83:8)";return _f;}(),function(){var _f=function _f(_ref){var i=_ref.i,newSharedIndexValue=_ref.newSharedIndexValue;index.value=i;(0,_reactNativeReanimated.runOnJS)(setSharedIndex)(newSharedIndexValue);};_f._closure={index:index,runOnJS:_reactNativeReanimated.runOnJS,setSharedIndex:setSharedIndex};_f.asString="function _f({i:i,newSharedIndexValue:newSharedIndexValue}){const{index,runOnJS,setSharedIndex}=jsThis._closure;{index.value=i;runOnJS(setSharedIndex)(newSharedIndexValue);}}";_f.__workletHash=16638491076412;_f.__location="/Users/zhaodonghao/code/github/react-native-reanimated-carousel/src/hooks/useCarouselController.tsx (103:8)";return _f;}(),[sharedPreIndex,sharedIndex,size,dataInfo,index,loop,autoFillData,handlerOffsetX]);var getCurrentIndex=_react.default.useCallback(function(){return index.value;},[index]);var canSliding=_react.default.useCallback(function(){return!dataInfo.disable;},[dataInfo]);var onScrollEnd=_react.default.useCallback(function(){options.onScrollEnd==null?void 0:options.onScrollEnd();},[options]);var onScrollBegin=_react.default.useCallback(function(){options.onScrollBegin==null?void 0:options.onScrollBegin();},[options]);var scrollWithTiming=_react.default.useCallback(function(){var _f=function _f(toValue,onFinished){var callback=function(){var _f=function _f(isFinished){if(isFinished){(0,_reactNativeReanimated.runOnJS)(onScrollEnd)();onFinished&&(0,_reactNativeReanimated.runOnJS)(onFinished)();}};_f._closure={runOnJS:_reactNativeReanimated.runOnJS,onScrollEnd:onScrollEnd,onFinished:onFinished};_f.asString="function _f(isFinished){const{runOnJS,onScrollEnd,onFinished}=jsThis._closure;{if(isFinished){runOnJS(onScrollEnd)();onFinished&&runOnJS(onFinished)();}}}";_f.__workletHash=7767198641261;_f.__location="/Users/zhaodonghao/code/github/react-native-reanimated-carousel/src/hooks/useCarouselController.tsx (138:29)";return _f;}();var defaultWithAnimation={type:'timing',config:{duration:duration,easing:_constants.Easing.easeOutQuart}};return(0,_dealWithAnimation.dealWithAnimation)(withAnimation!=null?withAnimation:defaultWithAnimation)(toValue,callback);};_f._closure={runOnJS:_reactNativeReanimated.runOnJS,onScrollEnd:onScrollEnd,duration:duration,Easing:{easeOutQuart:_constants.Easing.easeOutQuart},dealWithAnimation:_dealWithAnimation.dealWithAnimation,withAnimation:withAnimation};_f.asString="function _f(toValue,onFinished){const{runOnJS,onScrollEnd,duration,Easing,dealWithAnimation,withAnimation}=jsThis._closure;{var _withAnimation;const callback=function(isFinished){'worklet';if(isFinished){runOnJS(onScrollEnd)();onFinished&&runOnJS(onFinished)();}};const defaultWithAnimation={type:'timing',config:{duration:duration,easing:Easing.easeOutQuart}};return dealWithAnimation((_withAnimation=withAnimation)!==null&&_withAnimation!==void 0?_withAnimation:defaultWithAnimation)(toValue,callback);}}";_f.__workletHash=15006680124176;_f.__location="/Users/zhaodonghao/code/github/react-native-reanimated-carousel/src/hooks/useCarouselController.tsx (136:8)";return _f;}(),[duration,withAnimation,onScrollEnd]);var next=_react.default.useCallback(function(){var _f=function _f(){var opts=arguments.length>0&&arguments[0]!==undefined?arguments[0]:{};var _opts$count=opts.count,count=_opts$count===void 0?1:_opts$count,_opts$animated=opts.animated,animated=_opts$animated===void 0?true:_opts$animated,onFinished=opts.onFinished;if(!canSliding()||!loop&&index.value>=dataInfo.length-1)return;onScrollBegin==null?void 0:onScrollBegin();var nextPage=currentFixedPage()+count;index.value=nextPage;if(animated){handlerOffsetX.value=scrollWithTiming(-nextPage*size,onFinished);}else{handlerOffsetX.value=-nextPage*size;onFinished==null?void 0:onFinished();}};_f._closure={canSliding:canSliding,loop:loop,index:index,dataInfo:dataInfo,onScrollBegin:onScrollBegin,currentFixedPage:currentFixedPage,handlerOffsetX:handlerOffsetX,scrollWithTiming:scrollWithTiming,size:size};_f.asString="function _f(opts={}){const{canSliding,loop,index,dataInfo,onScrollBegin,currentFixedPage,handlerOffsetX,scrollWithTiming,size}=jsThis._closure;{var _onScrollBegin;const{count=1,animated=true,onFinished:onFinished}=opts;if(!canSliding()||!loop&&index.value>=dataInfo.length-1)return;(_onScrollBegin=onScrollBegin)===null||_onScrollBegin===void 0?void 0:_onScrollBegin();const nextPage=currentFixedPage()+count;index.value=nextPage;if(animated){handlerOffsetX.value=scrollWithTiming(-nextPage*size,onFinished);}else{handlerOffsetX.value=-nextPage*size;onFinished===null||onFinished===void 0?void 0:onFinished();}}}";_f.__workletHash=1734401141936;_f.__location="/Users/zhaodonghao/code/github/react-native-reanimated-carousel/src/hooks/useCarouselController.tsx (160:8)";return _f;}(),[canSliding,loop,index,dataInfo,onScrollBegin,handlerOffsetX,size,scrollWithTiming,currentFixedPage]);var prev=_react.default.useCallback(function(){var opts=arguments.length>0&&arguments[0]!==undefined?arguments[0]:{};var _opts$count2=opts.count,count=_opts$count2===void 0?1:_opts$count2,_opts$animated2=opts.animated,animated=_opts$animated2===void 0?true:_opts$animated2,onFinished=opts.onFinished;if(!canSliding()||!loop&&index.value<=0)return;onScrollBegin==null?void 0:onScrollBegin();var prevPage=currentFixedPage()-count;index.value=prevPage;if(animated){handlerOffsetX.value=scrollWithTiming(-prevPage*size,onFinished);}else{handlerOffsetX.value=-prevPage*size;onFinished==null?void 0:onFinished();}},[canSliding,loop,index,onScrollBegin,handlerOffsetX,size,scrollWithTiming,currentFixedPage]);var to=_react.default.useCallback(function(opts){var i=opts.i,_opts$animated3=opts.animated,animated=_opts$animated3===void 0?false:_opts$animated3,onFinished=opts.onFinished;if(i===index.value)return;if(!canSliding())return;onScrollBegin==null?void 0:onScrollBegin();var direction=handlerOffsetX.value/Math.abs(handlerOffsetX.value);var offset=i*size*direction;var totalSize=dataInfo.length*size;var isCloseToNextLoop=false;if(loop){isCloseToNextLoop=Math.abs(handlerOffsetX.value%totalSize)/totalSize>=0.5;}var finalOffset=(Math.floor(Math.abs(handlerOffsetX.value/totalSize))+(isCloseToNextLoop?1:0))*totalSize*direction+offset;if(animated){index.value=i;handlerOffsetX.value=scrollWithTiming(finalOffset,onFinished);}else{handlerOffsetX.value=finalOffset;index.value=i;onFinished==null?void 0:onFinished();}},[index,canSliding,onScrollBegin,handlerOffsetX,size,dataInfo.length,loop,scrollWithTiming]);var scrollTo=_react.default.useCallback(function(){var opts=arguments.length>0&&arguments[0]!==undefined?arguments[0]:{};var i=opts.index,count=opts.count,_opts$animated4=opts.animated,animated=_opts$animated4===void 0?false:_opts$animated4,onFinished=opts.onFinished;if(typeof i==='number'&&i>-1){to({i:i,animated:animated,onFinished:onFinished});return;}if(!count){return;}var n=Math.round(count);if(n<0){prev({count:Math.abs(n),animated:animated,onFinished:onFinished});}else{next({count:n,animated:animated,onFinished:onFinished});}},[prev,next,to]);return{next:next,prev:prev,scrollTo:scrollTo,getCurrentIndex:getCurrentIndex,getSharedIndex:function getSharedIndex(){return sharedIndex.current;}};}
|
|
2
2
|
//# sourceMappingURL=useCarouselController.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["useCarouselController.tsx"],"names":["useCarouselController","options","size","data","loop","handlerOffsetX","withAnimation","defaultIndex","duration","autoFillData","dataInfo","React","useMemo","length","disable","originalLength","index","sharedIndex","sharedPreIndex","currentFixedPage","useCallback","Math","round","value","fixed","abs","setSharedIndex","newSharedIndex","current","handlerOffsetXValue","toInt","isPositive","i","newSharedIndexValue","rawDataLength","convertToSharedIndex","runOnJS","getCurrentIndex","canSliding","onScrollEnd","onScrollBegin","scrollWithTiming","toValue","onFinished","callback","isFinished","defaultWithAnimation","type","config","easing","Easing","easeOutQuart","dealWithAnimation","next","opts","count","animated","nextPage","prev","prevPage","to","offset","scrollTo","n","getSharedIndex"],"mappings":"6GAAA,qDAEA,uCACA,8DAUA,6DACA,2EACA,iC,0/BAuBO,QAASA,CAAAA,qBAAT,CAA+BC,OAA/B,CAAoE,CACvE,GACIC,CAAAA,IADJ,CASID,OATJ,CACIC,IADJ,CAEIC,IAFJ,CASIF,OATJ,CAEIE,IAFJ,CAGIC,IAHJ,CASIH,OATJ,CAGIG,IAHJ,CAIIC,cAJJ,CASIJ,OATJ,CAIII,cAJJ,CAKIC,aALJ,CASIL,OAT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GAAL,CAASsC,CAAT,CAAT,CAAsBP,QAAQ,CAARA,QAAtB,CAAgCb,UAAU,CAAVA,UAAhC,CAAD,CAAJ,CACH,CAFD,IAEO,CACHU,IAAI,CAAC,CAAEE,KAAK,CAAEQ,CAAT,CAAYP,QAAQ,CAARA,QAAZ,CAAsBb,UAAU,CAAVA,UAAtB,CAAD,CAAJ,CACH,CACJ,CApBY,CAqBb,CAACe,IAAD,CAAOL,IAAP,CAAaO,EAAb,CArBa,CAAjB,CAwBA,MAAO,CACHP,IAAI,CAAJA,IADG,CAEHK,IAAI,CAAJA,IAFG,CAGHI,QAAQ,CAARA,QAHG,CAIHzB,eAAe,CAAfA,eAJG,CAKH2B,cAAc,CAAE,gCAAM/C,CAAAA,WAAW,CAACW,OAAlB,EALb,CAAP,CAOH","sourcesContent":["import React, { useRef } from 'react';\nimport type Animated from 'react-native-reanimated';\nimport { Easing } from '../constants';\nimport {\n runOnJS,\n useAnimatedReaction,\n useSharedValue,\n} from 'react-native-reanimated';\nimport type {\n TCarouselActionOptions,\n TCarouselProps,\n WithTimingAnimation,\n} from '../types';\nimport { dealWithAnimation } from '@/utils/dealWithAnimation';\nimport { convertToSharedIndex } from '@/utils/computedWithAutoFillData';\nimport { round } from '@/utils/log';\n\ninterface IOpts {\n loop: boolean;\n size: number;\n data: TCarouselProps['data'];\n autoFillData: TCarouselProps['autoFillData'];\n handlerOffsetX: Animated.SharedValue<number>;\n withAnimation?: TCarouselProps['withAnimation'];\n duration?: number;\n defaultIndex?: number;\n onScrollBegin?: () => void;\n onScrollEnd?: () => void;\n}\n\nexport interface ICarouselController {\n getSharedIndex: () => number;\n prev: (opts?: TCarouselActionOptions) => void;\n next: (opts?: TCarouselActionOptions) => void;\n getCurrentIndex: () => number;\n scrollTo: (opts?: TCarouselActionOptions) => void;\n}\n\nexport function useCarouselController(options: IOpts): ICarouselController {\n const {\n size,\n data,\n loop,\n handlerOffsetX,\n withAnimation,\n defaultIndex = 0,\n duration,\n autoFillData,\n } = options;\n\n const dataInfo = React.useMemo(\n () => ({\n length: data.length,\n disable: !data.length,\n originalLength: data.length,\n }),\n [data]\n );\n\n const index = useSharedValue<number>(defaultIndex);\n // The Index displayed to the user\n const sharedIndex = useRef<number>(defaultIndex);\n const sharedPreIndex = useRef<number>(defaultIndex);\n\n const currentFixedPage = React.useCallback(() => {\n if (loop) {\n return -Math.round(handlerOffsetX.value / size);\n }\n\n const fixed = (handlerOffsetX.value / size) % dataInfo.length;\n return Math.round(\n handlerOffsetX.value <= 0\n ? Math.abs(fixed)\n : Math.abs(fixed > 0 ? dataInfo.length - fixed : 0)\n );\n }, [handlerOffsetX, dataInfo, size, loop]);\n\n function setSharedIndex(newSharedIndex: number) {\n sharedIndex.current = newSharedIndex;\n }\n\n useAnimatedReaction(\n () => {\n const handlerOffsetXValue = handlerOffsetX.value;\n const toInt = round(handlerOffsetXValue / size) % dataInfo.length;\n const isPositive = handlerOffsetXValue <= 0;\n const i = isPositive\n ? Math.abs(toInt)\n : Math.abs(toInt > 0 ? dataInfo.length - toInt : 0);\n\n const newSharedIndexValue = convertToSharedIndex({\n loop,\n rawDataLength: dataInfo.originalLength,\n autoFillData: autoFillData!,\n index: i,\n });\n\n return {\n i,\n newSharedIndexValue,\n };\n },\n ({ i, newSharedIndexValue }) => {\n index.value = i;\n runOnJS(setSharedIndex)(newSharedIndexValue);\n },\n [\n sharedPreIndex,\n sharedIndex,\n size,\n dataInfo,\n index,\n loop,\n autoFillData,\n handlerOffsetX,\n ]\n );\n\n const getCurrentIndex = React.useCallback(() => {\n return index.value;\n }, [index]);\n\n const canSliding = React.useCallback(() => {\n return !dataInfo.disable;\n }, [dataInfo]);\n\n const onScrollEnd = React.useCallback(() => {\n options.onScrollEnd?.();\n }, [options]);\n\n const onScrollBegin = React.useCallback(() => {\n options.onScrollBegin?.();\n }, [options]);\n\n const scrollWithTiming = React.useCallback(\n (toValue: number, onFinished?: () => void) => {\n 'worklet';\n const callback = (isFinished: boolean) => {\n 'worklet';\n if (isFinished) {\n runOnJS(onScrollEnd)();\n onFinished && runOnJS(onFinished)();\n }\n };\n\n const defaultWithAnimation: WithTimingAnimation = {\n type: 'timing',\n config: { duration, easing: Easing.easeOutQuart },\n };\n\n return dealWithAnimation(withAnimation ?? defaultWithAnimation)(\n toValue,\n callback\n );\n },\n [duration, withAnimation, onScrollEnd]\n );\n\n const next = React.useCallback(\n (opts: TCarouselActionOptions = {}) => {\n 'worklet';\n const { count = 1, animated = true, onFinished } = opts;\n if (!canSliding() || (!loop && index.value >= dataInfo.length - 1))\n return;\n\n onScrollBegin?.();\n\n const nextPage = currentFixedPage() + count;\n index.value = nextPage;\n\n if (animated) {\n handlerOffsetX.value = scrollWithTiming(\n -nextPage * size,\n onFinished\n ) as any;\n } else {\n handlerOffsetX.value = -nextPage * size;\n onFinished?.();\n }\n },\n [\n canSliding,\n loop,\n index,\n dataInfo,\n onScrollBegin,\n handlerOffsetX,\n size,\n scrollWithTiming,\n currentFixedPage,\n ]\n );\n\n const prev = React.useCallback(\n (opts: TCarouselActionOptions = {}) => {\n const { count = 1, animated = true, onFinished } = opts;\n if (!canSliding() || (!loop && index.value <= 0)) return;\n\n onScrollBegin?.();\n\n const prevPage = currentFixedPage() - count;\n index.value = prevPage;\n\n if (animated) {\n handlerOffsetX.value = scrollWithTiming(\n -prevPage * size,\n onFinished\n );\n } else {\n handlerOffsetX.value = -prevPage * size;\n onFinished?.();\n }\n },\n [\n canSliding,\n loop,\n index,\n onScrollBegin,\n handlerOffsetX,\n size,\n scrollWithTiming,\n currentFixedPage,\n ]\n );\n\n const to = React.useCallback(\n (opts: { i: number; animated: boolean; onFinished?: () => void }) => {\n const { i, animated = false, onFinished } = opts;\n if (i === index.value) return;\n if (!canSliding()) return;\n\n onScrollBegin?.();\n\n const offset = handlerOffsetX.value + (index.value - i) * size;\n\n if (animated) {\n index.value = i;\n handlerOffsetX.value = scrollWithTiming(offset, onFinished);\n } else {\n handlerOffsetX.value = offset;\n index.value = i;\n onFinished?.();\n }\n },\n [\n index,\n canSliding,\n onScrollBegin,\n handlerOffsetX,\n size,\n scrollWithTiming,\n ]\n );\n\n const scrollTo = React.useCallback(\n (opts: TCarouselActionOptions = {}) => {\n const { index: i, count, animated = false, onFinished } = opts;\n\n if (typeof i === 'number' && i > -1) {\n to({ i, animated, onFinished });\n return;\n }\n\n if (!count) {\n return;\n }\n\n const n = Math.round(count);\n\n if (n < 0) {\n prev({ count: Math.abs(n), animated, onFinished });\n } else {\n next({ count: n, animated, onFinished });\n }\n },\n [prev, next, to]\n );\n\n return {\n next,\n prev,\n scrollTo,\n getCurrentIndex,\n getSharedIndex: () => sharedIndex.current,\n };\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["useCarouselController.tsx"],"names":["useCarouselController","options","size","data","loop","handlerOffsetX","withAnimation","defaultIndex","duration","autoFillData","dataInfo","React","useMemo","length","disable","originalLength","index","sharedIndex","sharedPreIndex","currentFixedPage","useCallback","Math","round","value","fixed","abs","setSharedIndex","newSharedIndex","current","handlerOffsetXValue","toInt","isPositive","i","newSharedIndexValue","rawDataLength","convertToSharedIndex","runOnJS","getCurrentIndex","canSliding","onScrollEnd","onScrollBegin","scrollWithTiming","toValue","onFinished","callback","isFinished","defaultWithAnimation","type","config","easing","Easing","easeOutQuart","dealWithAnimation","next","opts","count","animated","nextPage","prev","prevPage","to","direction","offset","totalSize","isCloseToNextLoop","finalOffset","floor","scrollTo","n","getSharedIndex"],"mappings":"6GAAA,qDAEA,uCACA,8DAUA,6DACA,2EACA,iC,0/BAuBO,QAASA,CAAAA,qBAAT,CAA+BC,OAA/B,CAAoE,CACvE,GACIC,CAAAA,IADJ,CASID,OATJ,CACIC,IADJ,CAEIC,IAFJ,CASIF,OATJ,CAEIE,IAFJ,CAGIC,IAHJ,CASIH,OATJ,CAGIG,IAHJ,CAIIC,cAJJ,CASIJ,OATJ,CAIII,cAJJ,CAKIC,aALJ,CASIL,OATJ,CAKIK,aALJ,uBASIL,OATJ,CAMIM,YANJ,CAMI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,IAA1D,CAAkBC,KAAlB,iBAA0DD,IAA1D,CAAyBE,QAAzB,CAAyBA,QAAzB,0BAAoC,KAApC,iBAA2Cb,UAA3C,CAA0DW,IAA1D,CAA2CX,UAA3C,CACA,GAAI,MAAOX,CAAAA,CAAP,GAAa,QAAb,EAAyBA,CAAC,CAAG,CAAC,CAAlC,CAAqC,CACjC4B,EAAE,CAAC,CAAE5B,CAAC,CAADA,CAAF,CAAKwB,QAAQ,CAARA,QAAL,CAAeb,UAAU,CAAVA,UAAf,CAAD,CAAF,CACA,OACH,CAED,GAAI,CAACY,KAAL,CAAY,CACR,OACH,CAED,GAAMa,CAAAA,CAAC,CAAG/C,IAAI,CAACC,KAAL,CAAWiC,KAAX,CAAV,CAEA,GAAIa,CAAC,CAAG,CAAR,CAAW,CACPV,IAAI,CAAC,CAAEH,KAAK,CAAElC,IAAI,CAACI,GAAL,CAAS2C,CAAT,CAAT,CAAsBZ,QAAQ,CAARA,QAAtB,CAAgCb,UAAU,CAAVA,UAAhC,CAAD,CAAJ,CACH,CAFD,IAEO,CACHU,IAAI,CAAC,CAAEE,KAAK,CAAEa,CAAT,CAAYZ,QAAQ,CAARA,QAAZ,CAAsBb,UAAU,CAAVA,UAAtB,CAAD,CAAJ,CACH,CACJ,CAnBY,CAoBb,CAACe,IAAD,CAAOL,IAAP,CAAaO,EAAb,CApBa,CAAjB,CAuBA,MAAO,CACHP,IAAI,CAAJA,IADG,CAEHK,IAAI,CAAJA,IAFG,CAGHS,QAAQ,CAARA,QAHG,CAIH9B,eAAe,CAAfA,eAJG,CAKHgC,cAAc,CAAE,gCAAMpD,CAAAA,WAAW,CAACW,OAAlB,EALb,CAAP,CAOH","sourcesContent":["import React, { useRef } from 'react';\nimport type Animated from 'react-native-reanimated';\nimport { Easing } from '../constants';\nimport {\n runOnJS,\n useAnimatedReaction,\n useSharedValue,\n} from 'react-native-reanimated';\nimport type {\n TCarouselActionOptions,\n TCarouselProps,\n WithTimingAnimation,\n} from '../types';\nimport { dealWithAnimation } from '../utils/dealWithAnimation';\nimport { convertToSharedIndex } from '../utils/computedWithAutoFillData';\nimport { round } from '../utils/log';\n\ninterface IOpts {\n loop: boolean;\n size: number;\n data: TCarouselProps['data'];\n autoFillData: TCarouselProps['autoFillData'];\n handlerOffsetX: Animated.SharedValue<number>;\n withAnimation?: TCarouselProps['withAnimation'];\n duration?: number;\n defaultIndex?: number;\n onScrollBegin?: () => void;\n onScrollEnd?: () => void;\n}\n\nexport interface ICarouselController {\n getSharedIndex: () => number;\n prev: (opts?: TCarouselActionOptions) => void;\n next: (opts?: TCarouselActionOptions) => void;\n getCurrentIndex: () => number;\n scrollTo: (opts?: TCarouselActionOptions) => void;\n}\n\nexport function useCarouselController(options: IOpts): ICarouselController {\n const {\n size,\n data,\n loop,\n handlerOffsetX,\n withAnimation,\n defaultIndex = 0,\n duration,\n autoFillData,\n } = options;\n\n const dataInfo = React.useMemo(\n () => ({\n length: data.length,\n disable: !data.length,\n originalLength: data.length,\n }),\n [data]\n );\n\n const index = useSharedValue<number>(defaultIndex);\n // The Index displayed to the user\n const sharedIndex = useRef<number>(defaultIndex);\n const sharedPreIndex = useRef<number>(defaultIndex);\n\n const currentFixedPage = React.useCallback(() => {\n if (loop) {\n return -Math.round(handlerOffsetX.value / size);\n }\n\n const fixed = (handlerOffsetX.value / size) % dataInfo.length;\n return Math.round(\n handlerOffsetX.value <= 0\n ? Math.abs(fixed)\n : Math.abs(fixed > 0 ? dataInfo.length - fixed : 0)\n );\n }, [handlerOffsetX, dataInfo, size, loop]);\n\n function setSharedIndex(newSharedIndex: number) {\n sharedIndex.current = newSharedIndex;\n }\n\n useAnimatedReaction(\n () => {\n const handlerOffsetXValue = handlerOffsetX.value;\n const toInt = round(handlerOffsetXValue / size) % dataInfo.length;\n const isPositive = handlerOffsetXValue <= 0;\n const i = isPositive\n ? Math.abs(toInt)\n : Math.abs(toInt > 0 ? dataInfo.length - toInt : 0);\n\n const newSharedIndexValue = convertToSharedIndex({\n loop,\n rawDataLength: dataInfo.originalLength,\n autoFillData: autoFillData!,\n index: i,\n });\n\n return {\n i,\n newSharedIndexValue,\n };\n },\n ({ i, newSharedIndexValue }) => {\n index.value = i;\n runOnJS(setSharedIndex)(newSharedIndexValue);\n },\n [\n sharedPreIndex,\n sharedIndex,\n size,\n dataInfo,\n index,\n loop,\n autoFillData,\n handlerOffsetX,\n ]\n );\n\n const getCurrentIndex = React.useCallback(() => {\n return index.value;\n }, [index]);\n\n const canSliding = React.useCallback(() => {\n return !dataInfo.disable;\n }, [dataInfo]);\n\n const onScrollEnd = React.useCallback(() => {\n options.onScrollEnd?.();\n }, [options]);\n\n const onScrollBegin = React.useCallback(() => {\n options.onScrollBegin?.();\n }, [options]);\n\n const scrollWithTiming = React.useCallback(\n (toValue: number, onFinished?: () => void) => {\n 'worklet';\n const callback = (isFinished: boolean) => {\n 'worklet';\n if (isFinished) {\n runOnJS(onScrollEnd)();\n onFinished && runOnJS(onFinished)();\n }\n };\n\n const defaultWithAnimation: WithTimingAnimation = {\n type: 'timing',\n config: { duration, easing: Easing.easeOutQuart },\n };\n\n return dealWithAnimation(withAnimation ?? defaultWithAnimation)(\n toValue,\n callback\n );\n },\n [duration, withAnimation, onScrollEnd]\n );\n\n const next = React.useCallback(\n (opts: TCarouselActionOptions = {}) => {\n 'worklet';\n const { count = 1, animated = true, onFinished } = opts;\n if (!canSliding() || (!loop && index.value >= dataInfo.length - 1))\n return;\n\n onScrollBegin?.();\n\n const nextPage = currentFixedPage() + count;\n index.value = nextPage;\n\n if (animated) {\n handlerOffsetX.value = scrollWithTiming(\n -nextPage * size,\n onFinished\n ) as any;\n } else {\n handlerOffsetX.value = -nextPage * size;\n onFinished?.();\n }\n },\n [\n canSliding,\n loop,\n index,\n dataInfo,\n onScrollBegin,\n handlerOffsetX,\n size,\n scrollWithTiming,\n currentFixedPage,\n ]\n );\n\n const prev = React.useCallback(\n (opts: TCarouselActionOptions = {}) => {\n const { count = 1, animated = true, onFinished } = opts;\n if (!canSliding() || (!loop && index.value <= 0)) return;\n\n onScrollBegin?.();\n\n const prevPage = currentFixedPage() - count;\n index.value = prevPage;\n\n if (animated) {\n handlerOffsetX.value = scrollWithTiming(\n -prevPage * size,\n onFinished\n );\n } else {\n handlerOffsetX.value = -prevPage * size;\n onFinished?.();\n }\n },\n [\n canSliding,\n loop,\n index,\n onScrollBegin,\n handlerOffsetX,\n size,\n scrollWithTiming,\n currentFixedPage,\n ]\n );\n\n const to = React.useCallback(\n (opts: { i: number; animated: boolean; onFinished?: () => void }) => {\n const { i, animated = false, onFinished } = opts;\n if (i === index.value) return;\n if (!canSliding()) return;\n\n onScrollBegin?.();\n // direction -> 1 | -1\n const direction =\n handlerOffsetX.value / Math.abs(handlerOffsetX.value);\n // target offset\n const offset = i * size * direction;\n // page width size * page count\n const totalSize = dataInfo.length * size;\n\n let isCloseToNextLoop = false;\n\n if (loop) {\n isCloseToNextLoop =\n Math.abs(handlerOffsetX.value % totalSize) / totalSize >=\n 0.5;\n }\n\n const finalOffset =\n (Math.floor(Math.abs(handlerOffsetX.value / totalSize)) +\n (isCloseToNextLoop ? 1 : 0)) *\n totalSize *\n direction +\n offset;\n\n if (animated) {\n index.value = i;\n handlerOffsetX.value = scrollWithTiming(\n finalOffset,\n onFinished\n );\n } else {\n handlerOffsetX.value = finalOffset;\n index.value = i;\n onFinished?.();\n }\n },\n [\n index,\n canSliding,\n onScrollBegin,\n handlerOffsetX,\n size,\n dataInfo.length,\n loop,\n scrollWithTiming,\n ]\n );\n\n const scrollTo = React.useCallback(\n (opts: TCarouselActionOptions = {}) => {\n const { index: i, count, animated = false, onFinished } = opts;\n if (typeof i === 'number' && i > -1) {\n to({ i, animated, onFinished });\n return;\n }\n\n if (!count) {\n return;\n }\n\n const n = Math.round(count);\n\n if (n < 0) {\n prev({ count: Math.abs(n), animated, onFinished });\n } else {\n next({ count: n, animated, onFinished });\n }\n },\n [prev, next, to]\n );\n\n return {\n next,\n prev,\n scrollTo,\n getCurrentIndex,\n getSharedIndex: () => sharedIndex.current,\n };\n}\n"]}
|