@mpxjs/webpack-plugin 2.9.70-alpha.0 → 2.9.71
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/movable-view.js +8 -1
- package/lib/platform/template/wx/component-config/picker-view.js +1 -5
- package/lib/platform/template/wx/component-config/rich-text.js +6 -2
- package/lib/platform/template/wx/component-config/scroll-view.js +1 -5
- 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 -131
- package/lib/resolve-loader.js +1 -4
- package/lib/runtime/components/react/context.ts +8 -0
- package/lib/runtime/components/react/dist/context.js +2 -0
- package/lib/runtime/components/react/dist/getInnerListeners.js +39 -37
- package/lib/runtime/components/react/dist/mpx-button.jsx +16 -44
- 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-movable-view.jsx +93 -58
- package/lib/runtime/components/react/dist/mpx-navigator.jsx +1 -1
- package/lib/runtime/components/react/dist/mpx-picker-view-column-item.jsx +10 -14
- package/lib/runtime/components/react/dist/mpx-picker-view-column.jsx +94 -81
- package/lib/runtime/components/react/dist/mpx-picker-view.jsx +19 -16
- package/lib/runtime/components/react/dist/mpx-rich-text/index.jsx +10 -11
- package/lib/runtime/components/react/dist/mpx-scroll-view.jsx +11 -4
- package/lib/runtime/components/react/dist/mpx-swiper-item.jsx +31 -8
- package/lib/runtime/components/react/dist/mpx-swiper.jsx +435 -371
- package/lib/runtime/components/react/dist/mpx-view.jsx +18 -53
- package/lib/runtime/components/react/dist/pickerFaces.js +3 -8
- package/lib/runtime/components/react/dist/pickerVIewContext.js +5 -0
- package/lib/runtime/components/react/dist/{pickerViewOverlay.jsx → pickerViewIndicator.jsx} +6 -6
- package/lib/runtime/components/react/dist/pickerViewMask.jsx +2 -2
- package/lib/runtime/components/react/dist/useAnimationHooks.js +27 -10
- package/lib/runtime/components/react/dist/utils.jsx +162 -70
- package/lib/runtime/components/react/event.config.ts +25 -26
- package/lib/runtime/components/react/getInnerListeners.ts +236 -182
- package/lib/runtime/components/react/mpx-button.tsx +27 -69
- 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 +133 -92
- package/lib/runtime/components/react/mpx-navigator.tsx +3 -9
- package/lib/runtime/components/react/mpx-picker-view-column-item.tsx +76 -0
- package/lib/runtime/components/react/mpx-picker-view-column.tsx +206 -183
- package/lib/runtime/components/react/mpx-picker-view.tsx +49 -48
- 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 +115 -0
- package/lib/runtime/components/react/mpx-root-portal.tsx +3 -5
- package/lib/runtime/components/react/mpx-scroll-view.tsx +53 -43
- package/lib/runtime/components/react/mpx-swiper-item.tsx +45 -11
- package/lib/runtime/components/react/mpx-swiper.tsx +742 -0
- 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 +28 -77
- package/lib/runtime/components/react/mpx-web-view.tsx +94 -59
- package/lib/runtime/components/react/pickerFaces.ts +10 -7
- package/lib/runtime/components/react/pickerVIewContext.ts +27 -0
- package/lib/runtime/components/react/pickerViewIndicator.tsx +34 -0
- package/lib/runtime/components/react/pickerViewMask.tsx +30 -0
- package/lib/runtime/components/react/types/{getInnerListeners.ts → getInnerListeners.d.ts} +4 -5
- package/lib/runtime/components/react/types/global.d.ts +12 -1
- package/lib/runtime/components/react/useAnimationHooks.ts +60 -15
- package/lib/runtime/components/react/utils.tsx +175 -71
- package/lib/runtime/components/web/mpx-checkbox.vue +1 -1
- package/lib/runtime/components/web/mpx-picker-view-column.vue +9 -4
- 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 +91 -39
- package/lib/utils/env.js +1 -6
- package/lib/utils/pre-process-json.js +9 -5
- package/lib/wxss/loader.js +15 -2
- package/package.json +4 -7
- package/lib/dependencies/AddEntryDependency.js +0 -24
- package/lib/runtime/components/react/dist/types/common.js +0 -1
- package/lib/runtime/components/react/dist/types/getInnerListeners.js +0 -1
- package/lib/runtime/components/react/mpx-swiper/carouse.tsx +0 -527
- package/lib/runtime/components/react/mpx-swiper/index.tsx +0 -80
- package/lib/runtime/components/react/mpx-swiper/type.ts +0 -87
- package/lib/runtime/components/react/pickerOverlay.tsx +0 -32
- 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
- /package/lib/runtime/components/react/types/{common.ts → common.d.ts} +0 -0
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
* ✘ scale-min
|
|
12
12
|
* ✘ scale-max
|
|
13
13
|
* ✘ scale-value
|
|
14
|
-
*
|
|
14
|
+
* ✔ animation
|
|
15
15
|
* ✔ bindchange
|
|
16
16
|
* ✘ bindscale
|
|
17
17
|
* ✔ htouchmove
|
|
@@ -19,12 +19,13 @@
|
|
|
19
19
|
*/
|
|
20
20
|
import { useEffect, forwardRef, useContext, useCallback, useRef, useMemo, createElement } from 'react';
|
|
21
21
|
import { StyleSheet } from 'react-native';
|
|
22
|
-
import { getCustomEvent } from './getInnerListeners';
|
|
22
|
+
import useInnerProps, { getCustomEvent } from './getInnerListeners';
|
|
23
23
|
import useNodesRef from './useNodesRef';
|
|
24
24
|
import { MovableAreaContext } from './context';
|
|
25
|
-
import { useTransformStyle, splitProps, splitStyle, HIDDEN_STYLE, wrapChildren, flatGesture, extendObject } from './utils';
|
|
25
|
+
import { useTransformStyle, splitProps, splitStyle, HIDDEN_STYLE, wrapChildren, flatGesture, extendObject, omit } from './utils';
|
|
26
26
|
import { GestureDetector, Gesture } from 'react-native-gesture-handler';
|
|
27
27
|
import Animated, { useSharedValue, useAnimatedStyle, withDecay, runOnJS, runOnUI, useAnimatedReaction, withSpring } from 'react-native-reanimated';
|
|
28
|
+
import { collectDataset, noop } from '@mpxjs/utils';
|
|
28
29
|
const styles = StyleSheet.create({
|
|
29
30
|
container: {
|
|
30
31
|
position: 'absolute',
|
|
@@ -233,8 +234,7 @@ const _MovableView = forwardRef((movableViewProps, ref) => {
|
|
|
233
234
|
});
|
|
234
235
|
props.onLayout && props.onLayout(e);
|
|
235
236
|
};
|
|
236
|
-
const extendEvent = useCallback((e) => {
|
|
237
|
-
'worklet';
|
|
237
|
+
const extendEvent = useCallback((e, obj) => {
|
|
238
238
|
const touchArr = [e.changedTouches, e.allTouches];
|
|
239
239
|
touchArr.forEach(touches => {
|
|
240
240
|
touches && touches.forEach((item) => {
|
|
@@ -242,45 +242,65 @@ const _MovableView = forwardRef((movableViewProps, ref) => {
|
|
|
242
242
|
item.pageY = item.absoluteY;
|
|
243
243
|
});
|
|
244
244
|
});
|
|
245
|
-
e
|
|
245
|
+
Object.assign(e, {
|
|
246
|
+
touches: e.allTouches,
|
|
247
|
+
detail: {
|
|
248
|
+
x: e.changedTouches[0].absoluteX,
|
|
249
|
+
y: e.changedTouches[0].absoluteY
|
|
250
|
+
},
|
|
251
|
+
currentTarget: {
|
|
252
|
+
id: props.id || '',
|
|
253
|
+
dataset: collectDataset(props),
|
|
254
|
+
offsetLeft: 0,
|
|
255
|
+
offsetTop: 0
|
|
256
|
+
}
|
|
257
|
+
}, obj);
|
|
246
258
|
}, []);
|
|
259
|
+
const triggerStartOnJS = ({ e }) => {
|
|
260
|
+
extendEvent(e);
|
|
261
|
+
bindtouchstart && bindtouchstart(e);
|
|
262
|
+
catchtouchstart && catchtouchstart(e);
|
|
263
|
+
};
|
|
264
|
+
const triggerMoveOnJS = ({ e, hasTouchmove, hasCatchTouchmove, touchEvent }) => {
|
|
265
|
+
extendEvent(e);
|
|
266
|
+
if (hasTouchmove) {
|
|
267
|
+
if (touchEvent === 'htouchmove') {
|
|
268
|
+
bindhtouchmove && bindhtouchmove(e);
|
|
269
|
+
}
|
|
270
|
+
else if (touchEvent === 'vtouchmove') {
|
|
271
|
+
bindvtouchmove && bindvtouchmove(e);
|
|
272
|
+
}
|
|
273
|
+
bindtouchmove && bindtouchmove(e);
|
|
274
|
+
}
|
|
275
|
+
if (hasCatchTouchmove) {
|
|
276
|
+
if (touchEvent === 'htouchmove') {
|
|
277
|
+
catchhtouchmove && catchhtouchmove(e);
|
|
278
|
+
}
|
|
279
|
+
else if (touchEvent === 'vtouchmove') {
|
|
280
|
+
catchvtouchmove && catchvtouchmove(e);
|
|
281
|
+
}
|
|
282
|
+
catchtouchmove && catchtouchmove(e);
|
|
283
|
+
}
|
|
284
|
+
};
|
|
285
|
+
const triggerEndOnJS = ({ e }) => {
|
|
286
|
+
extendEvent(e);
|
|
287
|
+
bindtouchend && bindtouchend(e);
|
|
288
|
+
catchtouchend && catchtouchend(e);
|
|
289
|
+
};
|
|
247
290
|
const gesture = useMemo(() => {
|
|
248
|
-
const handleTriggerStart = (e) => {
|
|
249
|
-
'worklet';
|
|
250
|
-
extendEvent(e);
|
|
251
|
-
bindtouchstart && runOnJS(bindtouchstart)(e);
|
|
252
|
-
catchtouchstart && runOnJS(catchtouchstart)(e);
|
|
253
|
-
};
|
|
254
291
|
const handleTriggerMove = (e) => {
|
|
255
292
|
'worklet';
|
|
256
|
-
extendEvent(e);
|
|
257
293
|
const hasTouchmove = !!bindhtouchmove || !!bindvtouchmove || !!bindtouchmove;
|
|
258
294
|
const hasCatchTouchmove = !!catchhtouchmove || !!catchvtouchmove || !!catchtouchmove;
|
|
259
|
-
if (hasTouchmove) {
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
}
|
|
266
|
-
bindtouchmove && runOnJS(bindtouchmove)(e);
|
|
267
|
-
}
|
|
268
|
-
if (hasCatchTouchmove) {
|
|
269
|
-
if (touchEvent.value === 'htouchmove') {
|
|
270
|
-
catchhtouchmove && runOnJS(catchhtouchmove)(e);
|
|
271
|
-
}
|
|
272
|
-
else if (touchEvent.value === 'vtouchmove') {
|
|
273
|
-
catchvtouchmove && runOnJS(catchvtouchmove)(e);
|
|
274
|
-
}
|
|
275
|
-
catchtouchmove && runOnJS(catchtouchmove)(e);
|
|
295
|
+
if (hasTouchmove || hasCatchTouchmove) {
|
|
296
|
+
runOnJS(triggerMoveOnJS)({
|
|
297
|
+
e,
|
|
298
|
+
touchEvent: touchEvent.value,
|
|
299
|
+
hasTouchmove,
|
|
300
|
+
hasCatchTouchmove
|
|
301
|
+
});
|
|
276
302
|
}
|
|
277
303
|
};
|
|
278
|
-
const handleTriggerEnd = (e) => {
|
|
279
|
-
'worklet';
|
|
280
|
-
extendEvent(e);
|
|
281
|
-
bindtouchend && runOnJS(bindtouchend)(e);
|
|
282
|
-
catchtouchend && runOnJS(catchtouchend)(e);
|
|
283
|
-
};
|
|
284
304
|
const gesturePan = Gesture.Pan()
|
|
285
305
|
.onTouchesDown((e) => {
|
|
286
306
|
'worklet';
|
|
@@ -290,12 +310,14 @@ const _MovableView = forwardRef((movableViewProps, ref) => {
|
|
|
290
310
|
x: changedTouches.x,
|
|
291
311
|
y: changedTouches.y
|
|
292
312
|
};
|
|
293
|
-
|
|
313
|
+
if (bindtouchstart || catchtouchstart) {
|
|
314
|
+
runOnJS(triggerStartOnJS)({ e });
|
|
315
|
+
}
|
|
294
316
|
})
|
|
295
317
|
.onTouchesMove((e) => {
|
|
296
318
|
'worklet';
|
|
297
|
-
isMoving.value = true;
|
|
298
319
|
const changedTouches = e.changedTouches[0] || { x: 0, y: 0 };
|
|
320
|
+
isMoving.value = true;
|
|
299
321
|
if (isFirstTouch.value) {
|
|
300
322
|
touchEvent.value = Math.abs(changedTouches.x - startPosition.value.x) > Math.abs(changedTouches.y - startPosition.value.y) ? 'htouchmove' : 'vtouchmove';
|
|
301
323
|
isFirstTouch.value = false;
|
|
@@ -330,7 +352,9 @@ const _MovableView = forwardRef((movableViewProps, ref) => {
|
|
|
330
352
|
'worklet';
|
|
331
353
|
isFirstTouch.value = true;
|
|
332
354
|
isMoving.value = false;
|
|
333
|
-
|
|
355
|
+
if (bindtouchend || catchtouchend) {
|
|
356
|
+
runOnJS(triggerEndOnJS)({ e });
|
|
357
|
+
}
|
|
334
358
|
if (disabled)
|
|
335
359
|
return;
|
|
336
360
|
if (!inertia) {
|
|
@@ -355,9 +379,9 @@ const _MovableView = forwardRef((movableViewProps, ref) => {
|
|
|
355
379
|
})
|
|
356
380
|
.onFinalize((e) => {
|
|
357
381
|
'worklet';
|
|
382
|
+
isMoving.value = false;
|
|
358
383
|
if (!inertia || disabled || !animation)
|
|
359
384
|
return;
|
|
360
|
-
isMoving.value = false;
|
|
361
385
|
if (direction === 'horizontal' || direction === 'all') {
|
|
362
386
|
xInertialMotion.value = true;
|
|
363
387
|
offsetX.value = withDecay({
|
|
@@ -396,31 +420,42 @@ const _MovableView = forwardRef((movableViewProps, ref) => {
|
|
|
396
420
|
]
|
|
397
421
|
};
|
|
398
422
|
});
|
|
399
|
-
const
|
|
400
|
-
const
|
|
401
|
-
const
|
|
402
|
-
{
|
|
403
|
-
{
|
|
404
|
-
{
|
|
423
|
+
const rewriteCatchEvent = () => {
|
|
424
|
+
const handlers = {};
|
|
425
|
+
const events = [
|
|
426
|
+
{ type: 'touchstart' },
|
|
427
|
+
{ type: 'touchmove', alias: ['vtouchmove', 'htouchmove'] },
|
|
428
|
+
{ type: 'touchend' }
|
|
405
429
|
];
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
};
|
|
412
|
-
}
|
|
413
|
-
});
|
|
430
|
+
events.forEach(({ type, alias = [] }) => {
|
|
431
|
+
const hasCatchEvent = props[`catch${type}`] ||
|
|
432
|
+
alias.some(name => props[`catch${name}`]);
|
|
433
|
+
if (hasCatchEvent)
|
|
434
|
+
handlers[`catch${type}`] = noop;
|
|
414
435
|
});
|
|
415
|
-
return
|
|
436
|
+
return handlers;
|
|
416
437
|
};
|
|
417
|
-
const catchEventHandlers = injectCatchEvent(props);
|
|
418
438
|
const layoutStyle = !hasLayoutRef.current && hasSelfPercent ? HIDDEN_STYLE : {};
|
|
419
|
-
|
|
439
|
+
// bind 相关 touch 事件直接由 gesture 触发,无须重复挂载
|
|
440
|
+
// catch 相关 touch 事件需要重写并通过 useInnerProps 注入阻止冒泡逻辑
|
|
441
|
+
const filterProps = omit(props, [
|
|
442
|
+
'bindtouchstart',
|
|
443
|
+
'bindtouchmove',
|
|
444
|
+
'bindvtouchmove',
|
|
445
|
+
'bindhtouchmove',
|
|
446
|
+
'bindtouchend',
|
|
447
|
+
'catchtouchstart',
|
|
448
|
+
'catchtouchmove',
|
|
449
|
+
'catchvtouchmove',
|
|
450
|
+
'catchhtouchmove',
|
|
451
|
+
'catchtouchend'
|
|
452
|
+
]);
|
|
453
|
+
const innerProps = useInnerProps(filterProps, extendObject({
|
|
420
454
|
ref: nodeRef,
|
|
421
455
|
onLayout: onLayout,
|
|
422
456
|
style: [innerStyle, animatedStyles, layoutStyle]
|
|
423
|
-
},
|
|
457
|
+
}, rewriteCatchEvent()));
|
|
458
|
+
return createElement(GestureDetector, { gesture: gesture }, createElement(Animated.View, innerProps, wrapChildren(props, {
|
|
424
459
|
hasVarDec,
|
|
425
460
|
varContext: varContextRef.current,
|
|
426
461
|
textStyle,
|
|
@@ -3,7 +3,7 @@ import useInnerProps from './getInnerListeners';
|
|
|
3
3
|
import { redirectTo, navigateTo, navigateBack, reLaunch, switchTab } from '@mpxjs/api-proxy';
|
|
4
4
|
import MpxView from './mpx-view';
|
|
5
5
|
const _Navigator = forwardRef((props, ref) => {
|
|
6
|
-
const { children, 'open-type': openType, url, delta } = props;
|
|
6
|
+
const { children, 'open-type': openType, url = '', delta } = props;
|
|
7
7
|
const handleClick = useCallback(() => {
|
|
8
8
|
switch (openType) {
|
|
9
9
|
case 'navigateBack':
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import React, { useEffect } from 'react';
|
|
2
2
|
import Reanimated, { Extrapolation, interpolate, useAnimatedStyle, useSharedValue } from 'react-native-reanimated';
|
|
3
|
-
import {
|
|
3
|
+
import { extendObject } from './utils';
|
|
4
4
|
import { createFaces } from './pickerFaces';
|
|
5
|
-
import { usePickerViewColumnAnimationContext } from './pickerVIewContext';
|
|
6
|
-
const
|
|
5
|
+
import { usePickerViewColumnAnimationContext, usePickerViewStyleContext } from './pickerVIewContext';
|
|
6
|
+
const PickerViewColumnItem = ({ item, index, itemHeight, itemWidth = '100%', textStyle, textProps, visibleCount, onItemLayout }) => {
|
|
7
|
+
const textStyleFromAncestor = usePickerViewStyleContext();
|
|
7
8
|
const offsetYShared = usePickerViewColumnAnimationContext();
|
|
8
9
|
const facesShared = useSharedValue(createFaces(itemHeight, visibleCount));
|
|
9
10
|
useEffect(() => {
|
|
@@ -14,8 +15,8 @@ const _PickerViewColumnItem = ({ item, index, itemHeight, itemWidth, textStyleFr
|
|
|
14
15
|
return {
|
|
15
16
|
opacity: interpolate(offsetYShared.value, inputRange, facesShared.value.map((x) => x.opacity), Extrapolation.CLAMP),
|
|
16
17
|
transform: [
|
|
17
|
-
{ rotateX: interpolate(offsetYShared.value, inputRange, facesShared.value.map((x) => x.deg), Extrapolation.CLAMP) + 'deg' },
|
|
18
18
|
{ translateY: interpolate(offsetYShared.value, inputRange, facesShared.value.map((x) => x.offsetY), Extrapolation.EXTEND) },
|
|
19
|
+
{ rotateX: interpolate(offsetYShared.value, inputRange, facesShared.value.map((x) => x.deg), Extrapolation.CLAMP) + 'deg' },
|
|
19
20
|
{ scale: interpolate(offsetYShared.value, inputRange, facesShared.value.map((x) => x.scale), Extrapolation.EXTEND) }
|
|
20
21
|
]
|
|
21
22
|
};
|
|
@@ -23,17 +24,12 @@ const _PickerViewColumnItem = ({ item, index, itemHeight, itemWidth, textStyleFr
|
|
|
23
24
|
const strKey = `picker-column-item-${index}`;
|
|
24
25
|
const restProps = index === 0 ? { onLayout: onItemLayout } : {};
|
|
25
26
|
const itemProps = extendObject({
|
|
26
|
-
style: extendObject({ height: itemHeight, width: '100%' },
|
|
27
|
-
}, restProps);
|
|
27
|
+
style: extendObject({ height: itemHeight, width: '100%' }, textStyleFromAncestor, textStyle, item.props.style)
|
|
28
|
+
}, textProps, restProps);
|
|
28
29
|
const realItem = React.cloneElement(item, itemProps);
|
|
29
30
|
return (<Reanimated.View key={strKey} style={[{ height: itemHeight, width: itemWidth }, animatedStyles]}>
|
|
30
|
-
{
|
|
31
|
-
hasVarDec,
|
|
32
|
-
varContext,
|
|
33
|
-
textStyle,
|
|
34
|
-
textProps
|
|
35
|
-
})}
|
|
31
|
+
{realItem}
|
|
36
32
|
</Reanimated.View>);
|
|
37
33
|
};
|
|
38
|
-
|
|
39
|
-
export default
|
|
34
|
+
PickerViewColumnItem.displayName = 'MpxPickerViewColumnItem';
|
|
35
|
+
export default PickerViewColumnItem;
|
|
@@ -1,34 +1,31 @@
|
|
|
1
1
|
import React, { forwardRef, useRef, useState, useMemo, useEffect, useCallback } from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import { StyleSheet, View } from 'react-native';
|
|
3
3
|
import Reanimated, { useAnimatedRef, useScrollViewOffset } from 'react-native-reanimated';
|
|
4
|
-
import {
|
|
5
|
-
import { useTransformStyle, splitStyle, splitProps, useLayout, usePrevious } from './utils';
|
|
4
|
+
import { useTransformStyle, splitStyle, splitProps, useLayout, usePrevious, isAndroid, isIOS } from './utils';
|
|
6
5
|
import useNodesRef from './useNodesRef';
|
|
7
|
-
import
|
|
6
|
+
import PickerIndicator from './pickerViewIndicator';
|
|
8
7
|
import PickerMask from './pickerViewMask';
|
|
9
8
|
import MpxPickerVIewColumnItem from './mpx-picker-view-column-item';
|
|
10
9
|
import { PickerViewColumnAnimationContext } from './pickerVIewContext';
|
|
11
10
|
const visibleCount = 5;
|
|
12
11
|
const _PickerViewColumn = forwardRef((props, ref) => {
|
|
13
|
-
const { columnData, columnIndex,
|
|
14
|
-
const { normalStyle,
|
|
15
|
-
const { textStyle: textStyleFromParent = {} } = splitStyle(columnStyle);
|
|
12
|
+
const { columnData, columnIndex, initialIndex, onSelectChange, style, wrapperStyle, pickerMaskStyle, pickerIndicatorStyle, 'enable-var': enableVar, 'external-var-context': externalVarContext } = props;
|
|
13
|
+
const { normalStyle, hasSelfPercent, setWidth, setHeight } = useTransformStyle(style, { enableVar, externalVarContext });
|
|
16
14
|
const { textStyle = {} } = splitStyle(normalStyle);
|
|
17
|
-
const { textProps } = splitProps(props);
|
|
15
|
+
const { textProps = {} } = splitProps(props);
|
|
18
16
|
const scrollViewRef = useAnimatedRef();
|
|
19
17
|
const offsetYShared = useScrollViewOffset(scrollViewRef);
|
|
20
18
|
useNodesRef(props, ref, scrollViewRef, {
|
|
21
19
|
style: normalStyle
|
|
22
20
|
});
|
|
23
21
|
const { height: pickerH, itemHeight } = wrapperStyle;
|
|
24
|
-
const [scrollViewWidth, setScrollViewWidth] = useState('100%');
|
|
25
|
-
const [itemRawW, setItemRawW] = useState('100%');
|
|
26
22
|
const [itemRawH, setItemRawH] = useState(itemHeight);
|
|
27
23
|
const maxIndex = useMemo(() => columnData.length - 1, [columnData]);
|
|
28
|
-
const maxScrollViewWidth = useRef(-1);
|
|
29
24
|
const prevScrollingInfo = useRef({ index: initialIndex, y: 0 });
|
|
30
25
|
const touching = useRef(false);
|
|
31
26
|
const scrolling = useRef(false);
|
|
27
|
+
const timerResetPosition = useRef(null);
|
|
28
|
+
const timerScrollTo = useRef(null);
|
|
32
29
|
const activeIndex = useRef(initialIndex);
|
|
33
30
|
const prevIndex = usePrevious(initialIndex);
|
|
34
31
|
const prevMaxIndex = usePrevious(maxIndex);
|
|
@@ -39,13 +36,8 @@ const _PickerViewColumn = forwardRef((props, ref) => {
|
|
|
39
36
|
setHeight,
|
|
40
37
|
nodeRef: scrollViewRef
|
|
41
38
|
});
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
// x: 0,
|
|
45
|
-
// y: itemRawH * initialIndex
|
|
46
|
-
// }), [itemRawH])
|
|
47
|
-
const snapToOffsets = useMemo(() => columnData.map((_, i) => i * itemRawH), [columnData, itemRawH]);
|
|
48
|
-
const paddingHeight = useMemo(() => Math.round((pickerH - itemRawH) / 2), [pickerH, itemRawH]);
|
|
39
|
+
const paddingHeight = useMemo(() => Math.round((pickerH - itemHeight) / 2), [pickerH, itemHeight]);
|
|
40
|
+
const snapToOffsets = useMemo(() => Array.from({ length: maxIndex + 1 }, (_, i) => i * itemRawH), [maxIndex, itemRawH]);
|
|
49
41
|
const contentContainerStyle = useMemo(() => {
|
|
50
42
|
return [{ paddingVertical: paddingHeight }];
|
|
51
43
|
}, [paddingHeight]);
|
|
@@ -53,6 +45,24 @@ const _PickerViewColumn = forwardRef((props, ref) => {
|
|
|
53
45
|
const calc = Math.round(y / itemRawH);
|
|
54
46
|
return Math.max(0, Math.min(calc, maxIndex));
|
|
55
47
|
}, [itemRawH, maxIndex]);
|
|
48
|
+
const clearTimerResetPosition = useCallback(() => {
|
|
49
|
+
if (timerResetPosition.current) {
|
|
50
|
+
clearTimeout(timerResetPosition.current);
|
|
51
|
+
timerResetPosition.current = null;
|
|
52
|
+
}
|
|
53
|
+
}, []);
|
|
54
|
+
const clearTimerScrollTo = useCallback(() => {
|
|
55
|
+
if (timerScrollTo.current) {
|
|
56
|
+
clearTimeout(timerScrollTo.current);
|
|
57
|
+
timerScrollTo.current = null;
|
|
58
|
+
}
|
|
59
|
+
}, []);
|
|
60
|
+
useEffect(() => {
|
|
61
|
+
return () => {
|
|
62
|
+
clearTimerResetPosition();
|
|
63
|
+
clearTimerScrollTo();
|
|
64
|
+
};
|
|
65
|
+
}, []);
|
|
56
66
|
useEffect(() => {
|
|
57
67
|
if (!scrollViewRef.current ||
|
|
58
68
|
!itemRawH ||
|
|
@@ -64,80 +74,82 @@ const _PickerViewColumn = forwardRef((props, ref) => {
|
|
|
64
74
|
maxIndex !== prevMaxIndex) {
|
|
65
75
|
return;
|
|
66
76
|
}
|
|
67
|
-
|
|
68
|
-
setTimeout(() => {
|
|
77
|
+
clearTimerScrollTo();
|
|
78
|
+
timerScrollTo.current = setTimeout(() => {
|
|
69
79
|
scrollViewRef.current?.scrollTo({
|
|
70
80
|
x: 0,
|
|
71
|
-
y:
|
|
81
|
+
y: initialIndex * itemRawH,
|
|
72
82
|
animated: false
|
|
73
83
|
});
|
|
74
|
-
}, 0);
|
|
84
|
+
}, isAndroid ? 200 : 0);
|
|
75
85
|
activeIndex.current = initialIndex;
|
|
76
|
-
}, [itemRawH, initialIndex]);
|
|
77
|
-
const onContentSizeChange = (_w, h) => {
|
|
78
|
-
const y =
|
|
79
|
-
// console.log('[mpx-picker-view-column], onContentSizeChange --->', 'columnIndex=', columnIndex, '_w=', _w, 'h=', h, 'y=', y)
|
|
86
|
+
}, [itemRawH, maxIndex, initialIndex]);
|
|
87
|
+
const onContentSizeChange = useCallback((_w, h) => {
|
|
88
|
+
const y = initialIndex * itemRawH;
|
|
80
89
|
if (y <= h) {
|
|
81
|
-
|
|
90
|
+
clearTimerScrollTo();
|
|
91
|
+
timerScrollTo.current = setTimeout(() => {
|
|
82
92
|
scrollViewRef.current?.scrollTo({ x: 0, y, animated: false });
|
|
83
93
|
}, 0);
|
|
84
94
|
}
|
|
85
|
-
};
|
|
86
|
-
const
|
|
87
|
-
const {
|
|
88
|
-
const
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
const maxW = maxScrollViewWidth.current;
|
|
92
|
-
if (maxW !== -1 && widthInt > maxW) {
|
|
93
|
-
return;
|
|
94
|
-
}
|
|
95
|
-
if (maxW === -1) {
|
|
96
|
-
maxScrollViewWidth.current = Math.ceil(widthInt * 1.5);
|
|
97
|
-
}
|
|
98
|
-
setScrollViewWidth(widthInt);
|
|
95
|
+
}, [itemRawH, initialIndex]);
|
|
96
|
+
const onItemLayout = useCallback((e) => {
|
|
97
|
+
const { height: rawH } = e.nativeEvent.layout;
|
|
98
|
+
const roundedH = Math.round(rawH);
|
|
99
|
+
if (roundedH && roundedH !== itemRawH) {
|
|
100
|
+
setItemRawH(roundedH);
|
|
99
101
|
}
|
|
100
|
-
|
|
101
|
-
|
|
102
|
+
}, [itemRawH]);
|
|
103
|
+
const resetScrollPosition = useCallback((y) => {
|
|
104
|
+
if (touching.current || scrolling.current) {
|
|
105
|
+
return;
|
|
102
106
|
}
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
107
|
+
scrolling.current = true;
|
|
108
|
+
const targetIndex = getIndex(y);
|
|
109
|
+
scrollViewRef.current?.scrollTo({ x: 0, y: targetIndex * itemRawH, animated: false });
|
|
110
|
+
}, [itemRawH, getIndex]);
|
|
111
|
+
const onMomentumScrollBegin = useCallback(() => {
|
|
112
|
+
isIOS && clearTimerResetPosition();
|
|
113
|
+
scrolling.current = true;
|
|
114
|
+
}, []);
|
|
115
|
+
const onMomentumScrollEnd = useCallback((e) => {
|
|
116
|
+
scrolling.current = false;
|
|
117
|
+
const { y: scrollY } = e.nativeEvent.contentOffset;
|
|
118
|
+
if (isIOS && scrollY % itemRawH !== 0) {
|
|
119
|
+
return resetScrollPosition(scrollY);
|
|
108
120
|
}
|
|
109
|
-
|
|
110
|
-
|
|
121
|
+
const calcIndex = getIndex(scrollY);
|
|
122
|
+
if (calcIndex !== activeIndex.current) {
|
|
123
|
+
activeIndex.current = calcIndex;
|
|
124
|
+
onSelectChange(calcIndex);
|
|
125
|
+
}
|
|
126
|
+
}, [itemRawH, getIndex, onSelectChange, resetScrollPosition]);
|
|
127
|
+
const onScrollBeginDrag = useCallback(() => {
|
|
128
|
+
isIOS && clearTimerResetPosition();
|
|
111
129
|
touching.current = true;
|
|
112
130
|
prevScrollingInfo.current = {
|
|
113
131
|
index: activeIndex.current,
|
|
114
132
|
y: activeIndex.current * itemRawH
|
|
115
133
|
};
|
|
116
|
-
};
|
|
117
|
-
const
|
|
134
|
+
}, [itemRawH]);
|
|
135
|
+
const onScrollEndDrag = useCallback((e) => {
|
|
118
136
|
touching.current = false;
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
return;
|
|
130
|
-
}
|
|
131
|
-
const { y: scrollY } = e.nativeEvent.contentOffset;
|
|
132
|
-
let calcIndex = Math.round(scrollY / itemRawH);
|
|
133
|
-
activeIndex.current = calcIndex;
|
|
134
|
-
if (calcIndex !== initialIndex) {
|
|
135
|
-
calcIndex = Math.max(0, Math.min(calcIndex, maxIndex)) || 0;
|
|
136
|
-
onSelectChange(calcIndex);
|
|
137
|
+
if (isIOS) {
|
|
138
|
+
const { y } = e.nativeEvent.contentOffset;
|
|
139
|
+
if (y % itemRawH === 0) {
|
|
140
|
+
onMomentumScrollEnd({ nativeEvent: { contentOffset: { y } } });
|
|
141
|
+
}
|
|
142
|
+
else if (y > 0 && y < snapToOffsets[maxIndex]) {
|
|
143
|
+
timerResetPosition.current = setTimeout(() => {
|
|
144
|
+
resetScrollPosition(y);
|
|
145
|
+
}, 10);
|
|
146
|
+
}
|
|
137
147
|
}
|
|
138
|
-
};
|
|
139
|
-
const onScroll = (e) => {
|
|
140
|
-
|
|
148
|
+
}, [itemRawH, maxIndex, snapToOffsets, onMomentumScrollEnd, resetScrollPosition]);
|
|
149
|
+
const onScroll = useCallback((e) => {
|
|
150
|
+
// 全局注册的振动触感 hook
|
|
151
|
+
const pickerVibrate = global.__mpx?.config?.rnConfig?.pickerVibrate;
|
|
152
|
+
if (typeof pickerVibrate !== 'function') {
|
|
141
153
|
return;
|
|
142
154
|
}
|
|
143
155
|
const { y } = e.nativeEvent.contentOffset;
|
|
@@ -150,28 +162,29 @@ const _PickerViewColumn = forwardRef((props, ref) => {
|
|
|
150
162
|
index: currentId,
|
|
151
163
|
y: currentId * itemRawH
|
|
152
164
|
};
|
|
153
|
-
vibrateShort({ type: 'selection' })
|
|
165
|
+
// vibrateShort({ type: 'selection' })
|
|
166
|
+
pickerVibrate();
|
|
154
167
|
}
|
|
155
168
|
}
|
|
156
169
|
}
|
|
157
|
-
};
|
|
170
|
+
}, [itemRawH, getIndex]);
|
|
158
171
|
const renderInnerchild = () => columnData.map((item, index) => {
|
|
159
|
-
return (<MpxPickerVIewColumnItem key={index} item={item} index={index} itemHeight={itemHeight}
|
|
172
|
+
return (<MpxPickerVIewColumnItem key={index} item={item} index={index} itemHeight={itemHeight} textStyle={textStyle} textProps={textProps} visibleCount={visibleCount} onItemLayout={onItemLayout}/>);
|
|
160
173
|
});
|
|
161
174
|
const renderScollView = () => {
|
|
162
175
|
return (<PickerViewColumnAnimationContext.Provider value={offsetYShared}>
|
|
163
|
-
<Reanimated.ScrollView ref={scrollViewRef} bounces={true} horizontal={false} nestedScrollEnabled={true} removeClippedSubviews={false} showsVerticalScrollIndicator={false} showsHorizontalScrollIndicator={false} scrollEventThrottle={16} {...layoutProps} style={[{ width:
|
|
176
|
+
<Reanimated.ScrollView ref={scrollViewRef} bounces={true} horizontal={false} nestedScrollEnabled={true} removeClippedSubviews={false} showsVerticalScrollIndicator={false} showsHorizontalScrollIndicator={false} scrollEventThrottle={16} {...layoutProps} style={[{ width: '100%' }]} decelerationRate="fast" snapToOffsets={snapToOffsets} onScroll={onScroll} onScrollBeginDrag={onScrollBeginDrag} onScrollEndDrag={onScrollEndDrag} onMomentumScrollBegin={onMomentumScrollBegin} onMomentumScrollEnd={onMomentumScrollEnd} onContentSizeChange={onContentSizeChange} contentContainerStyle={contentContainerStyle}>
|
|
164
177
|
{renderInnerchild()}
|
|
165
178
|
</Reanimated.ScrollView>
|
|
166
179
|
</PickerViewColumnAnimationContext.Provider>);
|
|
167
180
|
};
|
|
168
|
-
const
|
|
181
|
+
const renderIndicator = () => (<PickerIndicator itemHeight={itemHeight} indicatorItemStyle={pickerIndicatorStyle}/>);
|
|
169
182
|
const renderMask = () => (<PickerMask itemHeight={itemHeight} maskContainerStyle={pickerMaskStyle}/>);
|
|
170
|
-
return (<
|
|
183
|
+
return (<View style={[styles.wrapper, normalStyle]}>
|
|
171
184
|
{renderScollView()}
|
|
172
185
|
{renderMask()}
|
|
173
|
-
{
|
|
174
|
-
</
|
|
186
|
+
{renderIndicator()}
|
|
187
|
+
</View>);
|
|
175
188
|
});
|
|
176
189
|
const styles = StyleSheet.create({
|
|
177
190
|
wrapper: { display: 'flex', flex: 1 }
|
|
@@ -2,7 +2,8 @@ import { View } from 'react-native';
|
|
|
2
2
|
import React, { forwardRef, useRef } from 'react';
|
|
3
3
|
import useInnerProps, { getCustomEvent } from './getInnerListeners';
|
|
4
4
|
import useNodesRef from './useNodesRef';
|
|
5
|
-
import { useLayout, splitProps, splitStyle, wrapChildren,
|
|
5
|
+
import { useLayout, splitProps, splitStyle, wrapChildren, useTransformStyle, extendObject } from './utils';
|
|
6
|
+
import { PickerViewStyleContext } from './pickerVIewContext';
|
|
6
7
|
const styles = {
|
|
7
8
|
wrapper: {
|
|
8
9
|
display: 'flex',
|
|
@@ -15,16 +16,13 @@ const styles = {
|
|
|
15
16
|
};
|
|
16
17
|
const DefaultPickerItemH = 36;
|
|
17
18
|
const _PickerView = forwardRef((props, ref) => {
|
|
18
|
-
const { children, value = [], bindchange, style, 'enable-var': enableVar, 'external-var-context': externalVarContext } = props;
|
|
19
|
-
const
|
|
20
|
-
const pickerMaskStyle = parseInlineStyle(props['mask-style']);
|
|
21
|
-
const { height: indicatorH, ...pickerOverlayStyle } = indicatorStyle;
|
|
19
|
+
const { children, value = [], bindchange, style, 'indicator-style': indicatorStyle = {}, 'mask-style': pickerMaskStyle = {}, 'enable-var': enableVar, 'external-var-context': externalVarContext } = props;
|
|
20
|
+
const { height: indicatorH, ...pickerIndicatorStyle } = indicatorStyle;
|
|
22
21
|
const nodeRef = useRef(null);
|
|
23
22
|
const cloneRef = useRef(null);
|
|
24
23
|
const activeValueRef = useRef(value);
|
|
25
24
|
activeValueRef.current = value.slice();
|
|
26
25
|
const snapActiveValueRef = useRef(null);
|
|
27
|
-
console.log('[mpx-picker-view] value=', value, Date.now());
|
|
28
26
|
const { normalStyle, hasVarDec, varContextRef, hasSelfPercent, setWidth, setHeight } = useTransformStyle(style, { enableVar, externalVarContext });
|
|
29
27
|
useNodesRef(props, ref, nodeRef, {
|
|
30
28
|
style: normalStyle
|
|
@@ -35,8 +33,7 @@ const _PickerView = forwardRef((props, ref) => {
|
|
|
35
33
|
const onSelectChange = (columnIndex, selectedIndex) => {
|
|
36
34
|
const activeValue = activeValueRef.current;
|
|
37
35
|
activeValue[columnIndex] = selectedIndex;
|
|
38
|
-
|
|
39
|
-
const eventData = getCustomEvent('change', {}, { detail: { value: activeValue, source: 'change' }, layoutRef });
|
|
36
|
+
const eventData = getCustomEvent('change', {}, { detail: { value: activeValue.slice(), source: 'change' }, layoutRef });
|
|
40
37
|
bindchange?.(eventData);
|
|
41
38
|
snapActiveValueRef.current = activeValueRef.current;
|
|
42
39
|
};
|
|
@@ -45,8 +42,7 @@ const _PickerView = forwardRef((props, ref) => {
|
|
|
45
42
|
};
|
|
46
43
|
const onInitialChange = (isInvalid, value) => {
|
|
47
44
|
if (isInvalid || !snapActiveValueRef.current || hasDiff(snapActiveValueRef.current, value)) {
|
|
48
|
-
|
|
49
|
-
const eventData = getCustomEvent('change', {}, { detail: { value, source: 'change' }, layoutRef });
|
|
45
|
+
const eventData = getCustomEvent('change', {}, { detail: { value: value.slice(), source: 'change' }, layoutRef });
|
|
50
46
|
bindchange?.(eventData);
|
|
51
47
|
snapActiveValueRef.current = value.slice();
|
|
52
48
|
}
|
|
@@ -58,7 +54,13 @@ const _PickerView = forwardRef((props, ref) => {
|
|
|
58
54
|
overflow: 'hidden'
|
|
59
55
|
}),
|
|
60
56
|
layoutProps
|
|
61
|
-
}), [
|
|
57
|
+
}), [
|
|
58
|
+
'enable-offset',
|
|
59
|
+
'indicator-style',
|
|
60
|
+
'indicator-class',
|
|
61
|
+
'mask-style',
|
|
62
|
+
'mask-class'
|
|
63
|
+
], { layoutRef });
|
|
62
64
|
const renderColumn = (child, index, columnData, initialIndex) => {
|
|
63
65
|
const childProps = child?.props || {};
|
|
64
66
|
const wrappedProps = extendObject({}, childProps, {
|
|
@@ -70,10 +72,9 @@ const _PickerView = forwardRef((props, ref) => {
|
|
|
70
72
|
height: normalStyle?.height || DefaultPickerItemH,
|
|
71
73
|
itemHeight: indicatorH || DefaultPickerItemH
|
|
72
74
|
},
|
|
73
|
-
columnStyle: normalStyle,
|
|
74
75
|
onSelectChange: onSelectChange.bind(null, index),
|
|
75
76
|
initialIndex,
|
|
76
|
-
|
|
77
|
+
pickerIndicatorStyle,
|
|
77
78
|
pickerMaskStyle
|
|
78
79
|
});
|
|
79
80
|
const realElement = React.cloneElement(child, wrappedProps);
|
|
@@ -114,9 +115,11 @@ const _PickerView = forwardRef((props, ref) => {
|
|
|
114
115
|
onInitialChange(isInvalid, validValue);
|
|
115
116
|
return renderColumns;
|
|
116
117
|
};
|
|
117
|
-
return (<
|
|
118
|
-
<View
|
|
119
|
-
|
|
118
|
+
return (<PickerViewStyleContext.Provider value={textStyle}>
|
|
119
|
+
<View {...innerProps}>
|
|
120
|
+
<View style={[styles.wrapper]}>{renderPickerColumns()}</View>
|
|
121
|
+
</View>
|
|
122
|
+
</PickerViewStyleContext.Provider>);
|
|
120
123
|
});
|
|
121
124
|
_PickerView.displayName = 'MpxPickerView';
|
|
122
125
|
export default _PickerView;
|