react-native-reanimated-carousel 2.2.3 → 2.2.5-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/README.zh-CN.md +1 -1
- package/lib/commonjs/Carousel.js +1 -227
- package/lib/commonjs/Carousel.js.map +1 -1
- package/lib/commonjs/LazyView.js +1 -25
- package/lib/commonjs/LazyView.js.map +1 -1
- package/lib/commonjs/ScrollViewGesture.js +1 -225
- package/lib/commonjs/ScrollViewGesture.js.map +1 -1
- package/lib/commonjs/constants/index.js +1 -21
- package/lib/commonjs/constants/index.js.map +1 -1
- package/lib/commonjs/hooks/useAutoPlay.js +1 -65
- package/lib/commonjs/hooks/useAutoPlay.js.map +1 -1
- package/lib/commonjs/hooks/useCarouselController.js +1 -194
- package/lib/commonjs/hooks/useCarouselController.js.map +1 -1
- package/lib/commonjs/hooks/useCommonVariables.js +1 -36
- package/lib/commonjs/hooks/useCommonVariables.js.map +1 -1
- package/lib/commonjs/hooks/useInitProps.js +1 -70
- package/lib/commonjs/hooks/useInitProps.js.map +1 -1
- package/lib/commonjs/hooks/useLayoutConfig.js +1 -39
- package/lib/commonjs/hooks/useLayoutConfig.js.map +1 -1
- package/lib/commonjs/hooks/useOffsetX.js +1 -54
- package/lib/commonjs/hooks/useOffsetX.js.map +1 -1
- package/lib/commonjs/hooks/useOnProgressChange.js +1 -38
- package/lib/commonjs/hooks/useOnProgressChange.js.map +1 -1
- package/lib/commonjs/hooks/usePropsErrorBoundary.js +1 -37
- package/lib/commonjs/hooks/usePropsErrorBoundary.js.map +1 -1
- package/lib/commonjs/hooks/useVisibleRanges.js +1 -42
- package/lib/commonjs/hooks/useVisibleRanges.js.map +1 -1
- package/lib/commonjs/index.js +1 -13
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/layouts/BaseLayout.js +1 -100
- package/lib/commonjs/layouts/BaseLayout.js.map +1 -1
- package/lib/commonjs/layouts/ParallaxLayout.js +1 -82
- package/lib/commonjs/layouts/ParallaxLayout.js.map +1 -1
- package/lib/commonjs/layouts/index.js +1 -20
- package/lib/commonjs/layouts/index.js.map +1 -1
- package/lib/commonjs/layouts/normal.js +1 -27
- package/lib/commonjs/layouts/normal.js.map +1 -1
- package/lib/commonjs/layouts/parallax.js +1 -36
- package/lib/commonjs/layouts/parallax.js.map +1 -1
- package/lib/commonjs/layouts/stack.js +1 -219
- package/lib/commonjs/layouts/stack.js.map +1 -1
- package/lib/commonjs/store/index.js +1 -14
- package/lib/commonjs/store/index.js.map +1 -1
- package/lib/commonjs/types.js +1 -5
- package/lib/commonjs/utils/dealWithAnimation.js +2 -0
- package/lib/commonjs/utils/dealWithAnimation.js.map +1 -0
- package/lib/commonjs/utils/log.js +1 -14
- package/lib/commonjs/utils/log.js.map +1 -1
- package/lib/module/Carousel.js +5 -5
- package/lib/module/Carousel.js.map +1 -1
- package/lib/module/ScrollViewGesture.js +23 -12
- package/lib/module/ScrollViewGesture.js.map +1 -1
- package/lib/module/hooks/useCarouselController.js +21 -7
- package/lib/module/hooks/useCarouselController.js.map +1 -1
- package/lib/module/layouts/BaseLayout.js +2 -1
- package/lib/module/layouts/BaseLayout.js.map +1 -1
- package/lib/module/layouts/stack.js.map +1 -1
- package/lib/module/utils/dealWithAnimation.js +17 -0
- package/lib/module/utils/dealWithAnimation.js.map +1 -0
- package/lib/typescript/Carousel.d.ts +3 -4
- package/lib/typescript/hooks/useCarouselController.d.ts +2 -1
- package/lib/typescript/layouts/BaseLayout.d.ts +2 -2
- package/lib/typescript/layouts/stack.d.ts +1 -1
- package/lib/typescript/types.d.ts +14 -2
- package/lib/typescript/utils/dealWithAnimation.d.ts +2 -0
- package/package.json +12 -3
- package/src/Carousel.tsx +203 -194
- package/src/ScrollViewGesture.tsx +22 -12
- package/src/hooks/useCarouselController.tsx +28 -12
- package/src/layouts/BaseLayout.tsx +3 -3
- package/src/layouts/stack.ts +1 -1
- package/src/types.ts +22 -4
- package/src/utils/dealWithAnimation.ts +22 -0
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@ English | [简体中文](./README.zh-CN.md)
|
|
|
2
2
|
|
|
3
3
|
# react-native-reanimated-carousel
|
|
4
4
|
|
|
5
|
-
<img src="assets/banner.png" width="100%"/>
|
|
5
|
+
<img src="assets/home-banner.png" width="100%"/>
|
|
6
6
|
|
|
7
7
|

