@mpxjs/webpack-plugin 2.8.25-alpha.21 → 2.8.25-alpha.22
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/lib/runtime/components/react/dist/KeyboardAvoidingView.jsx +89 -0
- package/lib/runtime/components/react/dist/context.js +14 -0
- package/lib/runtime/components/react/dist/event.config.js +27 -0
- package/lib/runtime/components/react/dist/getInnerListeners.js +262 -0
- package/lib/runtime/components/react/dist/mpx-button.jsx +271 -0
- package/lib/runtime/components/react/dist/mpx-canvas/Bus.js +60 -0
- package/lib/runtime/components/react/dist/mpx-canvas/CanvasGradient.js +15 -0
- package/lib/runtime/components/react/dist/mpx-canvas/CanvasRenderingContext2D.js +84 -0
- package/lib/runtime/components/react/dist/mpx-canvas/Image.js +87 -0
- package/lib/runtime/components/react/dist/mpx-canvas/ImageData.js +15 -0
- package/lib/runtime/components/react/dist/mpx-canvas/constructorsRegistry.js +28 -0
- package/lib/runtime/components/react/dist/mpx-canvas/html.js +341 -0
- package/lib/runtime/components/react/dist/mpx-canvas/index.jsx +236 -0
- package/lib/runtime/components/react/dist/mpx-canvas/utils.jsx +89 -0
- package/lib/runtime/components/react/dist/mpx-checkbox-group.jsx +90 -0
- package/lib/runtime/components/react/dist/mpx-checkbox.jsx +131 -0
- package/lib/runtime/components/react/dist/mpx-form.jsx +68 -0
- package/lib/runtime/components/react/dist/mpx-icon/icons/cancel.png +0 -0
- package/lib/runtime/components/react/dist/mpx-icon/icons/clear.png +0 -0
- package/lib/runtime/components/react/dist/mpx-icon/icons/download.png +0 -0
- package/lib/runtime/components/react/dist/mpx-icon/icons/info.png +0 -0
- package/lib/runtime/components/react/dist/mpx-icon/icons/search.png +0 -0
- package/lib/runtime/components/react/dist/mpx-icon/icons/success.png +0 -0
- package/lib/runtime/components/react/dist/mpx-icon/icons/success_no_circle.png +0 -0
- package/lib/runtime/components/react/dist/mpx-icon/icons/waiting.png +0 -0
- package/lib/runtime/components/react/dist/mpx-icon/icons/warn.png +0 -0
- package/lib/runtime/components/react/dist/mpx-icon/index.jsx +50 -0
- package/lib/runtime/components/react/dist/mpx-image.jsx +292 -0
- package/lib/runtime/components/react/dist/mpx-input.jsx +292 -0
- package/lib/runtime/components/react/dist/mpx-label.jsx +52 -0
- package/lib/runtime/components/react/dist/mpx-movable-area.jsx +32 -0
- package/lib/runtime/components/react/dist/mpx-movable-view.jsx +468 -0
- package/lib/runtime/components/react/dist/mpx-navigator.jsx +33 -0
- package/lib/runtime/components/react/dist/mpx-picker/date.jsx +74 -0
- package/lib/runtime/components/react/dist/mpx-picker/index.jsx +141 -0
- package/lib/runtime/components/react/dist/mpx-picker/multiSelector.jsx +147 -0
- package/lib/runtime/components/react/dist/mpx-picker/region.jsx +99 -0
- package/lib/runtime/components/react/dist/mpx-picker/regionData.js +6099 -0
- package/lib/runtime/components/react/dist/mpx-picker/selector.jsx +81 -0
- package/lib/runtime/components/react/dist/mpx-picker/time.jsx +242 -0
- package/lib/runtime/components/react/dist/mpx-picker/type.js +1 -0
- package/lib/runtime/components/react/dist/mpx-picker-view-column-item.jsx +35 -0
- package/lib/runtime/components/react/dist/mpx-picker-view-column.jsx +193 -0
- package/lib/runtime/components/react/dist/mpx-picker-view.jsx +125 -0
- package/lib/runtime/components/react/dist/mpx-portal/index.jsx +30 -0
- package/lib/runtime/components/react/dist/mpx-portal/portal-host.jsx +112 -0
- package/lib/runtime/components/react/dist/mpx-portal/portal-manager.jsx +41 -0
- package/lib/runtime/components/react/dist/mpx-radio-group.jsx +86 -0
- package/lib/runtime/components/react/dist/mpx-radio.jsx +140 -0
- package/lib/runtime/components/react/dist/mpx-rich-text/html.js +39 -0
- package/lib/runtime/components/react/dist/mpx-rich-text/index.jsx +62 -0
- package/lib/runtime/components/react/dist/mpx-root-portal.jsx +17 -0
- package/lib/runtime/components/react/dist/mpx-scroll-view.jsx +372 -0
- package/lib/runtime/components/react/dist/mpx-simple-text.jsx +11 -0
- package/lib/runtime/components/react/dist/mpx-swiper-item.jsx +59 -0
- package/lib/runtime/components/react/dist/mpx-swiper.jsx +671 -0
- package/lib/runtime/components/react/dist/mpx-switch.jsx +97 -0
- package/lib/runtime/components/react/dist/mpx-text.jsx +41 -0
- package/lib/runtime/components/react/dist/mpx-textarea.jsx +40 -0
- package/lib/runtime/components/react/dist/mpx-video.jsx +248 -0
- package/lib/runtime/components/react/dist/mpx-view.jsx +611 -0
- package/lib/runtime/components/react/dist/mpx-web-view.jsx +289 -0
- package/lib/runtime/components/react/dist/parser.js +218 -0
- package/lib/runtime/components/react/dist/pickerFaces.js +76 -0
- package/lib/runtime/components/react/dist/pickerVIewContext.js +14 -0
- package/lib/runtime/components/react/dist/pickerViewIndicator.jsx +23 -0
- package/lib/runtime/components/react/dist/pickerViewMask.jsx +18 -0
- package/lib/runtime/components/react/dist/useAnimationHooks.js +346 -0
- package/lib/runtime/components/react/dist/useNodesRef.js +16 -0
- package/lib/runtime/components/react/dist/utils.jsx +599 -0
- package/package.json +6 -3
- package/LICENSE +0 -433
|
@@ -0,0 +1,468 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ✔ direction
|
|
3
|
+
* ✔ inertia
|
|
4
|
+
* ✔ out-of-bounds
|
|
5
|
+
* ✔ x
|
|
6
|
+
* ✔ y
|
|
7
|
+
* ✘ damping
|
|
8
|
+
* ✘ friction
|
|
9
|
+
* ✔ disabled
|
|
10
|
+
* ✘ scale
|
|
11
|
+
* ✘ scale-min
|
|
12
|
+
* ✘ scale-max
|
|
13
|
+
* ✘ scale-value
|
|
14
|
+
* ✔ animation
|
|
15
|
+
* ✔ bindchange
|
|
16
|
+
* ✘ bindscale
|
|
17
|
+
* ✔ htouchmove
|
|
18
|
+
* ✔ vtouchmove
|
|
19
|
+
*/
|
|
20
|
+
import { useEffect, forwardRef, useContext, useCallback, useRef, useMemo, createElement } from 'react';
|
|
21
|
+
import { StyleSheet } from 'react-native';
|
|
22
|
+
import useInnerProps, { getCustomEvent } from './getInnerListeners';
|
|
23
|
+
import useNodesRef from './useNodesRef';
|
|
24
|
+
import { MovableAreaContext } from './context';
|
|
25
|
+
import { useTransformStyle, splitProps, splitStyle, HIDDEN_STYLE, wrapChildren, flatGesture, extendObject, omit, useNavigation } from './utils';
|
|
26
|
+
import { GestureDetector, Gesture } from 'react-native-gesture-handler';
|
|
27
|
+
import Animated, { useSharedValue, useAnimatedStyle, withDecay, runOnJS, runOnUI, useAnimatedReaction, withSpring } from 'react-native-reanimated';
|
|
28
|
+
import { collectDataset, noop } from '@mpxjs/utils';
|
|
29
|
+
const styles = StyleSheet.create({
|
|
30
|
+
container: {
|
|
31
|
+
position: 'absolute',
|
|
32
|
+
left: 0,
|
|
33
|
+
top: 0
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
const _MovableView = forwardRef((movableViewProps, ref) => {
|
|
37
|
+
const { textProps, innerProps: props = {} } = splitProps(movableViewProps);
|
|
38
|
+
const movableGestureRef = useRef();
|
|
39
|
+
const layoutRef = useRef({});
|
|
40
|
+
const changeSource = useRef('');
|
|
41
|
+
const hasLayoutRef = useRef(false);
|
|
42
|
+
const propsRef = useRef({});
|
|
43
|
+
propsRef.current = (props || {});
|
|
44
|
+
const { x = 0, y = 0, inertia = false, disabled = false, animation = true, 'out-of-bounds': outOfBounds = false, 'enable-var': enableVar, 'external-var-context': externalVarContext, 'parent-font-size': parentFontSize, 'parent-width': parentWidth, 'parent-height': parentHeight, direction = 'none', 'simultaneous-handlers': originSimultaneousHandlers = [], 'wait-for': waitFor = [], style = {}, bindtouchstart, catchtouchstart, bindhtouchmove, bindvtouchmove, bindtouchmove, catchhtouchmove, catchvtouchmove, catchtouchmove, bindtouchend, catchtouchend } = props;
|
|
45
|
+
const { hasSelfPercent, normalStyle, hasVarDec, varContextRef, setWidth, setHeight } = useTransformStyle(Object.assign({}, style, styles.container), { enableVar, externalVarContext, parentFontSize, parentWidth, parentHeight });
|
|
46
|
+
const navigation = useNavigation();
|
|
47
|
+
const prevSimultaneousHandlersRef = useRef(originSimultaneousHandlers || []);
|
|
48
|
+
const prevWaitForHandlersRef = useRef(waitFor || []);
|
|
49
|
+
const gestureSwitch = useRef(false);
|
|
50
|
+
const { textStyle, innerStyle } = splitStyle(normalStyle);
|
|
51
|
+
const offsetX = useSharedValue(x);
|
|
52
|
+
const offsetY = useSharedValue(y);
|
|
53
|
+
const startPosition = useSharedValue({
|
|
54
|
+
x: 0,
|
|
55
|
+
y: 0
|
|
56
|
+
});
|
|
57
|
+
const draggableXRange = useSharedValue([0, 0]);
|
|
58
|
+
const draggableYRange = useSharedValue([0, 0]);
|
|
59
|
+
const isMoving = useSharedValue(false);
|
|
60
|
+
const xInertialMotion = useSharedValue(false);
|
|
61
|
+
const yInertialMotion = useSharedValue(false);
|
|
62
|
+
const isFirstTouch = useSharedValue(true);
|
|
63
|
+
const touchEvent = useSharedValue('');
|
|
64
|
+
const MovableAreaLayout = useContext(MovableAreaContext);
|
|
65
|
+
const simultaneousHandlers = flatGesture(originSimultaneousHandlers);
|
|
66
|
+
const waitForHandlers = flatGesture(waitFor);
|
|
67
|
+
const nodeRef = useRef(null);
|
|
68
|
+
useNodesRef(props, ref, nodeRef, {
|
|
69
|
+
style: normalStyle,
|
|
70
|
+
gestureRef: movableGestureRef
|
|
71
|
+
});
|
|
72
|
+
const hasSimultaneousHandlersChanged = prevSimultaneousHandlersRef.current.length !== (originSimultaneousHandlers?.length || 0) ||
|
|
73
|
+
(originSimultaneousHandlers || []).some((handler, index) => handler !== prevSimultaneousHandlersRef.current[index]);
|
|
74
|
+
const hasWaitForHandlersChanged = prevWaitForHandlersRef.current.length !== (waitFor?.length || 0) ||
|
|
75
|
+
(waitFor || []).some((handler, index) => handler !== prevWaitForHandlersRef.current[index]);
|
|
76
|
+
if (hasSimultaneousHandlersChanged || hasWaitForHandlersChanged) {
|
|
77
|
+
gestureSwitch.current = !gestureSwitch.current;
|
|
78
|
+
}
|
|
79
|
+
prevSimultaneousHandlersRef.current = originSimultaneousHandlers || [];
|
|
80
|
+
prevWaitForHandlersRef.current = waitFor || [];
|
|
81
|
+
const handleTriggerChange = useCallback(({ x, y, type }) => {
|
|
82
|
+
const { bindchange } = propsRef.current;
|
|
83
|
+
if (!bindchange)
|
|
84
|
+
return;
|
|
85
|
+
let source = '';
|
|
86
|
+
if (type !== 'setData') {
|
|
87
|
+
source = getTouchSource(x, y);
|
|
88
|
+
}
|
|
89
|
+
else {
|
|
90
|
+
changeSource.current = '';
|
|
91
|
+
}
|
|
92
|
+
bindchange(getCustomEvent('change', {}, {
|
|
93
|
+
detail: {
|
|
94
|
+
x,
|
|
95
|
+
y,
|
|
96
|
+
source
|
|
97
|
+
},
|
|
98
|
+
layoutRef
|
|
99
|
+
}, propsRef.current));
|
|
100
|
+
}, []);
|
|
101
|
+
useEffect(() => {
|
|
102
|
+
runOnUI(() => {
|
|
103
|
+
if (offsetX.value !== x || offsetY.value !== y) {
|
|
104
|
+
const { x: newX, y: newY } = checkBoundaryPosition({ positionX: Number(x), positionY: Number(y) });
|
|
105
|
+
if (direction === 'horizontal' || direction === 'all') {
|
|
106
|
+
offsetX.value = animation
|
|
107
|
+
? withSpring(newX, {
|
|
108
|
+
duration: 1500,
|
|
109
|
+
dampingRatio: 0.8
|
|
110
|
+
})
|
|
111
|
+
: newX;
|
|
112
|
+
}
|
|
113
|
+
if (direction === 'vertical' || direction === 'all') {
|
|
114
|
+
offsetY.value = animation
|
|
115
|
+
? withSpring(newY, {
|
|
116
|
+
duration: 1500,
|
|
117
|
+
dampingRatio: 0.8
|
|
118
|
+
})
|
|
119
|
+
: newY;
|
|
120
|
+
}
|
|
121
|
+
runOnJS(handleTriggerChange)({
|
|
122
|
+
x: newX,
|
|
123
|
+
y: newY,
|
|
124
|
+
type: 'setData'
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
})();
|
|
128
|
+
}, [x, y]);
|
|
129
|
+
useEffect(() => {
|
|
130
|
+
const { width, height } = layoutRef.current;
|
|
131
|
+
if (width && height) {
|
|
132
|
+
resetBoundaryAndCheck({ width, height });
|
|
133
|
+
}
|
|
134
|
+
}, [MovableAreaLayout.height, MovableAreaLayout.width]);
|
|
135
|
+
useAnimatedReaction(() => ({
|
|
136
|
+
offsetX: offsetX.value,
|
|
137
|
+
offsetY: offsetY.value
|
|
138
|
+
}), (currentValue) => {
|
|
139
|
+
const { offsetX, offsetY } = currentValue;
|
|
140
|
+
runOnJS(handleTriggerChange)({
|
|
141
|
+
x: offsetX,
|
|
142
|
+
y: offsetY
|
|
143
|
+
});
|
|
144
|
+
});
|
|
145
|
+
const getTouchSource = useCallback((offsetX, offsetY) => {
|
|
146
|
+
const hasOverBoundary = offsetX < draggableXRange.value[0] || offsetX > draggableXRange.value[1] ||
|
|
147
|
+
offsetY < draggableYRange.value[0] || offsetY > draggableYRange.value[1];
|
|
148
|
+
let source = changeSource.current;
|
|
149
|
+
if (hasOverBoundary) {
|
|
150
|
+
if (isMoving.value) {
|
|
151
|
+
source = 'touch-out-of-bounds';
|
|
152
|
+
}
|
|
153
|
+
else {
|
|
154
|
+
source = 'out-of-bounds';
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
else {
|
|
158
|
+
if (isMoving.value) {
|
|
159
|
+
source = 'touch';
|
|
160
|
+
}
|
|
161
|
+
else if ((xInertialMotion.value || yInertialMotion.value) && (changeSource.current === 'touch' || changeSource.current === 'friction')) {
|
|
162
|
+
source = 'friction';
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
changeSource.current = source;
|
|
166
|
+
return source;
|
|
167
|
+
}, []);
|
|
168
|
+
const setBoundary = useCallback(({ width, height }) => {
|
|
169
|
+
const top = (style.position === 'absolute' && style.top) || 0;
|
|
170
|
+
const left = (style.position === 'absolute' && style.left) || 0;
|
|
171
|
+
const scaledWidth = width || 0;
|
|
172
|
+
const scaledHeight = height || 0;
|
|
173
|
+
const maxY = MovableAreaLayout.height - scaledHeight - top;
|
|
174
|
+
const maxX = MovableAreaLayout.width - scaledWidth - left;
|
|
175
|
+
let xRange;
|
|
176
|
+
let yRange;
|
|
177
|
+
if (MovableAreaLayout.width < scaledWidth) {
|
|
178
|
+
xRange = [maxX, 0];
|
|
179
|
+
}
|
|
180
|
+
else {
|
|
181
|
+
xRange = [left === 0 ? 0 : -left, maxX < 0 ? 0 : maxX];
|
|
182
|
+
}
|
|
183
|
+
if (MovableAreaLayout.height < scaledHeight) {
|
|
184
|
+
yRange = [maxY, 0];
|
|
185
|
+
}
|
|
186
|
+
else {
|
|
187
|
+
yRange = [top === 0 ? 0 : -top, maxY < 0 ? 0 : maxY];
|
|
188
|
+
}
|
|
189
|
+
draggableXRange.value = xRange;
|
|
190
|
+
draggableYRange.value = yRange;
|
|
191
|
+
}, [MovableAreaLayout.height, MovableAreaLayout.width, style.position, style.top, style.left]);
|
|
192
|
+
const checkBoundaryPosition = useCallback(({ positionX, positionY }) => {
|
|
193
|
+
'worklet';
|
|
194
|
+
let x = positionX;
|
|
195
|
+
let y = positionY;
|
|
196
|
+
// 计算边界限制
|
|
197
|
+
if (x > draggableXRange.value[1]) {
|
|
198
|
+
x = draggableXRange.value[1];
|
|
199
|
+
}
|
|
200
|
+
else if (x < draggableXRange.value[0]) {
|
|
201
|
+
x = draggableXRange.value[0];
|
|
202
|
+
}
|
|
203
|
+
if (y > draggableYRange.value[1]) {
|
|
204
|
+
y = draggableYRange.value[1];
|
|
205
|
+
}
|
|
206
|
+
else if (y < draggableYRange.value[0]) {
|
|
207
|
+
y = draggableYRange.value[0];
|
|
208
|
+
}
|
|
209
|
+
return { x, y };
|
|
210
|
+
}, []);
|
|
211
|
+
const resetBoundaryAndCheck = ({ width, height }) => {
|
|
212
|
+
setBoundary({ width, height });
|
|
213
|
+
runOnUI(() => {
|
|
214
|
+
const positionX = offsetX.value;
|
|
215
|
+
const positionY = offsetY.value;
|
|
216
|
+
const { x: newX, y: newY } = checkBoundaryPosition({ positionX, positionY });
|
|
217
|
+
if (positionX !== newX) {
|
|
218
|
+
offsetX.value = newX;
|
|
219
|
+
}
|
|
220
|
+
if (positionY !== newY) {
|
|
221
|
+
offsetY.value = newY;
|
|
222
|
+
}
|
|
223
|
+
})();
|
|
224
|
+
};
|
|
225
|
+
const onLayout = (e) => {
|
|
226
|
+
hasLayoutRef.current = true;
|
|
227
|
+
if (hasSelfPercent) {
|
|
228
|
+
const { width, height } = e?.nativeEvent?.layout || {};
|
|
229
|
+
setWidth(width || 0);
|
|
230
|
+
setHeight(height || 0);
|
|
231
|
+
}
|
|
232
|
+
nodeRef.current?.measure((x, y, width, height) => {
|
|
233
|
+
const { y: navigationY = 0 } = navigation?.layout || {};
|
|
234
|
+
layoutRef.current = { x, y: y - navigationY, width, height, offsetLeft: 0, offsetTop: 0 };
|
|
235
|
+
resetBoundaryAndCheck({ width, height });
|
|
236
|
+
});
|
|
237
|
+
props.onLayout && props.onLayout(e);
|
|
238
|
+
};
|
|
239
|
+
const extendEvent = useCallback((e, type) => {
|
|
240
|
+
const { y: navigationY = 0 } = navigation?.layout || {};
|
|
241
|
+
const touchArr = [e.changedTouches, e.allTouches];
|
|
242
|
+
touchArr.forEach(touches => {
|
|
243
|
+
touches && touches.forEach((item) => {
|
|
244
|
+
item.pageX = item.absoluteX;
|
|
245
|
+
item.pageY = item.absoluteY - navigationY;
|
|
246
|
+
item.clientX = item.absoluteX;
|
|
247
|
+
item.clientY = item.absoluteY - navigationY;
|
|
248
|
+
});
|
|
249
|
+
});
|
|
250
|
+
Object.assign(e, {
|
|
251
|
+
touches: type === 'end' ? [] : e.allTouches,
|
|
252
|
+
currentTarget: {
|
|
253
|
+
id: props.id || '',
|
|
254
|
+
dataset: collectDataset(props),
|
|
255
|
+
offsetLeft: 0,
|
|
256
|
+
offsetTop: 0
|
|
257
|
+
},
|
|
258
|
+
detail: {}
|
|
259
|
+
});
|
|
260
|
+
}, []);
|
|
261
|
+
const triggerStartOnJS = ({ e }) => {
|
|
262
|
+
extendEvent(e, 'start');
|
|
263
|
+
bindtouchstart && bindtouchstart(e);
|
|
264
|
+
catchtouchstart && catchtouchstart(e);
|
|
265
|
+
};
|
|
266
|
+
const triggerMoveOnJS = ({ e, hasTouchmove, hasCatchTouchmove, touchEvent }) => {
|
|
267
|
+
extendEvent(e, 'move');
|
|
268
|
+
if (hasTouchmove) {
|
|
269
|
+
if (touchEvent === 'htouchmove') {
|
|
270
|
+
bindhtouchmove && bindhtouchmove(e);
|
|
271
|
+
}
|
|
272
|
+
else if (touchEvent === 'vtouchmove') {
|
|
273
|
+
bindvtouchmove && bindvtouchmove(e);
|
|
274
|
+
}
|
|
275
|
+
bindtouchmove && bindtouchmove(e);
|
|
276
|
+
}
|
|
277
|
+
if (hasCatchTouchmove) {
|
|
278
|
+
if (touchEvent === 'htouchmove') {
|
|
279
|
+
catchhtouchmove && catchhtouchmove(e);
|
|
280
|
+
}
|
|
281
|
+
else if (touchEvent === 'vtouchmove') {
|
|
282
|
+
catchvtouchmove && catchvtouchmove(e);
|
|
283
|
+
}
|
|
284
|
+
catchtouchmove && catchtouchmove(e);
|
|
285
|
+
}
|
|
286
|
+
};
|
|
287
|
+
const triggerEndOnJS = ({ e }) => {
|
|
288
|
+
extendEvent(e, 'end');
|
|
289
|
+
bindtouchend && bindtouchend(e);
|
|
290
|
+
catchtouchend && catchtouchend(e);
|
|
291
|
+
};
|
|
292
|
+
const gesture = useMemo(() => {
|
|
293
|
+
const handleTriggerMove = (e) => {
|
|
294
|
+
'worklet';
|
|
295
|
+
const hasTouchmove = !!bindhtouchmove || !!bindvtouchmove || !!bindtouchmove;
|
|
296
|
+
const hasCatchTouchmove = !!catchhtouchmove || !!catchvtouchmove || !!catchtouchmove;
|
|
297
|
+
if (hasTouchmove || hasCatchTouchmove) {
|
|
298
|
+
runOnJS(triggerMoveOnJS)({
|
|
299
|
+
e,
|
|
300
|
+
touchEvent: touchEvent.value,
|
|
301
|
+
hasTouchmove,
|
|
302
|
+
hasCatchTouchmove
|
|
303
|
+
});
|
|
304
|
+
}
|
|
305
|
+
};
|
|
306
|
+
const gesturePan = Gesture.Pan()
|
|
307
|
+
.onTouchesDown((e) => {
|
|
308
|
+
'worklet';
|
|
309
|
+
const changedTouches = e.changedTouches[0] || { x: 0, y: 0 };
|
|
310
|
+
isMoving.value = false;
|
|
311
|
+
startPosition.value = {
|
|
312
|
+
x: changedTouches.x,
|
|
313
|
+
y: changedTouches.y
|
|
314
|
+
};
|
|
315
|
+
if (bindtouchstart || catchtouchstart) {
|
|
316
|
+
runOnJS(triggerStartOnJS)({ e });
|
|
317
|
+
}
|
|
318
|
+
})
|
|
319
|
+
.onTouchesMove((e) => {
|
|
320
|
+
'worklet';
|
|
321
|
+
const changedTouches = e.changedTouches[0] || { x: 0, y: 0 };
|
|
322
|
+
isMoving.value = true;
|
|
323
|
+
if (isFirstTouch.value) {
|
|
324
|
+
touchEvent.value = Math.abs(changedTouches.x - startPosition.value.x) > Math.abs(changedTouches.y - startPosition.value.y) ? 'htouchmove' : 'vtouchmove';
|
|
325
|
+
isFirstTouch.value = false;
|
|
326
|
+
}
|
|
327
|
+
handleTriggerMove(e);
|
|
328
|
+
if (disabled)
|
|
329
|
+
return;
|
|
330
|
+
const changeX = changedTouches.x - startPosition.value.x;
|
|
331
|
+
const changeY = changedTouches.y - startPosition.value.y;
|
|
332
|
+
if (direction === 'horizontal' || direction === 'all') {
|
|
333
|
+
const newX = offsetX.value + changeX;
|
|
334
|
+
if (!outOfBounds) {
|
|
335
|
+
const { x } = checkBoundaryPosition({ positionX: newX, positionY: offsetY.value });
|
|
336
|
+
offsetX.value = x;
|
|
337
|
+
}
|
|
338
|
+
else {
|
|
339
|
+
offsetX.value = newX;
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
if (direction === 'vertical' || direction === 'all') {
|
|
343
|
+
const newY = offsetY.value + changeY;
|
|
344
|
+
if (!outOfBounds) {
|
|
345
|
+
const { y } = checkBoundaryPosition({ positionX: offsetX.value, positionY: newY });
|
|
346
|
+
offsetY.value = y;
|
|
347
|
+
}
|
|
348
|
+
else {
|
|
349
|
+
offsetY.value = newY;
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
})
|
|
353
|
+
.onTouchesUp((e) => {
|
|
354
|
+
'worklet';
|
|
355
|
+
isFirstTouch.value = true;
|
|
356
|
+
isMoving.value = false;
|
|
357
|
+
if (bindtouchend || catchtouchend) {
|
|
358
|
+
runOnJS(triggerEndOnJS)({ e });
|
|
359
|
+
}
|
|
360
|
+
if (disabled)
|
|
361
|
+
return;
|
|
362
|
+
if (!inertia) {
|
|
363
|
+
const { x, y } = checkBoundaryPosition({ positionX: offsetX.value, positionY: offsetY.value });
|
|
364
|
+
if (x !== offsetX.value) {
|
|
365
|
+
offsetX.value = animation
|
|
366
|
+
? withSpring(x, {
|
|
367
|
+
duration: 1500,
|
|
368
|
+
dampingRatio: 0.8
|
|
369
|
+
})
|
|
370
|
+
: x;
|
|
371
|
+
}
|
|
372
|
+
if (y !== offsetY.value) {
|
|
373
|
+
offsetY.value = animation
|
|
374
|
+
? withSpring(y, {
|
|
375
|
+
duration: 1500,
|
|
376
|
+
dampingRatio: 0.8
|
|
377
|
+
})
|
|
378
|
+
: y;
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
})
|
|
382
|
+
.onFinalize((e) => {
|
|
383
|
+
'worklet';
|
|
384
|
+
isMoving.value = false;
|
|
385
|
+
if (!inertia || disabled || !animation)
|
|
386
|
+
return;
|
|
387
|
+
if (direction === 'horizontal' || direction === 'all') {
|
|
388
|
+
xInertialMotion.value = true;
|
|
389
|
+
offsetX.value = withDecay({
|
|
390
|
+
velocity: e.velocityX / 10,
|
|
391
|
+
rubberBandEffect: outOfBounds,
|
|
392
|
+
clamp: draggableXRange.value
|
|
393
|
+
}, () => {
|
|
394
|
+
xInertialMotion.value = false;
|
|
395
|
+
});
|
|
396
|
+
}
|
|
397
|
+
if (direction === 'vertical' || direction === 'all') {
|
|
398
|
+
yInertialMotion.value = true;
|
|
399
|
+
offsetY.value = withDecay({
|
|
400
|
+
velocity: e.velocityY / 10,
|
|
401
|
+
rubberBandEffect: outOfBounds,
|
|
402
|
+
clamp: draggableYRange.value
|
|
403
|
+
}, () => {
|
|
404
|
+
yInertialMotion.value = false;
|
|
405
|
+
});
|
|
406
|
+
}
|
|
407
|
+
})
|
|
408
|
+
.withRef(movableGestureRef);
|
|
409
|
+
if (simultaneousHandlers && simultaneousHandlers.length) {
|
|
410
|
+
gesturePan.simultaneousWithExternalGesture(...simultaneousHandlers);
|
|
411
|
+
}
|
|
412
|
+
if (waitForHandlers && waitForHandlers.length) {
|
|
413
|
+
gesturePan.requireExternalGestureToFail(...waitForHandlers);
|
|
414
|
+
}
|
|
415
|
+
return gesturePan;
|
|
416
|
+
}, [disabled, direction, inertia, outOfBounds, gestureSwitch.current]);
|
|
417
|
+
const animatedStyles = useAnimatedStyle(() => {
|
|
418
|
+
return {
|
|
419
|
+
transform: [
|
|
420
|
+
{ translateX: offsetX.value },
|
|
421
|
+
{ translateY: offsetY.value }
|
|
422
|
+
]
|
|
423
|
+
};
|
|
424
|
+
});
|
|
425
|
+
const rewriteCatchEvent = () => {
|
|
426
|
+
const handlers = {};
|
|
427
|
+
const events = [
|
|
428
|
+
{ type: 'touchstart' },
|
|
429
|
+
{ type: 'touchmove', alias: ['vtouchmove', 'htouchmove'] },
|
|
430
|
+
{ type: 'touchend' }
|
|
431
|
+
];
|
|
432
|
+
events.forEach(({ type, alias = [] }) => {
|
|
433
|
+
const hasCatchEvent = props[`catch${type}`] ||
|
|
434
|
+
alias.some(name => props[`catch${name}`]);
|
|
435
|
+
if (hasCatchEvent)
|
|
436
|
+
handlers[`catch${type}`] = noop;
|
|
437
|
+
});
|
|
438
|
+
return handlers;
|
|
439
|
+
};
|
|
440
|
+
const layoutStyle = !hasLayoutRef.current && hasSelfPercent ? HIDDEN_STYLE : {};
|
|
441
|
+
// bind 相关 touch 事件直接由 gesture 触发,无须重复挂载
|
|
442
|
+
// catch 相关 touch 事件需要重写并通过 useInnerProps 注入阻止冒泡逻辑
|
|
443
|
+
const filterProps = omit(props, [
|
|
444
|
+
'bindtouchstart',
|
|
445
|
+
'bindtouchmove',
|
|
446
|
+
'bindvtouchmove',
|
|
447
|
+
'bindhtouchmove',
|
|
448
|
+
'bindtouchend',
|
|
449
|
+
'catchtouchstart',
|
|
450
|
+
'catchtouchmove',
|
|
451
|
+
'catchvtouchmove',
|
|
452
|
+
'catchhtouchmove',
|
|
453
|
+
'catchtouchend'
|
|
454
|
+
]);
|
|
455
|
+
const innerProps = useInnerProps(filterProps, extendObject({
|
|
456
|
+
ref: nodeRef,
|
|
457
|
+
onLayout: onLayout,
|
|
458
|
+
style: [innerStyle, animatedStyles, layoutStyle]
|
|
459
|
+
}, rewriteCatchEvent()));
|
|
460
|
+
return createElement(GestureDetector, { gesture: gesture }, createElement(Animated.View, innerProps, wrapChildren(props, {
|
|
461
|
+
hasVarDec,
|
|
462
|
+
varContext: varContextRef.current,
|
|
463
|
+
textStyle,
|
|
464
|
+
textProps
|
|
465
|
+
})));
|
|
466
|
+
});
|
|
467
|
+
_MovableView.displayName = 'MpxMovableView';
|
|
468
|
+
export default _MovableView;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { useCallback, forwardRef, createElement } from 'react';
|
|
2
|
+
import useInnerProps from './getInnerListeners';
|
|
3
|
+
import { redirectTo, navigateTo, navigateBack, reLaunch, switchTab } from '@mpxjs/api-proxy';
|
|
4
|
+
import MpxView from './mpx-view';
|
|
5
|
+
const _Navigator = forwardRef((props, ref) => {
|
|
6
|
+
const { children, 'open-type': openType, url = '', delta } = props;
|
|
7
|
+
const handleClick = useCallback(() => {
|
|
8
|
+
switch (openType) {
|
|
9
|
+
case 'navigateBack':
|
|
10
|
+
navigateBack({ delta });
|
|
11
|
+
break;
|
|
12
|
+
case 'redirect':
|
|
13
|
+
redirectTo({ url });
|
|
14
|
+
break;
|
|
15
|
+
case 'switchTab':
|
|
16
|
+
switchTab({ url });
|
|
17
|
+
break;
|
|
18
|
+
case 'reLaunch':
|
|
19
|
+
reLaunch({ url });
|
|
20
|
+
break;
|
|
21
|
+
default:
|
|
22
|
+
navigateTo({ url });
|
|
23
|
+
break;
|
|
24
|
+
}
|
|
25
|
+
}, [openType, url, delta]);
|
|
26
|
+
const innerProps = useInnerProps(props, {
|
|
27
|
+
ref,
|
|
28
|
+
bindtap: handleClick
|
|
29
|
+
});
|
|
30
|
+
return createElement(MpxView, innerProps, children);
|
|
31
|
+
});
|
|
32
|
+
_Navigator.displayName = 'MpxNavigator';
|
|
33
|
+
export default _Navigator;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { View, TouchableWithoutFeedback } from 'react-native';
|
|
2
|
+
import { DatePicker } from '@ant-design/react-native';
|
|
3
|
+
import React, { forwardRef, useState, useRef, useEffect } from 'react';
|
|
4
|
+
import useNodesRef from '../useNodesRef'; // 引入辅助函数
|
|
5
|
+
function formatTimeStr(time = '') {
|
|
6
|
+
let [year, month, day] = time.split('-');
|
|
7
|
+
year = ~~year || 2000;
|
|
8
|
+
month = ~~month || 1;
|
|
9
|
+
day = ~~day || 1;
|
|
10
|
+
return new Date(year, month - 1, day);
|
|
11
|
+
}
|
|
12
|
+
function dateToString(date, fields = 'day') {
|
|
13
|
+
const yyyy = date.getFullYear() + '';
|
|
14
|
+
const MM = ('0' + (date.getMonth() + 1)).slice(-2);
|
|
15
|
+
const dd = ('0' + date.getDate()).slice(-2);
|
|
16
|
+
let ret = yyyy;
|
|
17
|
+
if (fields === 'month' || fields === 'day') {
|
|
18
|
+
ret += `-${MM}`;
|
|
19
|
+
if (fields === 'day') {
|
|
20
|
+
ret += `-${dd}`;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return ret;
|
|
24
|
+
}
|
|
25
|
+
const _DatePicker = forwardRef((props, ref) => {
|
|
26
|
+
const { children, start = '1970-01-01', end = '2999-01-01', value, bindchange, bindcancel, disabled, fields, style } = props;
|
|
27
|
+
const [datevalue, setDateValue] = useState(value);
|
|
28
|
+
// 存储layout布局信息
|
|
29
|
+
const layoutRef = useRef({});
|
|
30
|
+
const viewRef = useRef(null);
|
|
31
|
+
const nodeRef = useRef(null);
|
|
32
|
+
useNodesRef(props, ref, nodeRef, {
|
|
33
|
+
style
|
|
34
|
+
});
|
|
35
|
+
useEffect(() => {
|
|
36
|
+
value && setDateValue(value);
|
|
37
|
+
}, [value]);
|
|
38
|
+
const onChange = (date) => {
|
|
39
|
+
const { fields = 'day' } = props;
|
|
40
|
+
const ret = dateToString(date, fields);
|
|
41
|
+
setDateValue(ret);
|
|
42
|
+
bindchange && bindchange({ detail: { value: ret } });
|
|
43
|
+
};
|
|
44
|
+
const onDismiss = () => {
|
|
45
|
+
bindcancel && bindcancel();
|
|
46
|
+
};
|
|
47
|
+
const onElementLayout = (layout) => {
|
|
48
|
+
viewRef.current?.measure((x, y, width, height, offsetLeft, offsetTop) => {
|
|
49
|
+
layoutRef.current = { x, y, width, height, offsetLeft, offsetTop };
|
|
50
|
+
props.getInnerLayout && props.getInnerLayout(layoutRef);
|
|
51
|
+
});
|
|
52
|
+
};
|
|
53
|
+
const dateProps = {
|
|
54
|
+
ref: nodeRef,
|
|
55
|
+
precision: fields,
|
|
56
|
+
value: formatTimeStr(datevalue),
|
|
57
|
+
minDate: formatTimeStr(start),
|
|
58
|
+
maxDate: formatTimeStr(end),
|
|
59
|
+
onChange,
|
|
60
|
+
onDismiss,
|
|
61
|
+
disabled
|
|
62
|
+
};
|
|
63
|
+
const touchProps = {
|
|
64
|
+
onLayout: onElementLayout,
|
|
65
|
+
ref: viewRef
|
|
66
|
+
};
|
|
67
|
+
return (<DatePicker {...dateProps}>
|
|
68
|
+
<TouchableWithoutFeedback>
|
|
69
|
+
<View {...touchProps}>{children}</View>
|
|
70
|
+
</TouchableWithoutFeedback>
|
|
71
|
+
</DatePicker>);
|
|
72
|
+
});
|
|
73
|
+
_DatePicker.displayName = 'mpx-picker-date';
|
|
74
|
+
export default _DatePicker;
|