@mpxjs/webpack-plugin 2.9.70-alpha.0 → 2.9.70
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/LICENSE +433 -0
- package/README.md +1 -1
- package/lib/config.js +0 -14
- package/lib/dependencies/ResolveDependency.js +0 -5
- package/lib/index.js +7 -38
- package/lib/json-compiler/helper.js +3 -3
- package/lib/loader.js +0 -53
- package/lib/parser.js +1 -1
- package/lib/platform/json/wx/index.js +21 -8
- package/lib/platform/style/wx/index.js +51 -54
- package/lib/platform/template/wx/component-config/button.js +2 -14
- package/lib/platform/template/wx/component-config/fix-component-name.js +15 -12
- package/lib/platform/template/wx/component-config/image.js +0 -4
- package/lib/platform/template/wx/component-config/index.js +1 -1
- package/lib/platform/template/wx/component-config/input.js +0 -4
- package/lib/platform/template/wx/component-config/rich-text.js +6 -2
- package/lib/platform/template/wx/component-config/scroll-view.js +0 -4
- package/lib/platform/template/wx/component-config/switch.js +0 -4
- package/lib/platform/template/wx/component-config/text.js +0 -4
- package/lib/platform/template/wx/component-config/textarea.js +0 -5
- package/lib/platform/template/wx/component-config/unsupported.js +1 -1
- package/lib/platform/template/wx/component-config/view.js +0 -4
- package/lib/platform/template/wx/index.js +1 -127
- package/lib/resolve-loader.js +1 -4
- package/lib/runtime/components/react/dist/getInnerListeners.js +5 -6
- package/lib/runtime/components/react/dist/mpx-canvas/html.js +2 -4
- package/lib/runtime/components/react/dist/mpx-canvas/index.jsx +5 -1
- package/lib/runtime/components/react/dist/mpx-picker-view-column.jsx +96 -107
- package/lib/runtime/components/react/dist/mpx-picker-view.jsx +26 -27
- package/lib/runtime/components/react/dist/mpx-swiper/carouse.jsx +480 -0
- package/lib/runtime/components/react/dist/mpx-swiper/index.jsx +68 -0
- package/lib/runtime/components/react/dist/mpx-swiper/type.js +1 -0
- package/lib/runtime/components/react/dist/mpx-view.jsx +6 -3
- package/lib/runtime/components/react/dist/pickerFaces.js +6 -12
- package/lib/runtime/components/react/dist/{pickerViewOverlay.jsx → pickerOverlay.jsx} +3 -5
- package/lib/runtime/components/react/dist/useAnimationHooks.js +7 -8
- package/lib/runtime/components/react/dist/utils.jsx +89 -60
- package/lib/runtime/components/react/event.config.ts +25 -26
- package/lib/runtime/components/react/getInnerListeners.ts +212 -169
- package/lib/runtime/components/react/mpx-button.tsx +9 -14
- package/lib/runtime/components/react/mpx-canvas/html.ts +2 -4
- package/lib/runtime/components/react/mpx-canvas/index.tsx +44 -46
- package/lib/runtime/components/react/mpx-checkbox-group.tsx +15 -13
- package/lib/runtime/components/react/mpx-checkbox.tsx +20 -21
- package/lib/runtime/components/react/mpx-form.tsx +15 -20
- package/lib/runtime/components/react/mpx-icon.tsx +2 -2
- package/lib/runtime/components/react/mpx-image.tsx +87 -47
- package/lib/runtime/components/react/mpx-input.tsx +24 -32
- package/lib/runtime/components/react/mpx-label.tsx +12 -14
- package/lib/runtime/components/react/mpx-movable-area.tsx +10 -16
- package/lib/runtime/components/react/mpx-movable-view.tsx +20 -24
- package/lib/runtime/components/react/mpx-navigator.tsx +2 -8
- package/lib/runtime/components/react/mpx-radio-group.tsx +13 -15
- package/lib/runtime/components/react/mpx-radio.tsx +19 -25
- package/lib/runtime/components/react/mpx-rich-text/html.ts +40 -0
- package/lib/runtime/components/react/mpx-rich-text/index.tsx +121 -0
- package/lib/runtime/components/react/mpx-root-portal.tsx +3 -5
- package/lib/runtime/components/react/mpx-scroll-view.tsx +40 -41
- package/lib/runtime/components/react/mpx-switch.tsx +19 -15
- package/lib/runtime/components/react/mpx-text.tsx +8 -16
- package/lib/runtime/components/react/mpx-textarea.tsx +11 -10
- package/lib/runtime/components/react/mpx-view.tsx +18 -20
- package/lib/runtime/components/react/mpx-web-view.tsx +94 -59
- package/lib/runtime/components/react/types/global.d.ts +2 -1
- package/lib/runtime/components/react/useAnimationHooks.ts +36 -12
- package/lib/runtime/components/react/utils.tsx +91 -60
- package/lib/runtime/components/web/mpx-web-view.vue +34 -20
- package/lib/runtime/optionProcessor.js +0 -22
- package/lib/style-compiler/index.js +1 -1
- package/lib/style-compiler/plugins/scope-id.js +30 -2
- package/lib/template-compiler/compiler.js +30 -26
- package/lib/utils/env.js +1 -6
- package/lib/utils/pre-process-json.js +9 -5
- package/package.json +4 -7
- package/lib/dependencies/AddEntryDependency.js +0 -24
- package/lib/runtime/components/react/dist/mpx-picker-view-column-item.jsx +0 -39
- package/lib/runtime/components/react/dist/mpx-swiper.jsx +0 -606
- package/lib/runtime/components/react/dist/pickerVIewContext.js +0 -9
- package/lib/runtime/components/react/dist/pickerViewMask.jsx +0 -18
- package/lib/runtime/components/tenon/getInnerListeners.js +0 -334
- package/lib/runtime/components/tenon/tenon-button.vue +0 -309
- package/lib/runtime/components/tenon/tenon-image.vue +0 -66
- package/lib/runtime/components/tenon/tenon-input.vue +0 -171
- package/lib/runtime/components/tenon/tenon-rich-text.vue +0 -26
- package/lib/runtime/components/tenon/tenon-scroll-view.vue +0 -127
- package/lib/runtime/components/tenon/tenon-switch.vue +0 -96
- package/lib/runtime/components/tenon/tenon-text.vue +0 -70
- package/lib/runtime/components/tenon/tenon-textarea.vue +0 -86
- package/lib/runtime/components/tenon/tenon-view.vue +0 -93
- package/lib/runtime/components/web/event.js +0 -105
- package/lib/runtime/optionProcessor.tenon.js +0 -84
- package/lib/style-compiler/plugins/hm.js +0 -20
- package/lib/tenon/index.js +0 -117
- package/lib/tenon/processJSON.js +0 -352
- package/lib/tenon/processScript.js +0 -203
- package/lib/tenon/processStyles.js +0 -21
- package/lib/tenon/processTemplate.js +0 -126
- package/lib/tenon/script-helper.js +0 -223
- package/lib/utils/get-relative-path.js +0 -25
|
@@ -1,606 +0,0 @@
|
|
|
1
|
-
import { View, Dimensions } from 'react-native';
|
|
2
|
-
import { GestureDetector, Gesture } from 'react-native-gesture-handler';
|
|
3
|
-
import Animated, { useAnimatedStyle, useSharedValue, withTiming, Easing, runOnJS, useAnimatedReaction, cancelAnimation } from 'react-native-reanimated';
|
|
4
|
-
import React, { forwardRef, useRef, useEffect, useState } from 'react';
|
|
5
|
-
import useInnerProps, { getCustomEvent } from './getInnerListeners';
|
|
6
|
-
import useNodesRef from './useNodesRef'; // 引入辅助函数
|
|
7
|
-
import { useTransformStyle, splitStyle, splitProps, useLayout, wrapChildren } from './utils';
|
|
8
|
-
/**
|
|
9
|
-
* 默认的Style类型
|
|
10
|
-
*/
|
|
11
|
-
const styles = {
|
|
12
|
-
pagination_x: {
|
|
13
|
-
position: 'absolute',
|
|
14
|
-
bottom: 25,
|
|
15
|
-
left: 0,
|
|
16
|
-
right: 0,
|
|
17
|
-
flexDirection: 'row',
|
|
18
|
-
flex: 1,
|
|
19
|
-
justifyContent: 'center',
|
|
20
|
-
alignItems: 'center'
|
|
21
|
-
},
|
|
22
|
-
pagination_y: {
|
|
23
|
-
position: 'absolute',
|
|
24
|
-
right: 15,
|
|
25
|
-
top: 0,
|
|
26
|
-
bottom: 0,
|
|
27
|
-
flexDirection: 'column',
|
|
28
|
-
flex: 1,
|
|
29
|
-
justifyContent: 'center',
|
|
30
|
-
alignItems: 'center'
|
|
31
|
-
},
|
|
32
|
-
pagerWrapper: {
|
|
33
|
-
position: 'absolute',
|
|
34
|
-
flexDirection: 'row',
|
|
35
|
-
justifyContent: 'center',
|
|
36
|
-
alignItems: 'center'
|
|
37
|
-
},
|
|
38
|
-
swiper: {
|
|
39
|
-
overflow: 'scroll',
|
|
40
|
-
display: 'flex',
|
|
41
|
-
justifyContent: 'flex-start'
|
|
42
|
-
}
|
|
43
|
-
};
|
|
44
|
-
const dotCommonStyle = {
|
|
45
|
-
width: 8,
|
|
46
|
-
height: 8,
|
|
47
|
-
borderRadius: 4,
|
|
48
|
-
marginLeft: 3,
|
|
49
|
-
marginRight: 3,
|
|
50
|
-
marginTop: 3,
|
|
51
|
-
marginBottom: 3,
|
|
52
|
-
zIndex: 98
|
|
53
|
-
};
|
|
54
|
-
const activeDotStyle = {
|
|
55
|
-
zIndex: 99
|
|
56
|
-
};
|
|
57
|
-
// 默认前后补位的元素个数
|
|
58
|
-
const patchElementNum = 1;
|
|
59
|
-
const longPressRatio = 100;
|
|
60
|
-
const easeMap = {
|
|
61
|
-
default: Easing.linear,
|
|
62
|
-
linear: Easing.linear,
|
|
63
|
-
easeInCubic: Easing.in(Easing.cubic),
|
|
64
|
-
easeOutCubic: Easing.out(Easing.cubic),
|
|
65
|
-
easeInOutCubic: Easing.inOut(Easing.cubic)
|
|
66
|
-
};
|
|
67
|
-
const SwiperWrapper = forwardRef((props, ref) => {
|
|
68
|
-
const { 'indicator-dots': showsPagination, 'indicator-color': dotColor = 'rgba(0, 0, 0, .3)', 'indicator-active-color': activeDotColor = '#000000', 'enable-var': enableVar = false, 'parent-font-size': parentFontSize, 'parent-width': parentWidth, 'parent-height': parentHeight, 'external-var-context': externalVarContext, style = {} } = props;
|
|
69
|
-
const previousMargin = props['previous-margin'] ? parseInt(props['previous-margin']) : 0;
|
|
70
|
-
const nextMargin = props['next-margin'] ? parseInt(props['next-margin']) : 0;
|
|
71
|
-
const easeingFunc = props['easing-function'] || 'default';
|
|
72
|
-
const easeDuration = props.duration || 500;
|
|
73
|
-
const horizontal = props.vertical !== undefined ? !props.vertical : true;
|
|
74
|
-
const nodeRef = useRef(null);
|
|
75
|
-
useNodesRef(props, ref, nodeRef, {});
|
|
76
|
-
// 默认取水平方向的width
|
|
77
|
-
const { width } = Dimensions.get('window');
|
|
78
|
-
// 计算transfrom之类的
|
|
79
|
-
const { normalStyle, hasVarDec, varContextRef, hasSelfPercent, setWidth, setHeight } = useTransformStyle(style, {
|
|
80
|
-
enableVar,
|
|
81
|
-
externalVarContext,
|
|
82
|
-
parentFontSize,
|
|
83
|
-
parentWidth,
|
|
84
|
-
parentHeight
|
|
85
|
-
});
|
|
86
|
-
const { textStyle } = splitStyle(normalStyle);
|
|
87
|
-
const { textProps } = splitProps(props);
|
|
88
|
-
const children = Array.isArray(props.children) ? props.children.filter(child => child) : (props.children ? [props.children] : []);
|
|
89
|
-
const defaultHeight = (normalStyle?.height || 150);
|
|
90
|
-
const defaultWidth = (normalStyle?.width || width || 375);
|
|
91
|
-
const initWidth = typeof defaultWidth === 'number' ? defaultWidth - previousMargin - nextMargin : defaultWidth;
|
|
92
|
-
const initHeight = typeof defaultHeight === 'number' ? defaultHeight - previousMargin - nextMargin : defaultHeight;
|
|
93
|
-
const [widthState, setWidthState] = useState(initWidth);
|
|
94
|
-
const [heightState, setHeightState] = useState(initHeight);
|
|
95
|
-
const dir = useSharedValue(horizontal === false ? 'y' : 'x');
|
|
96
|
-
const pstep = dir.value === 'x' ? widthState : heightState;
|
|
97
|
-
const initStep = isNaN(pstep) ? 0 : pstep;
|
|
98
|
-
// 每个元素的宽度 or 高度
|
|
99
|
-
const step = useSharedValue(initStep);
|
|
100
|
-
const totalElements = useSharedValue(children.length);
|
|
101
|
-
// 记录选中元素的索引值
|
|
102
|
-
const targetIndex = useSharedValue(0);
|
|
103
|
-
// 记录元素的偏移量
|
|
104
|
-
const offset = useSharedValue(0);
|
|
105
|
-
const strTrans = 'translation' + dir.value.toUpperCase();
|
|
106
|
-
const strAbso = 'absolute' + dir.value.toUpperCase();
|
|
107
|
-
const strVelocity = 'velocity' + dir.value.toUpperCase();
|
|
108
|
-
const arrPages = renderItems();
|
|
109
|
-
// autoplay的状态下是否被暂停
|
|
110
|
-
const paused = useRef(false);
|
|
111
|
-
// 标识手指触摸和抬起, 起点在onBegin
|
|
112
|
-
const touchfinish = useSharedValue(false);
|
|
113
|
-
// 用户是否触发了move事件,起点在onStart, 触发move事件才会执行onEnd, 1. 移动一定会触发onStart, onTouchesMove, onEnd 2. 点击未进行操作, 会触发onTouchsUp
|
|
114
|
-
const isTriggerStart = useSharedValue(false);
|
|
115
|
-
// 记录用户点击时绝对定位坐标
|
|
116
|
-
const preAbsolutePos = useSharedValue(0);
|
|
117
|
-
const timerId = useRef(0);
|
|
118
|
-
// 用户点击未移动状态下,记录用户上一次操作的transtion 的 direction
|
|
119
|
-
const customTrans = useSharedValue(0);
|
|
120
|
-
const intervalTimer = props.interval || 500;
|
|
121
|
-
totalElements.value = children.length;
|
|
122
|
-
const {
|
|
123
|
-
// 存储layout布局信息
|
|
124
|
-
layoutRef, layoutProps, layoutStyle } = useLayout({ props, hasSelfPercent, setWidth, setHeight, nodeRef, onLayout: onWrapperLayout });
|
|
125
|
-
const innerProps = useInnerProps(props, {
|
|
126
|
-
ref: nodeRef
|
|
127
|
-
}, [
|
|
128
|
-
'style',
|
|
129
|
-
'indicator-dots',
|
|
130
|
-
'indicator-color',
|
|
131
|
-
'indicator-active-color',
|
|
132
|
-
'previous-margin',
|
|
133
|
-
'vertical',
|
|
134
|
-
'previous-margin',
|
|
135
|
-
'next-margin',
|
|
136
|
-
'easing-function',
|
|
137
|
-
'autoplay',
|
|
138
|
-
'circular',
|
|
139
|
-
'interval',
|
|
140
|
-
'easing-function'
|
|
141
|
-
], { layoutRef: layoutRef });
|
|
142
|
-
function onWrapperLayout(e) {
|
|
143
|
-
const { width, height } = e.nativeEvent.layout;
|
|
144
|
-
const realWidth = dir.value === 'x' ? width - previousMargin - nextMargin : width;
|
|
145
|
-
const realHeight = dir.value === 'y' ? height - previousMargin - nextMargin : height;
|
|
146
|
-
setWidthState(realWidth);
|
|
147
|
-
setHeightState(realHeight);
|
|
148
|
-
}
|
|
149
|
-
const dotAnimatedStyle = useAnimatedStyle(() => {
|
|
150
|
-
const step = dir.value === 'x' ? widthState : heightState;
|
|
151
|
-
if (isNaN(+step))
|
|
152
|
-
return {};
|
|
153
|
-
const dotStep = dotCommonStyle.width + dotCommonStyle.marginRight + dotCommonStyle.marginLeft;
|
|
154
|
-
return {
|
|
155
|
-
transform: [{
|
|
156
|
-
translateX: targetIndex.value * dotStep
|
|
157
|
-
}]
|
|
158
|
-
};
|
|
159
|
-
});
|
|
160
|
-
function renderPagination() {
|
|
161
|
-
const stepValue = getStepValue();
|
|
162
|
-
if (totalElements.value <= 1 || isNaN(+stepValue))
|
|
163
|
-
return null;
|
|
164
|
-
const activeColor = activeDotColor || '#007aff';
|
|
165
|
-
const unActionColor = dotColor || 'rgba(0,0,0,.2)';
|
|
166
|
-
// 正常渲染所有dots
|
|
167
|
-
const dots = [];
|
|
168
|
-
for (let i = 0; i < totalElements.value; i++) {
|
|
169
|
-
dots.push(<View style={[dotCommonStyle, { backgroundColor: unActionColor }]} key={i}></View>);
|
|
170
|
-
}
|
|
171
|
-
return (<View pointerEvents="none" style={[styles['pagination_' + [dir.value]]]}>
|
|
172
|
-
<View style={[styles.pagerWrapper]}>
|
|
173
|
-
<Animated.View style={[
|
|
174
|
-
dotCommonStyle,
|
|
175
|
-
activeDotStyle,
|
|
176
|
-
{
|
|
177
|
-
backgroundColor: activeColor,
|
|
178
|
-
position: 'absolute',
|
|
179
|
-
left: 0
|
|
180
|
-
},
|
|
181
|
-
dotAnimatedStyle
|
|
182
|
-
]}/>
|
|
183
|
-
{dots}
|
|
184
|
-
</View>
|
|
185
|
-
</View>);
|
|
186
|
-
}
|
|
187
|
-
function renderItems() {
|
|
188
|
-
const pageStyle = { width: widthState, height: heightState };
|
|
189
|
-
let renderChild = children.slice();
|
|
190
|
-
if (props.circular && totalElements.value > 1) {
|
|
191
|
-
// 最前面加最后一个元素
|
|
192
|
-
const lastChild = React.cloneElement(children[totalElements.value - 1]);
|
|
193
|
-
// 最后面加第一个元素
|
|
194
|
-
const firstChild = React.cloneElement(children[0]);
|
|
195
|
-
renderChild = [lastChild].concat(renderChild).concat(firstChild);
|
|
196
|
-
}
|
|
197
|
-
return renderChild.map((child, index) => {
|
|
198
|
-
const extraStyle = {};
|
|
199
|
-
const xCondition = dir.value === 'x' && typeof widthState === 'number';
|
|
200
|
-
const yCondition = dir.value === 'y' && typeof heightState === 'number';
|
|
201
|
-
if (index === 0 && (xCondition || yCondition)) {
|
|
202
|
-
previousMargin && dir.value === 'x' && (extraStyle.marginLeft = previousMargin);
|
|
203
|
-
previousMargin && dir.value === 'y' && (extraStyle.marginTop = previousMargin);
|
|
204
|
-
}
|
|
205
|
-
if (index === totalElements.value - 1 && (xCondition || yCondition)) {
|
|
206
|
-
nextMargin && dir.value === 'x' && (extraStyle.marginRight = nextMargin);
|
|
207
|
-
nextMargin && dir.value === 'y' && (extraStyle.marginBottom = nextMargin);
|
|
208
|
-
}
|
|
209
|
-
return (<Animated.View style={[
|
|
210
|
-
pageStyle,
|
|
211
|
-
extraStyle
|
|
212
|
-
]} key={'page' + index}>
|
|
213
|
-
{child}
|
|
214
|
-
</Animated.View>);
|
|
215
|
-
});
|
|
216
|
-
}
|
|
217
|
-
function createAutoPlay() {
|
|
218
|
-
let targetOffset = 0;
|
|
219
|
-
let nextIndex = targetIndex.value;
|
|
220
|
-
if (!props.circular) {
|
|
221
|
-
// 获取下一个位置的坐标, 循环到最后一个元素,直接停止, 取消定时器
|
|
222
|
-
if (targetIndex.value === totalElements.value - 1) {
|
|
223
|
-
pauseLoop();
|
|
224
|
-
return;
|
|
225
|
-
}
|
|
226
|
-
nextIndex += 1;
|
|
227
|
-
targetOffset = -nextIndex * step.value;
|
|
228
|
-
offset.value = withTiming(targetOffset, {
|
|
229
|
-
duration: easeDuration,
|
|
230
|
-
easing: easeMap[easeingFunc]
|
|
231
|
-
}, () => {
|
|
232
|
-
offset.value = targetOffset;
|
|
233
|
-
targetIndex.value = nextIndex;
|
|
234
|
-
});
|
|
235
|
-
}
|
|
236
|
-
else {
|
|
237
|
-
// 默认向右, 向下
|
|
238
|
-
if (nextIndex === totalElements.value - 1) {
|
|
239
|
-
nextIndex = 0;
|
|
240
|
-
targetOffset = -(totalElements.value + patchElementNum) * step.value;
|
|
241
|
-
// 执行动画到下一帧
|
|
242
|
-
offset.value = withTiming(targetOffset, {
|
|
243
|
-
duration: easeDuration
|
|
244
|
-
}, () => {
|
|
245
|
-
const initOffset = -step.value * patchElementNum;
|
|
246
|
-
// 将开始位置设置为真正的位置
|
|
247
|
-
offset.value = initOffset;
|
|
248
|
-
targetIndex.value = nextIndex;
|
|
249
|
-
});
|
|
250
|
-
}
|
|
251
|
-
else {
|
|
252
|
-
nextIndex = targetIndex.value + 1;
|
|
253
|
-
targetOffset = -(nextIndex + patchElementNum) * step.value;
|
|
254
|
-
// 执行动画到下一帧
|
|
255
|
-
offset.value = withTiming(targetOffset, {
|
|
256
|
-
duration: easeDuration,
|
|
257
|
-
easing: easeMap[easeingFunc]
|
|
258
|
-
}, () => {
|
|
259
|
-
offset.value = targetOffset;
|
|
260
|
-
targetIndex.value = nextIndex;
|
|
261
|
-
});
|
|
262
|
-
}
|
|
263
|
-
}
|
|
264
|
-
}
|
|
265
|
-
function handleSwiperChange(current) {
|
|
266
|
-
const eventData = getCustomEvent('change', {}, { detail: { current, source: 'touch' }, layoutRef: layoutRef });
|
|
267
|
-
props.bindchange && props.bindchange(eventData);
|
|
268
|
-
}
|
|
269
|
-
function getStepValue() {
|
|
270
|
-
'worklet';
|
|
271
|
-
return dir.value === 'x' ? widthState : heightState;
|
|
272
|
-
}
|
|
273
|
-
function getInitOffset() {
|
|
274
|
-
const stepValue = getStepValue();
|
|
275
|
-
if (isNaN(+stepValue))
|
|
276
|
-
return 0;
|
|
277
|
-
let targetOffset = 0;
|
|
278
|
-
if (props.circular && totalElements.value > 1) {
|
|
279
|
-
const targetIndex = (props.current || 0) + patchElementNum;
|
|
280
|
-
targetOffset = -stepValue * targetIndex;
|
|
281
|
-
}
|
|
282
|
-
else if (props.current && props.current > 0) {
|
|
283
|
-
targetOffset = -props.current * stepValue;
|
|
284
|
-
}
|
|
285
|
-
return targetOffset;
|
|
286
|
-
}
|
|
287
|
-
function loop() {
|
|
288
|
-
if (!paused.current) {
|
|
289
|
-
timerId.current = setTimeout(() => {
|
|
290
|
-
createAutoPlay();
|
|
291
|
-
loop();
|
|
292
|
-
}, intervalTimer);
|
|
293
|
-
}
|
|
294
|
-
}
|
|
295
|
-
function pauseLoop() {
|
|
296
|
-
paused.current = true;
|
|
297
|
-
clearTimeout(timerId.current);
|
|
298
|
-
}
|
|
299
|
-
function resumeLoop() {
|
|
300
|
-
if (props.autoplay && paused.current) {
|
|
301
|
-
paused.current = false;
|
|
302
|
-
loop();
|
|
303
|
-
}
|
|
304
|
-
}
|
|
305
|
-
useAnimatedReaction(() => targetIndex.value, (newIndex, preIndex) => {
|
|
306
|
-
// 这里必须传递函数名, 直接写()=> {}形式会报 访问了未sharedValue信息
|
|
307
|
-
const isInit = !preIndex && newIndex === 0;
|
|
308
|
-
if (!isInit && props.current !== newIndex && props.bindchange) {
|
|
309
|
-
runOnJS(handleSwiperChange)(newIndex);
|
|
310
|
-
}
|
|
311
|
-
});
|
|
312
|
-
useEffect(() => {
|
|
313
|
-
// 这里stepValue 有时候拿不到
|
|
314
|
-
const stepValue = getStepValue();
|
|
315
|
-
if (isNaN(+stepValue)) {
|
|
316
|
-
return;
|
|
317
|
-
}
|
|
318
|
-
step.value = stepValue;
|
|
319
|
-
const targetOffset = getInitOffset();
|
|
320
|
-
if (props.current !== undefined && (props.current !== targetIndex.value || (props.current === 0 && targetIndex.value > 0))) {
|
|
321
|
-
targetIndex.value = props.current;
|
|
322
|
-
offset.value = withTiming(targetOffset, {
|
|
323
|
-
duration: easeDuration,
|
|
324
|
-
easing: easeMap[easeingFunc]
|
|
325
|
-
}, () => {
|
|
326
|
-
offset.value = targetOffset;
|
|
327
|
-
});
|
|
328
|
-
}
|
|
329
|
-
else {
|
|
330
|
-
offset.value = targetOffset;
|
|
331
|
-
}
|
|
332
|
-
}, [props.current, widthState, heightState]);
|
|
333
|
-
useEffect(() => {
|
|
334
|
-
const stepValue = getStepValue();
|
|
335
|
-
if (isNaN(+stepValue)) {
|
|
336
|
-
return;
|
|
337
|
-
}
|
|
338
|
-
const targetOffset = getInitOffset();
|
|
339
|
-
if (props.autoplay) {
|
|
340
|
-
pauseLoop();
|
|
341
|
-
offset.value = targetOffset;
|
|
342
|
-
resumeLoop();
|
|
343
|
-
}
|
|
344
|
-
else {
|
|
345
|
-
pauseLoop();
|
|
346
|
-
}
|
|
347
|
-
return () => { pauseLoop(); };
|
|
348
|
-
}, [props.autoplay, widthState, heightState]);
|
|
349
|
-
function getTargetPosition(eventData) {
|
|
350
|
-
'worklet';
|
|
351
|
-
// 移动的距离
|
|
352
|
-
const { translation } = eventData;
|
|
353
|
-
let resetOffsetPos = 0;
|
|
354
|
-
let selectedIndex = targetIndex.value;
|
|
355
|
-
// 是否临界点
|
|
356
|
-
let isCriticalItem = false;
|
|
357
|
-
// 真实滚动到的偏移量坐标
|
|
358
|
-
let moveToTargetPos = 0;
|
|
359
|
-
// 当前的位置
|
|
360
|
-
const currentOffset = offset.value;
|
|
361
|
-
const currentIndex = Math.abs(currentOffset) / step.value;
|
|
362
|
-
const moveToIndex = translation < 0 ? Math.ceil(currentIndex) : Math.floor(currentIndex);
|
|
363
|
-
// 实际应该定位的索引值
|
|
364
|
-
if (!props.circular) {
|
|
365
|
-
selectedIndex = moveToIndex;
|
|
366
|
-
moveToTargetPos = selectedIndex * step.value;
|
|
367
|
-
}
|
|
368
|
-
else {
|
|
369
|
-
if (moveToIndex >= totalElements.value + patchElementNum) {
|
|
370
|
-
selectedIndex = moveToIndex - (totalElements.value + patchElementNum);
|
|
371
|
-
resetOffsetPos = (selectedIndex + patchElementNum) * step.value;
|
|
372
|
-
moveToTargetPos = moveToIndex * step.value;
|
|
373
|
-
isCriticalItem = true;
|
|
374
|
-
}
|
|
375
|
-
else if (moveToIndex <= patchElementNum - 1) {
|
|
376
|
-
selectedIndex = moveToIndex === 0 ? totalElements.value - patchElementNum : totalElements.value - 1;
|
|
377
|
-
resetOffsetPos = (selectedIndex + patchElementNum) * step.value;
|
|
378
|
-
moveToTargetPos = moveToIndex * step.value;
|
|
379
|
-
isCriticalItem = true;
|
|
380
|
-
}
|
|
381
|
-
else {
|
|
382
|
-
selectedIndex = moveToIndex - patchElementNum;
|
|
383
|
-
moveToTargetPos = moveToIndex * step.value;
|
|
384
|
-
}
|
|
385
|
-
}
|
|
386
|
-
return {
|
|
387
|
-
selectedIndex,
|
|
388
|
-
isCriticalItem,
|
|
389
|
-
resetOffset: -resetOffsetPos,
|
|
390
|
-
targetOffset: -moveToTargetPos
|
|
391
|
-
};
|
|
392
|
-
}
|
|
393
|
-
function canMove(eventData) {
|
|
394
|
-
'worklet';
|
|
395
|
-
const { translation } = eventData;
|
|
396
|
-
const stepValue = getStepValue();
|
|
397
|
-
const currentOffset = Math.abs(offset.value);
|
|
398
|
-
if (!props.circular) {
|
|
399
|
-
if (translation < 0) {
|
|
400
|
-
return currentOffset + Math.abs(translation) < stepValue * (totalElements.value - 1);
|
|
401
|
-
}
|
|
402
|
-
else {
|
|
403
|
-
return currentOffset - Math.abs(translation) > 0;
|
|
404
|
-
}
|
|
405
|
-
}
|
|
406
|
-
else {
|
|
407
|
-
return true;
|
|
408
|
-
}
|
|
409
|
-
}
|
|
410
|
-
function handleEnd(eventData) {
|
|
411
|
-
'worklet';
|
|
412
|
-
const { isCriticalItem, targetOffset, resetOffset, selectedIndex } = getTargetPosition(eventData);
|
|
413
|
-
if (isCriticalItem) {
|
|
414
|
-
offset.value = withTiming(targetOffset, {
|
|
415
|
-
duration: easeDuration,
|
|
416
|
-
easing: easeMap[easeingFunc]
|
|
417
|
-
}, () => {
|
|
418
|
-
if (touchfinish.value !== false) {
|
|
419
|
-
targetIndex.value = selectedIndex;
|
|
420
|
-
offset.value = resetOffset;
|
|
421
|
-
runOnJS(resumeLoop)();
|
|
422
|
-
}
|
|
423
|
-
});
|
|
424
|
-
}
|
|
425
|
-
else {
|
|
426
|
-
offset.value = withTiming(targetOffset, {
|
|
427
|
-
duration: easeDuration,
|
|
428
|
-
easing: easeMap[easeingFunc]
|
|
429
|
-
}, () => {
|
|
430
|
-
if (touchfinish.value !== false) {
|
|
431
|
-
targetIndex.value = selectedIndex;
|
|
432
|
-
offset.value = targetOffset;
|
|
433
|
-
runOnJS(resumeLoop)();
|
|
434
|
-
}
|
|
435
|
-
});
|
|
436
|
-
}
|
|
437
|
-
}
|
|
438
|
-
function handleBack(eventData) {
|
|
439
|
-
'worklet';
|
|
440
|
-
const { translation } = eventData;
|
|
441
|
-
// 向右滑动的back:trans < 0, 向左滑动的back: trans < 0
|
|
442
|
-
const currentOffset = Math.abs(offset.value);
|
|
443
|
-
const curIndex = currentOffset / step.value;
|
|
444
|
-
const moveToIndex = (translation < 0 ? Math.floor(curIndex) : Math.ceil(curIndex)) - patchElementNum;
|
|
445
|
-
const targetOffset = -(moveToIndex + patchElementNum) * step.value;
|
|
446
|
-
offset.value = withTiming(targetOffset, {
|
|
447
|
-
duration: easeDuration,
|
|
448
|
-
easing: easeMap[easeingFunc]
|
|
449
|
-
}, () => {
|
|
450
|
-
if (touchfinish.value !== false) {
|
|
451
|
-
offset.value = targetOffset;
|
|
452
|
-
targetIndex.value = moveToIndex;
|
|
453
|
-
runOnJS(resumeLoop)();
|
|
454
|
-
}
|
|
455
|
-
});
|
|
456
|
-
}
|
|
457
|
-
function handleLongPress(eventData) {
|
|
458
|
-
'worklet';
|
|
459
|
-
const { translation } = eventData;
|
|
460
|
-
const currentOffset = Math.abs(offset.value);
|
|
461
|
-
const half = currentOffset % step.value > step.value / 2;
|
|
462
|
-
// 向右trans < 0, 向左trans > 0
|
|
463
|
-
const isExceedHalf = translation < 0 ? half : !half;
|
|
464
|
-
if (+translation === 0) {
|
|
465
|
-
runOnJS(resumeLoop)();
|
|
466
|
-
}
|
|
467
|
-
else if (isExceedHalf) {
|
|
468
|
-
handleEnd(eventData);
|
|
469
|
-
}
|
|
470
|
-
else {
|
|
471
|
-
handleBack(eventData);
|
|
472
|
-
}
|
|
473
|
-
}
|
|
474
|
-
function reachBoundary(eventData) {
|
|
475
|
-
'worklet';
|
|
476
|
-
// 移动的距离
|
|
477
|
-
const { translation } = eventData;
|
|
478
|
-
const elementsLength = step.value * totalElements.value;
|
|
479
|
-
let isBoundary = false;
|
|
480
|
-
let resetOffset = 0;
|
|
481
|
-
// Y轴向下滚动, transDistance > 0, 向上滚动 < 0 X轴向左滚动, transDistance > 0
|
|
482
|
-
const currentOffset = offset.value;
|
|
483
|
-
const moveStep = Math.ceil(translation / elementsLength);
|
|
484
|
-
if (translation < 0) {
|
|
485
|
-
const posEnd = (totalElements.value + patchElementNum + 1) * step.value;
|
|
486
|
-
const posReverseEnd = (patchElementNum - 1) * step.value;
|
|
487
|
-
if (currentOffset < -posEnd + step.value) {
|
|
488
|
-
isBoundary = true;
|
|
489
|
-
resetOffset = Math.abs(moveStep) === 0 ? patchElementNum * step.value + translation : moveStep * elementsLength;
|
|
490
|
-
}
|
|
491
|
-
if (currentOffset > -posReverseEnd) {
|
|
492
|
-
isBoundary = true;
|
|
493
|
-
resetOffset = moveStep * elementsLength;
|
|
494
|
-
}
|
|
495
|
-
}
|
|
496
|
-
else if (translation > 0) {
|
|
497
|
-
const posEnd = (patchElementNum - 1) * step.value;
|
|
498
|
-
const posReverseEnd = (patchElementNum + totalElements.value) * step.value;
|
|
499
|
-
if (currentOffset > -posEnd) {
|
|
500
|
-
isBoundary = true;
|
|
501
|
-
resetOffset = moveStep * elementsLength + step.value + (moveStep === 1 ? translation : 0);
|
|
502
|
-
}
|
|
503
|
-
if (currentOffset < -posReverseEnd) {
|
|
504
|
-
isBoundary = true;
|
|
505
|
-
resetOffset = moveStep * elementsLength + patchElementNum * step.value;
|
|
506
|
-
}
|
|
507
|
-
}
|
|
508
|
-
return {
|
|
509
|
-
isBoundary,
|
|
510
|
-
resetOffset: -resetOffset
|
|
511
|
-
};
|
|
512
|
-
}
|
|
513
|
-
const gestureHandler = Gesture.Pan()
|
|
514
|
-
.onBegin((e) => {
|
|
515
|
-
'worklet';
|
|
516
|
-
touchfinish.value = false;
|
|
517
|
-
cancelAnimation(offset);
|
|
518
|
-
runOnJS(pauseLoop)();
|
|
519
|
-
preAbsolutePos.value = e[strAbso];
|
|
520
|
-
})
|
|
521
|
-
.onStart(() => {
|
|
522
|
-
'worklet';
|
|
523
|
-
isTriggerStart.value = true;
|
|
524
|
-
})
|
|
525
|
-
.onTouchesMove((e) => {
|
|
526
|
-
'worklet';
|
|
527
|
-
const touchEventData = e.changedTouches[0];
|
|
528
|
-
const moveDistance = touchEventData[strAbso] - preAbsolutePos.value;
|
|
529
|
-
customTrans.value = moveDistance;
|
|
530
|
-
const eventData = {
|
|
531
|
-
translation: moveDistance
|
|
532
|
-
};
|
|
533
|
-
// 处理用户一直拖拽到临界点的场景, 不会执行onEnd
|
|
534
|
-
if (!props.circular && !canMove(eventData)) {
|
|
535
|
-
return;
|
|
536
|
-
}
|
|
537
|
-
const { isBoundary, resetOffset } = reachBoundary(eventData);
|
|
538
|
-
if (isBoundary && props.circular && !touchfinish.value) {
|
|
539
|
-
offset.value = resetOffset;
|
|
540
|
-
}
|
|
541
|
-
else {
|
|
542
|
-
offset.value = moveDistance + offset.value;
|
|
543
|
-
}
|
|
544
|
-
preAbsolutePos.value = touchEventData[strAbso];
|
|
545
|
-
})
|
|
546
|
-
.onTouchesUp((e) => {
|
|
547
|
-
'worklet';
|
|
548
|
-
// 未触发移动不会触发onStart事件, touches事件拿到的数据只有absoluteX 和 x, 无法判断方向
|
|
549
|
-
if (!isTriggerStart.value) {
|
|
550
|
-
const eventData = {
|
|
551
|
-
translation: customTrans.value
|
|
552
|
-
};
|
|
553
|
-
handleLongPress(eventData);
|
|
554
|
-
}
|
|
555
|
-
isTriggerStart.value = false;
|
|
556
|
-
touchfinish.value = true;
|
|
557
|
-
})
|
|
558
|
-
.onEnd((e) => {
|
|
559
|
-
'worklet';
|
|
560
|
-
const eventData = {
|
|
561
|
-
translation: e[strTrans]
|
|
562
|
-
};
|
|
563
|
-
if (!props.circular && !canMove(eventData) && isTriggerStart.value) {
|
|
564
|
-
return;
|
|
565
|
-
}
|
|
566
|
-
if (Math.abs(e[strVelocity]) < longPressRatio) {
|
|
567
|
-
handleLongPress(eventData);
|
|
568
|
-
}
|
|
569
|
-
else {
|
|
570
|
-
handleEnd(eventData);
|
|
571
|
-
}
|
|
572
|
-
});
|
|
573
|
-
const animatedStyles = useAnimatedStyle(() => {
|
|
574
|
-
if (dir.value === 'x') {
|
|
575
|
-
return { transform: [{ translateX: offset.value }] };
|
|
576
|
-
}
|
|
577
|
-
else {
|
|
578
|
-
return { transform: [{ translateY: offset.value }] };
|
|
579
|
-
}
|
|
580
|
-
});
|
|
581
|
-
function renderSwiper() {
|
|
582
|
-
return (<View style={[normalStyle, layoutStyle, styles.swiper]} {...layoutProps} {...innerProps}>
|
|
583
|
-
<Animated.View style={[{ flexDirection: dir.value === 'x' ? 'row' : 'column' }, animatedStyles]}>
|
|
584
|
-
{wrapChildren({
|
|
585
|
-
children: arrPages
|
|
586
|
-
}, {
|
|
587
|
-
hasVarDec,
|
|
588
|
-
varContext: varContextRef.current,
|
|
589
|
-
textStyle,
|
|
590
|
-
textProps
|
|
591
|
-
})}
|
|
592
|
-
</Animated.View>
|
|
593
|
-
{showsPagination && renderPagination()}
|
|
594
|
-
</View>);
|
|
595
|
-
}
|
|
596
|
-
if (totalElements.value === 1) {
|
|
597
|
-
return renderSwiper();
|
|
598
|
-
}
|
|
599
|
-
else {
|
|
600
|
-
return (<GestureDetector gesture={gestureHandler}>
|
|
601
|
-
{renderSwiper()}
|
|
602
|
-
</GestureDetector>);
|
|
603
|
-
}
|
|
604
|
-
});
|
|
605
|
-
SwiperWrapper.displayName = 'MpxSwiperWrapper';
|
|
606
|
-
export default SwiperWrapper;
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { createContext, useContext } from 'react';
|
|
2
|
-
export const PickerViewColumnAnimationContext = createContext(undefined);
|
|
3
|
-
export const usePickerViewColumnAnimationContext = () => {
|
|
4
|
-
const value = useContext(PickerViewColumnAnimationContext);
|
|
5
|
-
if (value === undefined) {
|
|
6
|
-
throw new Error('usePickerViewColumnAnimationContext must be called from within PickerViewColumnAnimationContext.Provider!');
|
|
7
|
-
}
|
|
8
|
-
return value;
|
|
9
|
-
};
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { StyleSheet, View } from 'react-native';
|
|
3
|
-
import LinearGradient from 'react-native-linear-gradient';
|
|
4
|
-
const _PickerViewMask = ({ itemHeight, maskContainerStyle }) => {
|
|
5
|
-
return (<View style={[styles.overlayContainer, maskContainerStyle]} pointerEvents={'none'}>
|
|
6
|
-
<LinearGradient colors={['rgba(255,255,255,1)', 'rgba(255,255,255,0.5)']} style={{ flex: 1 }}/>
|
|
7
|
-
<View style={{ height: itemHeight }}/>
|
|
8
|
-
<LinearGradient colors={['rgba(255,255,255,0.5)', 'rgba(255,255,255,1)']} style={{ flex: 1 }}/>
|
|
9
|
-
</View>);
|
|
10
|
-
};
|
|
11
|
-
const styles = StyleSheet.create({
|
|
12
|
-
overlayContainer: {
|
|
13
|
-
...StyleSheet.absoluteFillObject,
|
|
14
|
-
zIndex: 100
|
|
15
|
-
}
|
|
16
|
-
});
|
|
17
|
-
_PickerViewMask.displayName = 'MpxPickerViewMask';
|
|
18
|
-
export default _PickerViewMask;
|