|
|
8
8
|
[](https://www.npmjs.com/package/react-native-reanimated-carousel)
|
package/README.zh-CN.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
# react-native-reanimated-carousel
|
|
4
4
|
|
|
5
|
-
<img src="assets/banner-zh.
|
|
5
|
+
<img src="assets/home-banner-zh.png" width="100%"/>
|
|
6
6
|
|
|
7
7
|

|
|
8
8
|
[](https://www.npmjs.com/package/react-native-reanimated-carousel)
|
package/lib/commonjs/Carousel.js
CHANGED
|
@@ -1,228 +1,2 @@
|
|
|
1
|
-
"
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
|
|
8
|
-
var _react = _interopRequireDefault(require("react"));
|
|
9
|
-
|
|
10
|
-
var _reactNativeReanimated = _interopRequireWildcard(require("react-native-reanimated"));
|
|
11
|
-
|
|
12
|
-
var _useCarouselController = require("./hooks/useCarouselController");
|
|
13
|
-
|
|
14
|
-
var _useAutoPlay = require("./hooks/useAutoPlay");
|
|
15
|
-
|
|
16
|
-
var _usePropsErrorBoundary = require("./hooks/usePropsErrorBoundary");
|
|
17
|
-
|
|
18
|
-
var _ScrollViewGesture = require("./ScrollViewGesture");
|
|
19
|
-
|
|
20
|
-
var _useVisibleRanges = require("./hooks/useVisibleRanges");
|
|
21
|
-
|
|
22
|
-
var _reactNative = require("react-native");
|
|
23
|
-
|
|
24
|
-
var _constants = require("./constants");
|
|
25
|
-
|
|
26
|
-
var _BaseLayout = require("./layouts/BaseLayout");
|
|
27
|
-
|
|
28
|
-
var _useLayoutConfig = require("./hooks/useLayoutConfig");
|
|
29
|
-
|
|
30
|
-
var _useInitProps = require("./hooks/useInitProps");
|
|
31
|
-
|
|
32
|
-
var _store = require("./store");
|
|
33
|
-
|
|
34
|
-
var _useCommonVariables = require("./hooks/useCommonVariables");
|
|
35
|
-
|
|
36
|
-
var _useOnProgressChange = require("./hooks/useOnProgressChange");
|
|
37
|
-
|
|
38
|
-
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
39
|
-
|
|
40
|
-
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; }
|
|
41
|
-
|
|
42
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
43
|
-
|
|
44
|
-
function Carousel(_props, ref) {
|
|
45
|
-
const props = (0, _useInitProps.useInitProps)(_props);
|
|
46
|
-
const {
|
|
47
|
-
data,
|
|
48
|
-
rawData,
|
|
49
|
-
loop,
|
|
50
|
-
mode,
|
|
51
|
-
style,
|
|
52
|
-
width,
|
|
53
|
-
height,
|
|
54
|
-
vertical,
|
|
55
|
-
autoPlay,
|
|
56
|
-
windowSize,
|
|
57
|
-
autoPlayReverse,
|
|
58
|
-
autoPlayInterval,
|
|
59
|
-
scrollAnimationDuration,
|
|
60
|
-
renderItem,
|
|
61
|
-
onScrollEnd,
|
|
62
|
-
onSnapToItem,
|
|
63
|
-
onScrollBegin,
|
|
64
|
-
onProgressChange,
|
|
65
|
-
customAnimation
|
|
66
|
-
} = props;
|
|
67
|
-
const commonVariables = (0, _useCommonVariables.useCommonVariables)(props);
|
|
68
|
-
const {
|
|
69
|
-
size,
|
|
70
|
-
handlerOffsetX
|
|
71
|
-
} = commonVariables;
|
|
72
|
-
const offsetX = (0, _reactNativeReanimated.useDerivedValue)(() => {
|
|
73
|
-
const totalSize = size * data.length;
|
|
74
|
-
const x = handlerOffsetX.value % totalSize;
|
|
75
|
-
|
|
76
|
-
if (!loop) {
|
|
77
|
-
return handlerOffsetX.value;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
return isNaN(x) ? 0 : x;
|
|
81
|
-
}, [loop, size, data]);
|
|
82
|
-
(0, _usePropsErrorBoundary.usePropsErrorBoundary)(props);
|
|
83
|
-
(0, _useOnProgressChange.useOnProgressChange)({
|
|
84
|
-
size,
|
|
85
|
-
offsetX,
|
|
86
|
-
rawData,
|
|
87
|
-
onProgressChange
|
|
88
|
-
});
|
|
89
|
-
const carouselController = (0, _useCarouselController.useCarouselController)({
|
|
90
|
-
loop,
|
|
91
|
-
size,
|
|
92
|
-
handlerOffsetX,
|
|
93
|
-
length: data.length,
|
|
94
|
-
disable: !data.length,
|
|
95
|
-
originalLength: data.length,
|
|
96
|
-
onScrollEnd: () => (0, _reactNativeReanimated.runOnJS)(_onScrollEnd)(),
|
|
97
|
-
onScrollBegin: () => !!onScrollBegin && (0, _reactNativeReanimated.runOnJS)(onScrollBegin)(),
|
|
98
|
-
onChange: i => !!onSnapToItem && (0, _reactNativeReanimated.runOnJS)(onSnapToItem)(i),
|
|
99
|
-
duration: scrollAnimationDuration
|
|
100
|
-
});
|
|
101
|
-
const {
|
|
102
|
-
next,
|
|
103
|
-
prev,
|
|
104
|
-
sharedPreIndex,
|
|
105
|
-
sharedIndex,
|
|
106
|
-
computedIndex,
|
|
107
|
-
getCurrentIndex
|
|
108
|
-
} = carouselController;
|
|
109
|
-
const {
|
|
110
|
-
start,
|
|
111
|
-
pause
|
|
112
|
-
} = (0, _useAutoPlay.useAutoPlay)({
|
|
113
|
-
autoPlay,
|
|
114
|
-
autoPlayInterval,
|
|
115
|
-
autoPlayReverse,
|
|
116
|
-
carouselController
|
|
117
|
-
});
|
|
118
|
-
|
|
119
|
-
const _onScrollEnd = _react.default.useCallback(() => {
|
|
120
|
-
computedIndex();
|
|
121
|
-
onScrollEnd === null || onScrollEnd === void 0 ? void 0 : onScrollEnd(sharedPreIndex.current, sharedIndex.current);
|
|
122
|
-
}, [sharedPreIndex, sharedIndex, computedIndex, onScrollEnd]);
|
|
123
|
-
|
|
124
|
-
const scrollViewGestureOnScrollBegin = _react.default.useCallback(() => {
|
|
125
|
-
pause();
|
|
126
|
-
onScrollBegin === null || onScrollBegin === void 0 ? void 0 : onScrollBegin();
|
|
127
|
-
}, [onScrollBegin, pause]);
|
|
128
|
-
|
|
129
|
-
const scrollViewGestureOnScrollEnd = _react.default.useCallback(() => {
|
|
130
|
-
start();
|
|
131
|
-
|
|
132
|
-
_onScrollEnd();
|
|
133
|
-
}, [_onScrollEnd, start]);
|
|
134
|
-
|
|
135
|
-
const scrollViewGestureOnTouchBegin = _react.default.useCallback(pause, [pause]);
|
|
136
|
-
|
|
137
|
-
const scrollViewGestureOnTouchEnd = _react.default.useCallback(start, [start]);
|
|
138
|
-
|
|
139
|
-
const goToIndex = _react.default.useCallback((i, animated) => {
|
|
140
|
-
carouselController.to(i, animated);
|
|
141
|
-
}, [carouselController]);
|
|
142
|
-
|
|
143
|
-
_react.default.useImperativeHandle(ref, () => ({
|
|
144
|
-
next,
|
|
145
|
-
prev,
|
|
146
|
-
getCurrentIndex,
|
|
147
|
-
goToIndex,
|
|
148
|
-
scrollTo: carouselController.scrollTo
|
|
149
|
-
}), [getCurrentIndex, goToIndex, next, prev, carouselController.scrollTo]);
|
|
150
|
-
|
|
151
|
-
const visibleRanges = (0, _useVisibleRanges.useVisibleRanges)({
|
|
152
|
-
total: data.length,
|
|
153
|
-
viewSize: size,
|
|
154
|
-
translation: handlerOffsetX,
|
|
155
|
-
windowSize
|
|
156
|
-
});
|
|
157
|
-
const layoutConfig = (0, _useLayoutConfig.useLayoutConfig)({ ...props,
|
|
158
|
-
size
|
|
159
|
-
});
|
|
160
|
-
|
|
161
|
-
const renderLayout = _react.default.useCallback((item, i) => {
|
|
162
|
-
let realIndex = i;
|
|
163
|
-
|
|
164
|
-
if (rawData.length === _constants.DATA_LENGTH.SINGLE_ITEM) {
|
|
165
|
-
realIndex = i % 1;
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
if (rawData.length === _constants.DATA_LENGTH.DOUBLE_ITEM) {
|
|
169
|
-
realIndex = i % 2;
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
return /*#__PURE__*/_react.default.createElement(_BaseLayout.BaseLayout, {
|
|
173
|
-
key: i,
|
|
174
|
-
index: i,
|
|
175
|
-
handlerOffsetX: offsetX,
|
|
176
|
-
visibleRanges: visibleRanges,
|
|
177
|
-
animationStyle: customAnimation || layoutConfig
|
|
178
|
-
}, ({
|
|
179
|
-
animationValue
|
|
180
|
-
}) => renderItem({
|
|
181
|
-
item,
|
|
182
|
-
index: realIndex,
|
|
183
|
-
animationValue
|
|
184
|
-
}));
|
|
185
|
-
}, [rawData, offsetX, visibleRanges, renderItem, layoutConfig, customAnimation]);
|
|
186
|
-
|
|
187
|
-
return /*#__PURE__*/_react.default.createElement(_store.CTX.Provider, {
|
|
188
|
-
value: {
|
|
189
|
-
props,
|
|
190
|
-
common: commonVariables
|
|
191
|
-
}
|
|
192
|
-
}, /*#__PURE__*/_react.default.createElement(_reactNative.View, {
|
|
193
|
-
style: [styles.container, {
|
|
194
|
-
width: width || '100%',
|
|
195
|
-
height: height || '100%'
|
|
196
|
-
}, style]
|
|
197
|
-
}, /*#__PURE__*/_react.default.createElement(_ScrollViewGesture.ScrollViewGesture, {
|
|
198
|
-
size: size,
|
|
199
|
-
translation: handlerOffsetX,
|
|
200
|
-
onScrollBegin: scrollViewGestureOnScrollBegin,
|
|
201
|
-
onScrollEnd: scrollViewGestureOnScrollEnd,
|
|
202
|
-
onTouchBegin: scrollViewGestureOnTouchBegin,
|
|
203
|
-
onTouchEnd: scrollViewGestureOnTouchEnd
|
|
204
|
-
}, /*#__PURE__*/_react.default.createElement(_reactNativeReanimated.default.View, {
|
|
205
|
-
key: mode,
|
|
206
|
-
style: [styles.container, {
|
|
207
|
-
width: width || '100%',
|
|
208
|
-
height: height || '100%'
|
|
209
|
-
}, style, vertical ? styles.itemsVertical : styles.itemsHorizontal]
|
|
210
|
-
}, data.map(renderLayout)))));
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
var _default = /*#__PURE__*/_react.default.forwardRef(Carousel);
|
|
214
|
-
|
|
215
|
-
exports.default = _default;
|
|
216
|
-
|
|
217
|
-
const styles = _reactNative.StyleSheet.create({
|
|
218
|
-
container: {
|
|
219
|
-
overflow: 'hidden'
|
|
220
|
-
},
|
|
221
|
-
itemsHorizontal: {
|
|
222
|
-
flexDirection: 'row'
|
|
223
|
-
},
|
|
224
|
-
itemsVertical: {
|
|
225
|
-
flexDirection: 'column'
|
|
226
|
-
}
|
|
227
|
-
});
|
|
1
|
+
var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports,"__esModule",{value:true});exports.default=void 0;var _defineProperty2=_interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));var _react=_interopRequireDefault(require("react"));var _reactNativeReanimated=_interopRequireWildcard(require("react-native-reanimated"));var _useCarouselController=require("./hooks/useCarouselController");var _useAutoPlay2=require("./hooks/useAutoPlay");var _usePropsErrorBoundary=require("./hooks/usePropsErrorBoundary");var _ScrollViewGesture=require("./ScrollViewGesture");var _useVisibleRanges=require("./hooks/useVisibleRanges");var _reactNative=require("react-native");var _constants=require("./constants");var _BaseLayout=require("./layouts/BaseLayout");var _useLayoutConfig=require("./hooks/useLayoutConfig");var _useInitProps=require("./hooks/useInitProps");var _store=require("./store");var _useCommonVariables=require("./hooks/useCommonVariables");var _useOnProgressChange=require("./hooks/useOnProgressChange");var _this=this,_jsxFileName="/Users/zhaodonghao/code/react-native-reanimated-carousel/src/Carousel.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;}function ownKeys(object,enumerableOnly){var keys=Object.keys(object);if(Object.getOwnPropertySymbols){var symbols=Object.getOwnPropertySymbols(object);if(enumerableOnly){symbols=symbols.filter(function(sym){return Object.getOwnPropertyDescriptor(object,sym).enumerable;});}keys.push.apply(keys,symbols);}return keys;}function _objectSpread(target){for(var i=1;i<arguments.length;i++){var source=arguments[i]!=null?arguments[i]:{};if(i%2){ownKeys(Object(source),true).forEach(function(key){(0,_defineProperty2.default)(target,key,source[key]);});}else if(Object.getOwnPropertyDescriptors){Object.defineProperties(target,Object.getOwnPropertyDescriptors(source));}else{ownKeys(Object(source)).forEach(function(key){Object.defineProperty(target,key,Object.getOwnPropertyDescriptor(source,key));});}}return target;}var Carousel=_react.default.forwardRef(function(_props,ref){var props=(0,_useInitProps.useInitProps)(_props);var data=props.data,rawData=props.rawData,loop=props.loop,mode=props.mode,style=props.style,width=props.width,height=props.height,vertical=props.vertical,autoPlay=props.autoPlay,windowSize=props.windowSize,autoPlayReverse=props.autoPlayReverse,autoPlayInterval=props.autoPlayInterval,scrollAnimationDuration=props.scrollAnimationDuration,withAnimation=props.withAnimation,renderItem=props.renderItem,onScrollEnd=props.onScrollEnd,onSnapToItem=props.onSnapToItem,_onScrollBegin=props.onScrollBegin,onProgressChange=props.onProgressChange,customAnimation=props.customAnimation;var commonVariables=(0,_useCommonVariables.useCommonVariables)(props);var size=commonVariables.size,handlerOffsetX=commonVariables.handlerOffsetX;var offsetX=(0,_reactNativeReanimated.useDerivedValue)(function(){var _f=function _f(){var totalSize=size*data.length;var x=handlerOffsetX.value%totalSize;if(!loop){return handlerOffsetX.value;}return isNaN(x)?0:x;};_f._closure={size:size,data:data,handlerOffsetX:handlerOffsetX,loop:loop};_f.asString="function _f(){const{size,data,handlerOffsetX,loop}=jsThis._closure;{const totalSize=size*data.length;const x=handlerOffsetX.value%totalSize;if(!loop){return handlerOffsetX.value;}return isNaN(x)?0:x;}}";_f.__workletHash=3891980848773;_f.__location="/Users/zhaodonghao/code/react-native-reanimated-carousel/src/Carousel.tsx (50:40)";global.__reanimatedWorkletInit(_f);return _f;}(),[loop,size,data]);(0,_usePropsErrorBoundary.usePropsErrorBoundary)(props);(0,_useOnProgressChange.useOnProgressChange)({size:size,offsetX:offsetX,rawData:rawData,onProgressChange:onProgressChange});var carouselController=(0,_useCarouselController.useCarouselController)({loop:loop,size:size,handlerOffsetX:handlerOffsetX,length:data.length,disable:!data.length,withAnimation:withAnimation,originalLength:data.length,onScrollEnd:function onScrollEnd(){return(0,_reactNativeReanimated.runOnJS)(_onScrollEnd)();},onScrollBegin:function onScrollBegin(){return!!_onScrollBegin&&(0,_reactNativeReanimated.runOnJS)(_onScrollBegin)();},onChange:function onChange(i){return!!onSnapToItem&&(0,_reactNativeReanimated.runOnJS)(onSnapToItem)(i);},duration:scrollAnimationDuration});var next=carouselController.next,prev=carouselController.prev,sharedPreIndex=carouselController.sharedPreIndex,sharedIndex=carouselController.sharedIndex,computedIndex=carouselController.computedIndex,getCurrentIndex=carouselController.getCurrentIndex;var _useAutoPlay=(0,_useAutoPlay2.useAutoPlay)({autoPlay:autoPlay,autoPlayInterval:autoPlayInterval,autoPlayReverse:autoPlayReverse,carouselController:carouselController}),start=_useAutoPlay.start,pause=_useAutoPlay.pause;var _onScrollEnd=_react.default.useCallback(function(){computedIndex();onScrollEnd==null?void 0:onScrollEnd(sharedPreIndex.current,sharedIndex.current);},[sharedPreIndex,sharedIndex,computedIndex,onScrollEnd]);var scrollViewGestureOnScrollBegin=_react.default.useCallback(function(){pause();_onScrollBegin==null?void 0:_onScrollBegin();},[_onScrollBegin,pause]);var scrollViewGestureOnScrollEnd=_react.default.useCallback(function(){start();_onScrollEnd();},[_onScrollEnd,start]);var scrollViewGestureOnTouchBegin=_react.default.useCallback(pause,[pause]);var scrollViewGestureOnTouchEnd=_react.default.useCallback(start,[start]);var goToIndex=_react.default.useCallback(function(i,animated){carouselController.to(i,animated);},[carouselController]);_react.default.useImperativeHandle(ref,function(){return{next:next,prev:prev,getCurrentIndex:getCurrentIndex,goToIndex:goToIndex,scrollTo:carouselController.scrollTo};},[getCurrentIndex,goToIndex,next,prev,carouselController.scrollTo]);var visibleRanges=(0,_useVisibleRanges.useVisibleRanges)({total:data.length,viewSize:size,translation:handlerOffsetX,windowSize:windowSize});var layoutConfig=(0,_useLayoutConfig.useLayoutConfig)(_objectSpread(_objectSpread({},props),{},{size:size}));var renderLayout=_react.default.useCallback(function(item,i){var realIndex=i;if(rawData.length===_constants.DATA_LENGTH.SINGLE_ITEM){realIndex=i%1;}if(rawData.length===_constants.DATA_LENGTH.DOUBLE_ITEM){realIndex=i%2;}return _react.default.createElement(_BaseLayout.BaseLayout,{key:i,index:i,handlerOffsetX:offsetX,visibleRanges:visibleRanges,animationStyle:customAnimation||layoutConfig,__self:_this,__source:{fileName:_jsxFileName,lineNumber:158,columnNumber:21}},function(_ref){var animationValue=_ref.animationValue;return renderItem({item:item,index:realIndex,animationValue:animationValue});});},[rawData,offsetX,visibleRanges,renderItem,layoutConfig,customAnimation]);return _react.default.createElement(_store.CTX.Provider,{value:{props:props,common:commonVariables},__self:_this,__source:{fileName:_jsxFileName,lineNumber:186,columnNumber:13}},_react.default.createElement(_reactNative.View,{style:[styles.container,{width:width||'100%',height:height||'100%'},style],__self:_this,__source:{fileName:_jsxFileName,lineNumber:187,columnNumber:17}},_react.default.createElement(_ScrollViewGesture.ScrollViewGesture,{size:size,translation:handlerOffsetX,onScrollBegin:scrollViewGestureOnScrollBegin,onScrollEnd:scrollViewGestureOnScrollEnd,onTouchBegin:scrollViewGestureOnTouchBegin,onTouchEnd:scrollViewGestureOnTouchEnd,__self:_this,__source:{fileName:_jsxFileName,lineNumber:194,columnNumber:21}},_react.default.createElement(_reactNativeReanimated.default.View,{key:mode,style:[styles.container,{width:width||'100%',height:height||'100%'},style,vertical?styles.itemsVertical:styles.itemsHorizontal],__self:_this,__source:{fileName:_jsxFileName,lineNumber:202,columnNumber:25}},data.map(renderLayout)))));});var _default=Carousel;exports.default=_default;var styles=_reactNative.StyleSheet.create({container:{overflow:'hidden'},itemsHorizontal:{flexDirection:'row'},itemsVertical:{flexDirection:'column'}});
|
|
228
2
|
//# sourceMappingURL=Carousel.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["Carousel.tsx"],"names":["Carousel","_props","ref","props","data","rawData","loop","mode","style","width","height","vertical","autoPlay","windowSize","autoPlayReverse","autoPlayInterval","scrollAnimationDuration","renderItem","onScrollEnd","onSnapToItem","onScrollBegin","onProgressChange","customAnimation","commonVariables","size","handlerOffsetX","offsetX","totalSize","length","x","value","isNaN","carouselController","disable","originalLength","_onScrollEnd","onChange","i","duration","next","prev","sharedPreIndex","sharedIndex","computedIndex","getCurrentIndex","start","pause","React","useCallback","current","scrollViewGestureOnScrollBegin","scrollViewGestureOnScrollEnd","scrollViewGestureOnTouchBegin","scrollViewGestureOnTouchEnd","goToIndex","animated","to","useImperativeHandle","scrollTo","visibleRanges","total","viewSize","translation","layoutConfig","renderLayout","item","realIndex","DATA_LENGTH","SINGLE_ITEM","DOUBLE_ITEM","animationValue","index","common","styles","container","itemsVertical","itemsHorizontal","map","forwardRef","StyleSheet","create","overflow","flexDirection"],"mappings":";;;;;;;AAAA;;AACA;;AAEA;;AACA;;AACA;;AACA;;AACA;;AAGA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;;;;;;;AAEA,SAASA,QAAT,CACIC,MADJ,EAEIC,GAFJ,EAGE;AACE,QAAMC,KAAK,GAAG,gCAAaF,MAAb,CAAd;AAEA,QAAM;AACFG,IAAAA,IADE;AAEFC,IAAAA,OAFE;AAGFC,IAAAA,IAHE;AAIFC,IAAAA,IAJE;AAKFC,IAAAA,KALE;AAMFC,IAAAA,KANE;AAOFC,IAAAA,MAPE;AAQFC,IAAAA,QARE;AASFC,IAAAA,QATE;AAUFC,IAAAA,UAVE;AAWFC,IAAAA,eAXE;AAYFC,IAAAA,gBAZE;AAaFC,IAAAA,uBAbE;AAcFC,IAAAA,UAdE;AAeFC,IAAAA,WAfE;AAgBFC,IAAAA,YAhBE;AAiBFC,IAAAA,aAjBE;AAkBFC,IAAAA,gBAlBE;AAmBFC,IAAAA;AAnBE,MAoBFnB,KApBJ;AAsBA,QAAMoB,eAAe,GAAG,4CAAmBpB,KAAnB,CAAxB;AACA,QAAM;AAAEqB,IAAAA,IAAF;AAAQC,IAAAA;AAAR,MAA2BF,eAAjC;AAEA,QAAMG,OAAO,GAAG,4CAAgB,MAAM;AAClC,UAAMC,SAAS,GAAGH,IAAI,GA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,aAAa,EAAE;AADJ;AAPc,CAAlB,CAAf","sourcesContent":["import React, { PropsWithChildren } from 'react';\nimport Animated, { runOnJS, useDerivedValue } from 'react-native-reanimated';\n\nimport { useCarouselController } from './hooks/useCarouselController';\nimport { useAutoPlay } from './hooks/useAutoPlay';\nimport { usePropsErrorBoundary } from './hooks/usePropsErrorBoundary';\nimport { ScrollViewGesture } from './ScrollViewGesture';\nimport { useVisibleRanges } from './hooks/useVisibleRanges';\n\nimport type { ICarouselInstance, TCarouselProps } from './types';\nimport { StyleSheet, View } from 'react-native';\nimport { DATA_LENGTH } from './constants';\nimport { BaseLayout } from './layouts/BaseLayout';\nimport { useLayoutConfig } from './hooks/useLayoutConfig';\nimport { useInitProps } from './hooks/useInitProps';\nimport { CTX } from './store';\nimport { useCommonVariables } from './hooks/useCommonVariables';\nimport { useOnProgressChange } from './hooks/useOnProgressChange';\n\nfunction Carousel<T>(\n _props: PropsWithChildren<TCarouselProps<T>>,\n ref: React.Ref<ICarouselInstance>\n) {\n const props = useInitProps(_props);\n\n const {\n data,\n rawData,\n loop,\n mode,\n style,\n width,\n height,\n vertical,\n autoPlay,\n windowSize,\n autoPlayReverse,\n autoPlayInterval,\n scrollAnimationDuration,\n renderItem,\n onScrollEnd,\n onSnapToItem,\n onScrollBegin,\n onProgressChange,\n customAnimation,\n } = props;\n\n const commonVariables = useCommonVariables(props);\n const { size, handlerOffsetX } = commonVariables;\n\n const offsetX = useDerivedValue(() => {\n const totalSize = size * data.length;\n const x = handlerOffsetX.value % totalSize;\n\n if (!loop) {\n return handlerOffsetX.value;\n }\n return isNaN(x) ? 0 : x;\n }, [loop, size, data]);\n\n usePropsErrorBoundary(props);\n useOnProgressChange({ size, offsetX, rawData, onProgressChange });\n\n const carouselController = useCarouselController({\n loop,\n size,\n handlerOffsetX,\n length: data.length,\n disable: !data.length,\n originalLength: data.length,\n onScrollEnd: () => runOnJS(_onScrollEnd)(),\n onScrollBegin: () => !!onScrollBegin && runOnJS(onScrollBegin)(),\n onChange: (i) => !!onSnapToItem && runOnJS(onSnapToItem)(i),\n duration: scrollAnimationDuration,\n });\n\n const {\n next,\n prev,\n sharedPreIndex,\n sharedIndex,\n computedIndex,\n getCurrentIndex,\n } = carouselController;\n\n const { start, pause } = useAutoPlay({\n autoPlay,\n autoPlayInterval,\n autoPlayReverse,\n carouselController,\n });\n\n const _onScrollEnd = React.useCallback(() => {\n computedIndex();\n onScrollEnd?.(sharedPreIndex.current, sharedIndex.current);\n }, [sharedPreIndex, sharedIndex, computedIndex, onScrollEnd]);\n\n const scrollViewGestureOnScrollBegin = React.useCallback(() => {\n pause();\n onScrollBegin?.();\n }, [onScrollBegin, pause]);\n\n const scrollViewGestureOnScrollEnd = React.useCallback(() => {\n start();\n _onScrollEnd();\n }, [_onScrollEnd, start]);\n\n const scrollViewGestureOnTouchBegin = React.useCallback(pause, [pause]);\n\n const scrollViewGestureOnTouchEnd = React.useCallback(start, [start]);\n\n const goToIndex = React.useCallback(\n (i: number, animated?: boolean) => {\n carouselController.to(i, animated);\n },\n [carouselController]\n );\n\n React.useImperativeHandle(\n ref,\n () => ({\n next,\n prev,\n getCurrentIndex,\n goToIndex,\n scrollTo: carouselController.scrollTo,\n }),\n [getCurrentIndex, goToIndex, next, prev, carouselController.scrollTo]\n );\n\n const visibleRanges = useVisibleRanges({\n total: data.length,\n viewSize: size,\n translation: handlerOffsetX,\n windowSize,\n });\n\n const layoutConfig = useLayoutConfig<T>({ ...props, size });\n\n const renderLayout = React.useCallback(\n (item: T, i: number) => {\n let realIndex = i;\n if (rawData.length === DATA_LENGTH.SINGLE_ITEM) {\n realIndex = i % 1;\n }\n\n if (rawData.length === DATA_LENGTH.DOUBLE_ITEM) {\n realIndex = i % 2;\n }\n\n return (\n <BaseLayout\n key={i}\n index={i}\n handlerOffsetX={offsetX}\n visibleRanges={visibleRanges}\n animationStyle={customAnimation || layoutConfig}\n >\n {({ animationValue }) =>\n renderItem({\n item,\n index: realIndex,\n animationValue,\n })\n }\n </BaseLayout>\n );\n },\n [\n rawData,\n offsetX,\n visibleRanges,\n renderItem,\n layoutConfig,\n customAnimation,\n ]\n );\n\n return (\n <CTX.Provider value={{ props, common: commonVariables }}>\n <View\n style={[\n styles.container,\n { width: width || '100%', height: height || '100%' },\n style,\n ]}\n >\n <ScrollViewGesture\n size={size}\n translation={handlerOffsetX}\n onScrollBegin={scrollViewGestureOnScrollBegin}\n onScrollEnd={scrollViewGestureOnScrollEnd}\n onTouchBegin={scrollViewGestureOnTouchBegin}\n onTouchEnd={scrollViewGestureOnTouchEnd}\n >\n <Animated.View\n key={mode}\n style={[\n styles.container,\n {\n width: width || '100%',\n height: height || '100%',\n },\n style,\n vertical\n ? styles.itemsVertical\n : styles.itemsHorizontal,\n ]}\n >\n {data.map(renderLayout)}\n </Animated.View>\n </ScrollViewGesture>\n </View>\n </CTX.Provider>\n );\n}\n\nexport default React.forwardRef(Carousel) as typeof Carousel;\n\nconst styles = StyleSheet.create({\n container: {\n overflow: 'hidden',\n },\n itemsHorizontal: {\n flexDirection: 'row',\n },\n itemsVertical: {\n flexDirection: 'column',\n },\n});\n"]}
|
|
1
|
+
{"version":3,"sources":["Carousel.tsx"],"names":["Carousel","React","forwardRef","_props","ref","props","data","rawData","loop","mode","style","width","height","vertical","autoPlay","windowSize","autoPlayReverse","autoPlayInterval","scrollAnimationDuration","withAnimation","renderItem","onScrollEnd","onSnapToItem","onScrollBegin","onProgressChange","customAnimation","commonVariables","size","handlerOffsetX","offsetX","totalSize","length","x","value","isNaN","carouselController","disable","originalLength","_onScrollEnd","onChange","i","duration","next","prev","sharedPreIndex","sharedIndex","computedIndex","getCurrentIndex","start","pause","useCallback","current","scrollViewGestureOnScrollBegin","scrollViewGestureOnScrollEnd","scrollViewGestureOnTouchBegin","scrollViewGestureOnTouchEnd","goToIndex","animated","to","useImperativeHandle","scrollTo","visibleRanges","total","viewSize","translation","layoutConfig","renderLayout","item","realIndex","DATA_LENGTH","SINGLE_ITEM","DOUBLE_ITEM","animation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ANG,CAOHG,QAAQ,CACF8D,MAAM,CAACE,aADL,CAEFF,MAAM,CAACG,eATV,CAFX,+EAcKxE,IAAI,CAACyE,GAAL,CAASb,YAAT,CAdL,CARJ,CAPJ,CADJ,CADJ,CAqCH,CA1MY,CAAjB,C,aA6MelE,Q,0BAIf,GAAM2E,CAAAA,MAAM,CAAGK,wBAAWC,MAAX,CAAkB,CAC7BL,SAAS,CAAE,CACPM,QAAQ,CAAE,QADH,CADkB,CAI7BJ,eAAe,CAAE,CACbK,aAAa,CAAE,KADF,CAJY,CAO7BN,aAAa,CAAE,CACXM,aAAa,CAAE,QADJ,CAPc,CAAlB,CAAf","sourcesContent":["import React from 'react';\nimport Animated, { runOnJS, useDerivedValue } from 'react-native-reanimated';\n\nimport { useCarouselController } from './hooks/useCarouselController';\nimport { useAutoPlay } from './hooks/useAutoPlay';\nimport { usePropsErrorBoundary } from './hooks/usePropsErrorBoundary';\nimport { ScrollViewGesture } from './ScrollViewGesture';\nimport { useVisibleRanges } from './hooks/useVisibleRanges';\n\nimport type { ICarouselInstance, TCarouselProps } from './types';\nimport { StyleSheet, View } from 'react-native';\nimport { DATA_LENGTH } from './constants';\nimport { BaseLayout } from './layouts/BaseLayout';\nimport { useLayoutConfig } from './hooks/useLayoutConfig';\nimport { useInitProps } from './hooks/useInitProps';\nimport { CTX } from './store';\nimport { useCommonVariables } from './hooks/useCommonVariables';\nimport { useOnProgressChange } from './hooks/useOnProgressChange';\n\nconst Carousel = React.forwardRef<ICarouselInstance, TCarouselProps<any>>(\n (_props, ref) => {\n const props = useInitProps(_props);\n\n const {\n data,\n rawData,\n loop,\n mode,\n style,\n width,\n height,\n vertical,\n autoPlay,\n windowSize,\n autoPlayReverse,\n autoPlayInterval,\n scrollAnimationDuration,\n withAnimation,\n renderItem,\n onScrollEnd,\n onSnapToItem,\n onScrollBegin,\n onProgressChange,\n customAnimation,\n } = props;\n\n const commonVariables = useCommonVariables(props);\n const { size, handlerOffsetX } = commonVariables;\n\n const offsetX = useDerivedValue(() => {\n const totalSize = size * data.length;\n const x = handlerOffsetX.value % totalSize;\n\n if (!loop) {\n return handlerOffsetX.value;\n }\n return isNaN(x) ? 0 : x;\n }, [loop, size, data]);\n\n usePropsErrorBoundary(props);\n useOnProgressChange({ size, offsetX, rawData, onProgressChange });\n\n const carouselController = useCarouselController({\n loop,\n size,\n handlerOffsetX,\n length: data.length,\n disable: !data.length,\n withAnimation,\n originalLength: data.length,\n onScrollEnd: () => runOnJS(_onScrollEnd)(),\n onScrollBegin: () => !!onScrollBegin && runOnJS(onScrollBegin)(),\n onChange: (i) => !!onSnapToItem && runOnJS(onSnapToItem)(i),\n duration: scrollAnimationDuration,\n });\n\n const {\n next,\n prev,\n sharedPreIndex,\n sharedIndex,\n computedIndex,\n getCurrentIndex,\n } = carouselController;\n\n const { start, pause } = useAutoPlay({\n autoPlay,\n autoPlayInterval,\n autoPlayReverse,\n carouselController,\n });\n\n const _onScrollEnd = React.useCallback(() => {\n computedIndex();\n onScrollEnd?.(sharedPreIndex.current, sharedIndex.current);\n }, [sharedPreIndex, sharedIndex, computedIndex, onScrollEnd]);\n\n const scrollViewGestureOnScrollBegin = React.useCallback(() => {\n pause();\n onScrollBegin?.();\n }, [onScrollBegin, pause]);\n\n const scrollViewGestureOnScrollEnd = React.useCallback(() => {\n start();\n _onScrollEnd();\n }, [_onScrollEnd, start]);\n\n const scrollViewGestureOnTouchBegin = React.useCallback(pause, [pause]);\n\n const scrollViewGestureOnTouchEnd = React.useCallback(start, [start]);\n\n const goToIndex = React.useCallback(\n (i: number, animated?: boolean) => {\n carouselController.to(i, animated);\n },\n [carouselController]\n );\n\n React.useImperativeHandle(\n ref,\n () => ({\n next,\n prev,\n getCurrentIndex,\n goToIndex,\n scrollTo: carouselController.scrollTo,\n }),\n [\n getCurrentIndex,\n goToIndex,\n next,\n prev,\n carouselController.scrollTo,\n ]\n );\n\n const visibleRanges = useVisibleRanges({\n total: data.length,\n viewSize: size,\n translation: handlerOffsetX,\n windowSize,\n });\n\n const layoutConfig = useLayoutConfig({ ...props, size });\n\n const renderLayout = React.useCallback(\n (item: any, i: number) => {\n let realIndex = i;\n if (rawData.length === DATA_LENGTH.SINGLE_ITEM) {\n realIndex = i % 1;\n }\n\n if (rawData.length === DATA_LENGTH.DOUBLE_ITEM) {\n realIndex = i % 2;\n }\n\n return (\n <BaseLayout\n key={i}\n index={i}\n handlerOffsetX={offsetX}\n visibleRanges={visibleRanges}\n animationStyle={customAnimation || layoutConfig}\n >\n {({ animationValue }) =>\n renderItem({\n item,\n index: realIndex,\n animationValue,\n })\n }\n </BaseLayout>\n );\n },\n [\n rawData,\n offsetX,\n visibleRanges,\n renderItem,\n layoutConfig,\n customAnimation,\n ]\n );\n\n return (\n <CTX.Provider value={{ props, common: commonVariables }}>\n <View\n style={[\n styles.container,\n { width: width || '100%', height: height || '100%' },\n style,\n ]}\n >\n <ScrollViewGesture\n size={size}\n translation={handlerOffsetX}\n onScrollBegin={scrollViewGestureOnScrollBegin}\n onScrollEnd={scrollViewGestureOnScrollEnd}\n onTouchBegin={scrollViewGestureOnTouchBegin}\n onTouchEnd={scrollViewGestureOnTouchEnd}\n >\n <Animated.View\n key={mode}\n style={[\n styles.container,\n {\n width: width || '100%',\n height: height || '100%',\n },\n style,\n vertical\n ? styles.itemsVertical\n : styles.itemsHorizontal,\n ]}\n >\n {data.map(renderLayout)}\n </Animated.View>\n </ScrollViewGesture>\n </View>\n </CTX.Provider>\n );\n }\n);\n\nexport default Carousel as <T extends any>(\n props: React.PropsWithChildren<TCarouselProps<T>>\n) => React.ReactElement;\n\nconst styles = StyleSheet.create({\n container: {\n overflow: 'hidden',\n },\n itemsHorizontal: {\n flexDirection: 'row',\n },\n itemsVertical: {\n flexDirection: 'column',\n },\n});\n"]}
|
package/lib/commonjs/LazyView.js
CHANGED
|
@@ -1,26 +1,2 @@
|
|
|
1
|
-
"
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.LazyView = void 0;
|
|
7
|
-
|
|
8
|
-
var _react = _interopRequireDefault(require("react"));
|
|
9
|
-
|
|
10
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
|
-
|
|
12
|
-
const LazyView = props => {
|
|
13
|
-
const {
|
|
14
|
-
shouldUpdate,
|
|
15
|
-
children
|
|
16
|
-
} = props;
|
|
17
|
-
|
|
18
|
-
if (!shouldUpdate) {
|
|
19
|
-
return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, children);
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
exports.LazyView = LazyView;
|
|
1
|
+
var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports,"__esModule",{value:true});exports.LazyView=void 0;var _react=_interopRequireDefault(require("react"));var LazyView=function LazyView(props){var shouldUpdate=props.shouldUpdate,children=props.children;if(!shouldUpdate){return _react.default.createElement(_react.default.Fragment,null);}return _react.default.createElement(_react.default.Fragment,null,children);};exports.LazyView=LazyView;
|
|
26
2
|
//# sourceMappingURL=LazyView.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["LazyView.tsx"],"names":["LazyView","props","shouldUpdate","children"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["LazyView.tsx"],"names":["LazyView","props","shouldUpdate","children"],"mappings":"oKAAA,oDAMO,GAAMA,CAAAA,QAAyB,CAAG,QAA5BA,CAAAA,QAA4B,CAACC,KAAD,CAAW,CAChD,GAAQC,CAAAA,YAAR,CAAmCD,KAAnC,CAAQC,YAAR,CAAsBC,QAAtB,CAAmCF,KAAnC,CAAsBE,QAAtB,CAEA,GAAI,CAACD,YAAL,CAAmB,CACf,MAAO,2DAAP,CACH,CAED,MAAO,2DAAGC,QAAH,CAAP,CACH,CARM,C","sourcesContent":["import React from 'react';\n\ninterface Props {\n shouldUpdate: boolean;\n}\n\nexport const LazyView: React.FC<Props> = (props) => {\n const { shouldUpdate, children } = props;\n\n if (!shouldUpdate) {\n return <></>;\n }\n\n return <>{children}</>;\n};\n"]}
|
|
@@ -1,226 +1,2 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.ScrollViewGesture = void 0;
|
|
7
|
-
|
|
8
|
-
var _react = _interopRequireDefault(require("react"));
|
|
9
|
-
|
|
10
|
-
var _reactNative = require("react-native");
|
|
11
|
-
|
|
12
|
-
var _reactNativeGestureHandler = require("react-native-gesture-handler");
|
|
13
|
-
|
|
14
|
-
var _reactNativeReanimated = _interopRequireWildcard(require("react-native-reanimated"));
|
|
15
|
-
|
|
16
|
-
var _constants = require("./constants");
|
|
17
|
-
|
|
18
|
-
var _store = require("./store");
|
|
19
|
-
|
|
20
|
-
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
21
|
-
|
|
22
|
-
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; }
|
|
23
|
-
|
|
24
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
25
|
-
|
|
26
|
-
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
27
|
-
|
|
28
|
-
const IScrollViewGesture = props => {
|
|
29
|
-
const {
|
|
30
|
-
props: {
|
|
31
|
-
vertical,
|
|
32
|
-
style,
|
|
33
|
-
data,
|
|
34
|
-
pagingEnabled,
|
|
35
|
-
enableSnap,
|
|
36
|
-
panGestureHandlerProps,
|
|
37
|
-
loop: infinite,
|
|
38
|
-
scrollAnimationDuration
|
|
39
|
-
}
|
|
40
|
-
} = _react.default.useContext(_store.CTX);
|
|
41
|
-
|
|
42
|
-
const {
|
|
43
|
-
translation,
|
|
44
|
-
size,
|
|
45
|
-
onScrollBegin,
|
|
46
|
-
onScrollEnd,
|
|
47
|
-
onTouchBegin,
|
|
48
|
-
onTouchEnd
|
|
49
|
-
} = props;
|
|
50
|
-
const maxPage = data.length;
|
|
51
|
-
const isHorizontal = (0, _reactNativeReanimated.useDerivedValue)(() => !vertical, [vertical]);
|
|
52
|
-
const touching = (0, _reactNativeReanimated.useSharedValue)(false);
|
|
53
|
-
const scrollEndTranslation = (0, _reactNativeReanimated.useSharedValue)(0);
|
|
54
|
-
const scrollEndVelocity = (0, _reactNativeReanimated.useSharedValue)(0);
|
|
55
|
-
|
|
56
|
-
const _withSpring = _react.default.useCallback((toValue, onFinished) => {
|
|
57
|
-
'worklet';
|
|
58
|
-
|
|
59
|
-
return (0, _reactNativeReanimated.withTiming)(toValue, {
|
|
60
|
-
duration: scrollAnimationDuration,
|
|
61
|
-
easing: _constants.Easing.easeOutQuart
|
|
62
|
-
}, isFinished => {
|
|
63
|
-
if (isFinished) {
|
|
64
|
-
onFinished === null || onFinished === void 0 ? void 0 : onFinished();
|
|
65
|
-
}
|
|
66
|
-
});
|
|
67
|
-
}, [scrollAnimationDuration]);
|
|
68
|
-
|
|
69
|
-
const endWithSpring = _react.default.useCallback(onFinished => {
|
|
70
|
-
'worklet';
|
|
71
|
-
|
|
72
|
-
const origin = translation.value;
|
|
73
|
-
const velocity = scrollEndVelocity.value;
|
|
74
|
-
|
|
75
|
-
if (!pagingEnabled) {
|
|
76
|
-
if (enableSnap) {
|
|
77
|
-
const nextPage = Math.round((origin + velocity * 0.4) / size) * size;
|
|
78
|
-
translation.value = _withSpring(nextPage, onFinished);
|
|
79
|
-
return;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
translation.value = (0, _reactNativeReanimated.withDecay)({
|
|
83
|
-
velocity,
|
|
84
|
-
deceleration: 0.999
|
|
85
|
-
});
|
|
86
|
-
return;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
const page = Math.round(-translation.value / size);
|
|
90
|
-
const velocityPage = Math.round(-(translation.value + scrollEndVelocity.value) / size);
|
|
91
|
-
let finalPage = Math.min(page + 1, Math.max(page - 1, velocityPage));
|
|
92
|
-
|
|
93
|
-
if (!infinite) {
|
|
94
|
-
finalPage = Math.min(maxPage - 1, Math.max(0, finalPage));
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
translation.value = _withSpring(-finalPage * size, onFinished);
|
|
98
|
-
}, [infinite, _withSpring, translation, scrollEndVelocity, size, maxPage, pagingEnabled, enableSnap]);
|
|
99
|
-
|
|
100
|
-
const onFinish = _react.default.useCallback(isFinished => {
|
|
101
|
-
'worklet';
|
|
102
|
-
|
|
103
|
-
if (isFinished) {
|
|
104
|
-
touching.value = false;
|
|
105
|
-
onScrollEnd && (0, _reactNativeReanimated.runOnJS)(onScrollEnd)();
|
|
106
|
-
}
|
|
107
|
-
}, [onScrollEnd, touching]);
|
|
108
|
-
|
|
109
|
-
const activeDecay = _react.default.useCallback(() => {
|
|
110
|
-
'worklet';
|
|
111
|
-
|
|
112
|
-
touching.value = true;
|
|
113
|
-
translation.value = (0, _reactNativeReanimated.withDecay)({
|
|
114
|
-
velocity: scrollEndVelocity.value
|
|
115
|
-
}, onFinish);
|
|
116
|
-
}, [onFinish, scrollEndVelocity.value, touching, translation]);
|
|
117
|
-
|
|
118
|
-
const resetBoundary = _react.default.useCallback(() => {
|
|
119
|
-
'worklet';
|
|
120
|
-
|
|
121
|
-
if (touching.value) {
|
|
122
|
-
return;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
if (translation.value > 0) {
|
|
126
|
-
if (scrollEndTranslation.value < 0) {
|
|
127
|
-
activeDecay();
|
|
128
|
-
return;
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
if (!infinite) {
|
|
132
|
-
translation.value = _withSpring(0);
|
|
133
|
-
return;
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
if (translation.value < -((maxPage - 1) * size)) {
|
|
138
|
-
if (scrollEndTranslation.value > 0) {
|
|
139
|
-
activeDecay();
|
|
140
|
-
return;
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
if (!infinite) {
|
|
144
|
-
translation.value = _withSpring(-((maxPage - 1) * size));
|
|
145
|
-
return;
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
}, [touching.value, translation, maxPage, size, scrollEndTranslation.value, infinite, activeDecay, _withSpring]);
|
|
149
|
-
|
|
150
|
-
(0, _reactNativeReanimated.useAnimatedReaction)(() => translation.value, () => {
|
|
151
|
-
if (!pagingEnabled) {
|
|
152
|
-
resetBoundary();
|
|
153
|
-
}
|
|
154
|
-
}, [pagingEnabled, resetBoundary]);
|
|
155
|
-
const panGestureEventHandler = (0, _reactNativeReanimated.useAnimatedGestureHandler)({
|
|
156
|
-
onStart: (_, ctx) => {
|
|
157
|
-
touching.value = true;
|
|
158
|
-
(0, _reactNativeReanimated.cancelAnimation)(translation);
|
|
159
|
-
onScrollBegin && (0, _reactNativeReanimated.runOnJS)(onScrollBegin)();
|
|
160
|
-
ctx.max = (maxPage - 1) * size;
|
|
161
|
-
ctx.panOffset = translation.value;
|
|
162
|
-
},
|
|
163
|
-
onActive: (e, ctx) => {
|
|
164
|
-
touching.value = true;
|
|
165
|
-
const {
|
|
166
|
-
translationX,
|
|
167
|
-
translationY
|
|
168
|
-
} = e;
|
|
169
|
-
let panTranslation = isHorizontal.value ? translationX : translationY;
|
|
170
|
-
|
|
171
|
-
if (!infinite && (translation.value > 0 || translation.value < -ctx.max)) {
|
|
172
|
-
const boundary = translation.value > 0 ? 0 : -ctx.max;
|
|
173
|
-
const fixed = boundary - ctx.panOffset;
|
|
174
|
-
const dynamic = panTranslation - fixed;
|
|
175
|
-
translation.value = boundary + dynamic * 0.5;
|
|
176
|
-
return;
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
translation.value = ctx.panOffset + panTranslation;
|
|
180
|
-
},
|
|
181
|
-
onEnd: e => {
|
|
182
|
-
const {
|
|
183
|
-
velocityX,
|
|
184
|
-
velocityY,
|
|
185
|
-
translationX,
|
|
186
|
-
translationY
|
|
187
|
-
} = e;
|
|
188
|
-
scrollEndVelocity.value = isHorizontal.value ? velocityX : velocityY;
|
|
189
|
-
scrollEndTranslation.value = isHorizontal.value ? translationX : translationY;
|
|
190
|
-
endWithSpring(() => onScrollEnd && (0, _reactNativeReanimated.runOnJS)(onScrollEnd)());
|
|
191
|
-
|
|
192
|
-
if (!infinite) {
|
|
193
|
-
touching.value = false;
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
}, [pagingEnabled, isHorizontal.value, infinite, maxPage, size, enableSnap, onScrollBegin, onScrollEnd]);
|
|
197
|
-
|
|
198
|
-
const directionStyle = _react.default.useMemo(() => {
|
|
199
|
-
return vertical ? styles.contentHorizontal : styles.contentVertical;
|
|
200
|
-
}, [vertical]);
|
|
201
|
-
|
|
202
|
-
return /*#__PURE__*/_react.default.createElement(_reactNativeReanimated.default.View, {
|
|
203
|
-
style: [styles.container, directionStyle, style],
|
|
204
|
-
onTouchStart: onTouchBegin,
|
|
205
|
-
onTouchEnd: onTouchEnd
|
|
206
|
-
}, /*#__PURE__*/_react.default.createElement(_reactNativeGestureHandler.PanGestureHandler, _extends({}, panGestureHandlerProps, {
|
|
207
|
-
onGestureEvent: panGestureEventHandler
|
|
208
|
-
}), props.children));
|
|
209
|
-
};
|
|
210
|
-
|
|
211
|
-
const ScrollViewGesture = IScrollViewGesture;
|
|
212
|
-
exports.ScrollViewGesture = ScrollViewGesture;
|
|
213
|
-
|
|
214
|
-
const styles = _reactNative.StyleSheet.create({
|
|
215
|
-
container: {
|
|
216
|
-
flex: 1,
|
|
217
|
-
overflow: 'hidden'
|
|
218
|
-
},
|
|
219
|
-
contentVertical: {
|
|
220
|
-
flexDirection: 'column'
|
|
221
|
-
},
|
|
222
|
-
contentHorizontal: {
|
|
223
|
-
flexDirection: 'row'
|
|
224
|
-
}
|
|
225
|
-
});
|
|
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/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,style=_React$useContext$pro.style,data=_React$useContext$pro.data,pagingEnabled=_React$useContext$pro.pagingEnabled,enableSnap=_React$useContext$pro.enableSnap,panGestureHandlerProps=_React$useContext$pro.panGestureHandlerProps,infinite=_React$useContext$pro.loop,scrollAnimationDuration=_React$useContext$pro.scrollAnimationDuration,withAnimation=_React$useContext$pro.withAnimation;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/react-native-reanimated-carousel/src/ScrollViewGesture.tsx (62:41)";global.__reanimatedWorkletInit(_f);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 callback=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/react-native-reanimated-carousel/src/ScrollViewGesture.tsx (70:29)";global.__reanimatedWorkletInit(_f);return _f;}();var defaultWithAnimation={type:'timing',config:{duration:scrollAnimationDuration,easing:_constants.Easing.easeOutQuart}};return(0,_dealWithAnimation.dealWithAnimation)(withAnimation!=null?withAnimation:defaultWithAnimation)(toValue,callback);};_f._closure={runOnJS:_reactNativeReanimated.runOnJS,scrollAnimationDuration:scrollAnimationDuration,Easing:{easeOutQuart:_constants.Easing.easeOutQuart},dealWithAnimation:_dealWithAnimation.dealWithAnimation,withAnimation:withAnimation};_f.asString="function _f(toValue,onFinished){const{runOnJS,scrollAnimationDuration,Easing,dealWithAnimation,withAnimation}=jsThis._closure;{var _withAnimation;const callback=function(isFinished){'worklet';if(isFinished){onFinished&&runOnJS(onFinished)();}};const defaultWithAnimation={type:'timing',config:{duration:scrollAnimationDuration,easing:Easing.easeOutQuart}};return dealWithAnimation((_withAnimation=withAnimation)!==null&&_withAnimation!==void 0?_withAnimation:defaultWithAnimation)(toValue,callback);}}";_f.__workletHash=399949545942;_f.__location="/Users/zhaodonghao/code/react-native-reanimated-carousel/src/ScrollViewGesture.tsx (68:8)";global.__reanimatedWorkletInit(_f);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(enableSnap){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,enableSnap:enableSnap,size:size,_withSpring:_withSpring,withDecay:_reactNativeReanimated.withDecay,infinite:infinite,maxPage:maxPage};_f.asString="function _f(onFinished){const{translation,scrollEndVelocity,pagingEnabled,enableSnap,size,_withSpring,withDecay,infinite,maxPage}=jsThis._closure;{const origin=translation.value;const velocity=scrollEndVelocity.value;if(!pagingEnabled){if(enableSnap){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=2902619242237;_f.__location="/Users/zhaodonghao/code/react-native-reanimated-carousel/src/ScrollViewGesture.tsx (94:8)";global.__reanimatedWorkletInit(_f);return _f;}(),[infinite,_withSpring,translation,scrollEndVelocity,size,maxPage,pagingEnabled,enableSnap]);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/react-native-reanimated-carousel/src/ScrollViewGesture.tsx (138:8)";global.__reanimatedWorkletInit(_f);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/react-native-reanimated-carousel/src/ScrollViewGesture.tsx (153:12)";global.__reanimatedWorkletInit(_f);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/react-native-reanimated-carousel/src/ScrollViewGesture.tsx (148:42)";global.__reanimatedWorkletInit(_f);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/react-native-reanimated-carousel/src/ScrollViewGesture.tsx (157:44)";global.__reanimatedWorkletInit(_f);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/react-native-reanimated-carousel/src/ScrollViewGesture.tsx (196:8)";global.__reanimatedWorkletInit(_f);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/react-native-reanimated-carousel/src/ScrollViewGesture.tsx (197:8)";global.__reanimatedWorkletInit(_f);return _f;}(),[pagingEnabled,resetBoundary]);var panGestureEventHandler=(0,_reactNativeReanimated.useAnimatedGestureHandler)({onStart:function(){var _f=function _f(_,ctx){touching.value=true;(0,_reactNativeReanimated.cancelAnimation)(translation);onScrollBegin&&(0,_reactNativeReanimated.runOnJS)(onScrollBegin)();ctx.max=(maxPage-1)*size;ctx.panOffset=translation.value;};_f._closure={touching:touching,cancelAnimation:_reactNativeReanimated.cancelAnimation,translation:translation,onScrollBegin:onScrollBegin,runOnJS:_reactNativeReanimated.runOnJS,maxPage:maxPage,size:size};_f.asString="function _f(_,ctx){const{touching,cancelAnimation,translation,onScrollBegin,runOnJS,maxPage,size}=jsThis._closure;{touching.value=true;cancelAnimation(translation);onScrollBegin&&runOnJS(onScrollBegin)();ctx.max=(maxPage-1)*size;ctx.panOffset=translation.value;}}";_f.__workletHash=6284838066683;_f.__location="/Users/zhaodonghao/code/react-native-reanimated-carousel/src/ScrollViewGesture.tsx (210:21)";global.__reanimatedWorkletInit(_f);return _f;}(),onActive:function(){var _f=function _f(e,ctx){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={touching:touching,isHorizontal:isHorizontal,infinite:infinite,translation:translation};_f.asString="function _f(e,ctx){const{touching,isHorizontal,infinite,translation}=jsThis._closure;{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=1929108728437;_f.__location="/Users/zhaodonghao/code/react-native-reanimated-carousel/src/ScrollViewGesture.tsx (217:22)";global.__reanimatedWorkletInit(_f);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/react-native-reanimated-carousel/src/ScrollViewGesture.tsx (237:19)";global.__reanimatedWorkletInit(_f);return _f;}()},[pagingEnabled,isHorizontal.value,infinite,maxPage,size,enableSnap,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,style],onTouchStart:onTouchBegin,onTouchEnd:onTouchEnd,__self:_this,__source:{fileName:_jsxFileName,lineNumber:271,columnNumber:9}},_react.default.createElement(_reactNativeGestureHandler.PanGestureHandler,(0,_extends2.default)({},panGestureHandlerProps,{onGestureEvent:panGestureEventHandler,__self:_this,__source:{fileName:_jsxFileName,lineNumber:276,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'}});
|
|
226
2
|
//# sourceMappingURL=ScrollViewGesture.js.map
|