@mpxjs/webpack-plugin 2.9.66 → 2.9.67
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/dependencies/RecordGlobalComponentsDependency.js +11 -12
- package/lib/dependencies/RecordRuntimeInfoDependency.js +1 -1
- package/lib/index.js +23 -7
- package/lib/json-compiler/index.js +2 -11
- package/lib/loader.js +24 -45
- package/lib/native-loader.js +49 -64
- package/lib/platform/json/wx/index.js +3 -10
- package/lib/platform/style/wx/index.js +15 -10
- package/lib/react/index.js +4 -3
- package/lib/react/processJSON.js +5 -13
- package/lib/react/processMainScript.js +7 -3
- package/lib/react/processScript.js +3 -4
- package/lib/react/processTemplate.js +2 -2
- package/lib/resolver/AddModePlugin.js +17 -4
- package/lib/runtime/components/react/dist/mpx-button.jsx +1 -1
- package/lib/runtime/components/react/dist/mpx-checkbox-group.jsx +30 -17
- package/lib/runtime/components/react/dist/mpx-checkbox.jsx +1 -1
- package/lib/runtime/components/react/dist/mpx-form.jsx +33 -24
- package/lib/runtime/components/react/dist/mpx-icon.jsx +1 -1
- package/lib/runtime/components/react/dist/mpx-image/index.jsx +1 -1
- package/lib/runtime/components/react/dist/mpx-input.jsx +44 -38
- package/lib/runtime/components/react/dist/mpx-label.jsx +10 -7
- package/lib/runtime/components/react/dist/mpx-movable-area.jsx +10 -17
- package/lib/runtime/components/react/dist/mpx-movable-view.jsx +378 -294
- package/lib/runtime/components/react/dist/mpx-navigator.jsx +1 -1
- package/lib/runtime/components/react/dist/mpx-radio-group.jsx +30 -17
- package/lib/runtime/components/react/dist/mpx-radio.jsx +1 -1
- package/lib/runtime/components/react/dist/mpx-root-portal.jsx +1 -1
- package/lib/runtime/components/react/dist/mpx-scroll-view.jsx +49 -29
- package/lib/runtime/components/react/dist/mpx-swiper/carouse.jsx +1 -1
- package/lib/runtime/components/react/dist/mpx-swiper/index.jsx +1 -1
- package/lib/runtime/components/react/dist/mpx-swiper-item.jsx +1 -1
- package/lib/runtime/components/react/dist/mpx-switch.jsx +8 -1
- package/lib/runtime/components/react/dist/mpx-text.jsx +1 -1
- package/lib/runtime/components/react/dist/mpx-textarea.jsx +1 -1
- package/lib/runtime/components/react/dist/mpx-view.jsx +1 -1
- package/lib/runtime/components/react/dist/mpx-web-view.jsx +1 -1
- package/lib/runtime/components/react/dist/useAnimationHooks.js +96 -8
- package/lib/runtime/components/react/dist/utils.jsx +12 -3
- package/lib/runtime/components/react/getInnerListeners.ts +1 -0
- package/lib/runtime/components/react/mpx-button.tsx +1 -1
- package/lib/runtime/components/react/mpx-checkbox-group.tsx +52 -29
- package/lib/runtime/components/react/mpx-checkbox.tsx +1 -1
- package/lib/runtime/components/react/mpx-form.tsx +42 -34
- package/lib/runtime/components/react/mpx-icon.tsx +1 -1
- package/lib/runtime/components/react/mpx-image/index.tsx +2 -3
- package/lib/runtime/components/react/mpx-input.tsx +68 -66
- package/lib/runtime/components/react/mpx-label.tsx +11 -8
- package/lib/runtime/components/react/mpx-movable-area.tsx +11 -19
- package/lib/runtime/components/react/mpx-movable-view.tsx +456 -334
- package/lib/runtime/components/react/mpx-navigator.tsx +1 -1
- package/lib/runtime/components/react/mpx-radio-group.tsx +55 -29
- package/lib/runtime/components/react/mpx-radio.tsx +1 -1
- package/lib/runtime/components/react/mpx-root-portal.tsx +1 -1
- package/lib/runtime/components/react/mpx-scroll-view.tsx +81 -36
- package/lib/runtime/components/react/mpx-swiper/carouse.tsx +2 -2
- package/lib/runtime/components/react/mpx-swiper/index.tsx +2 -1
- package/lib/runtime/components/react/mpx-swiper-item.tsx +1 -1
- package/lib/runtime/components/react/mpx-switch.tsx +10 -2
- package/lib/runtime/components/react/mpx-text.tsx +1 -1
- package/lib/runtime/components/react/mpx-textarea.tsx +1 -1
- package/lib/runtime/components/react/mpx-view.tsx +1 -1
- package/lib/runtime/components/react/mpx-web-view.tsx +1 -1
- package/lib/runtime/components/react/useAnimationHooks.ts +97 -13
- package/lib/runtime/components/react/useNodesRef.ts +1 -0
- package/lib/runtime/components/react/utils.tsx +18 -3
- package/lib/runtime/optionProcessorReact.js +0 -15
- package/lib/runtime/swanHelper.wxs +1 -1
- package/lib/style-compiler/index.js +1 -1
- package/lib/style-compiler/plugins/scope-id.js +1 -0
- package/lib/template-compiler/compiler.js +46 -16
- package/lib/template-compiler/index.js +4 -4
- package/lib/utils/pre-process-json.js +113 -0
- package/lib/web/index.js +5 -4
- package/lib/web/processJSON.js +5 -13
- package/lib/web/processTemplate.js +2 -2
- package/package.json +4 -4
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* ✔ bindchange
|
|
3
3
|
*/
|
|
4
|
-
import { useRef, forwardRef, useContext } from 'react';
|
|
4
|
+
import { useRef, forwardRef, useContext, useMemo, useEffect } from 'react';
|
|
5
5
|
import { View } from 'react-native';
|
|
6
6
|
import { warn } from '@mpxjs/utils';
|
|
7
7
|
import { FormContext, RadioGroupContext } from './context';
|
|
@@ -9,7 +9,9 @@ import useInnerProps, { getCustomEvent } from './getInnerListeners';
|
|
|
9
9
|
import useNodesRef from './useNodesRef';
|
|
10
10
|
import { useLayout, useTransformStyle, wrapChildren } from './utils';
|
|
11
11
|
const radioGroup = forwardRef((props, ref) => {
|
|
12
|
-
const { style = {}, 'enable-var': enableVar, 'external-var-context': externalVarContext, 'parent-font-size': parentFontSize, 'parent-width': parentWidth, 'parent-height': parentHeight
|
|
12
|
+
const { style = {}, 'enable-var': enableVar, 'external-var-context': externalVarContext, 'parent-font-size': parentFontSize, 'parent-width': parentWidth, 'parent-height': parentHeight } = props;
|
|
13
|
+
const propsRef = useRef({});
|
|
14
|
+
propsRef.current = props;
|
|
13
15
|
const formContext = useContext(FormContext);
|
|
14
16
|
let formValuesMap;
|
|
15
17
|
if (formContext) {
|
|
@@ -28,16 +30,13 @@ const radioGroup = forwardRef((props, ref) => {
|
|
|
28
30
|
const nodeRef = useRef(null);
|
|
29
31
|
useNodesRef(props, ref, nodeRef, { defaultStyle });
|
|
30
32
|
const { layoutRef, layoutStyle, layoutProps } = useLayout({ props, hasSelfPercent, setWidth, setHeight, nodeRef });
|
|
31
|
-
const
|
|
33
|
+
const getValue = () => {
|
|
32
34
|
for (const key in groupValue) {
|
|
33
35
|
if (groupValue[key].checked) {
|
|
34
36
|
return key;
|
|
35
37
|
}
|
|
36
38
|
}
|
|
37
39
|
};
|
|
38
|
-
const getValue = () => {
|
|
39
|
-
return getSelectionValue();
|
|
40
|
-
};
|
|
41
40
|
const resetValue = () => {
|
|
42
41
|
Object.keys(groupValue).forEach((key) => {
|
|
43
42
|
groupValue[key].checked = false;
|
|
@@ -52,15 +51,29 @@ const radioGroup = forwardRef((props, ref) => {
|
|
|
52
51
|
formValuesMap.set(props.name, { getValue, resetValue });
|
|
53
52
|
}
|
|
54
53
|
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
54
|
+
useEffect(() => {
|
|
55
|
+
return () => {
|
|
56
|
+
if (formValuesMap && props.name) {
|
|
57
|
+
formValuesMap.delete(props.name);
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
}, []);
|
|
61
|
+
const contextValue = useMemo(() => {
|
|
62
|
+
const notifyChange = (evt) => {
|
|
63
|
+
const { bindchange } = propsRef.current;
|
|
64
|
+
bindchange &&
|
|
65
|
+
bindchange(getCustomEvent('tap', evt, {
|
|
66
|
+
layoutRef,
|
|
67
|
+
detail: {
|
|
68
|
+
value: getValue()
|
|
69
|
+
}
|
|
70
|
+
}, propsRef.current));
|
|
71
|
+
};
|
|
72
|
+
return {
|
|
73
|
+
groupValue,
|
|
74
|
+
notifyChange
|
|
75
|
+
};
|
|
76
|
+
}, []);
|
|
64
77
|
const innerProps = useInnerProps(props, {
|
|
65
78
|
ref: nodeRef,
|
|
66
79
|
style: { ...normalStyle, ...layoutStyle },
|
|
@@ -69,7 +82,7 @@ const radioGroup = forwardRef((props, ref) => {
|
|
|
69
82
|
layoutRef
|
|
70
83
|
});
|
|
71
84
|
return (<View {...innerProps}>
|
|
72
|
-
<RadioGroupContext.Provider value={
|
|
85
|
+
<RadioGroupContext.Provider value={contextValue}>
|
|
73
86
|
{wrapChildren(props, {
|
|
74
87
|
hasVarDec,
|
|
75
88
|
varContext: varContextRef.current
|
|
@@ -77,5 +90,5 @@ const radioGroup = forwardRef((props, ref) => {
|
|
|
77
90
|
</RadioGroupContext.Provider>
|
|
78
91
|
</View>);
|
|
79
92
|
});
|
|
80
|
-
radioGroup.displayName = '
|
|
93
|
+
radioGroup.displayName = 'MpxRadioGroup';
|
|
81
94
|
export default radioGroup;
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* ✔ lower-threshold
|
|
6
6
|
* ✔ scroll-top
|
|
7
7
|
* ✔ scroll-left
|
|
8
|
-
*
|
|
8
|
+
* ✔ scroll-into-view
|
|
9
9
|
* ✔ scroll-with-animation
|
|
10
10
|
* ✔ enable-back-to-top
|
|
11
11
|
* ✘ enable-passive
|
|
@@ -38,11 +38,13 @@ import { useAnimatedRef } from 'react-native-reanimated';
|
|
|
38
38
|
import { warn } from '@mpxjs/utils';
|
|
39
39
|
import useInnerProps, { getCustomEvent } from './getInnerListeners';
|
|
40
40
|
import useNodesRef from './useNodesRef';
|
|
41
|
-
import { splitProps, splitStyle, useTransformStyle, useLayout, wrapChildren } from './utils';
|
|
41
|
+
import { splitProps, splitStyle, useTransformStyle, useLayout, wrapChildren, flatGesture } from './utils';
|
|
42
42
|
import { IntersectionObserverContext } from './context';
|
|
43
43
|
const _ScrollView = forwardRef((scrollViewProps = {}, ref) => {
|
|
44
44
|
const { textProps, innerProps: props = {} } = splitProps(scrollViewProps);
|
|
45
|
-
const { enhanced = false, bounces = true, style = {}, 'scroll-x': scrollX = false, 'scroll-y': scrollY = false, 'enable-back-to-top': enableBackToTop = false, 'enable-trigger-intersection-observer': enableTriggerIntersectionObserver = false, 'paging-enabled': pagingEnabled = false, 'upper-threshold': upperThreshold = 50, 'lower-threshold': lowerThreshold = 50, 'scroll-with-animation': scrollWithAnimation, 'refresher-enabled': refresherEnabled, 'refresher-default-style': refresherDefaultStyle, 'refresher-background': refresherBackground, 'show-scrollbar': showScrollbar = true, 'enable-var': enableVar, 'external-var-context': externalVarContext, 'parent-font-size': parentFontSize, 'parent-width': parentWidth, 'parent-height': parentHeight } = props;
|
|
45
|
+
const { enhanced = false, bounces = true, style = {}, binddragstart, binddragging, binddragend, bindtouchstart, bindtouchmove, bindtouchend, 'scroll-x': scrollX = false, 'scroll-y': scrollY = false, 'enable-back-to-top': enableBackToTop = false, 'enable-trigger-intersection-observer': enableTriggerIntersectionObserver = false, 'paging-enabled': pagingEnabled = false, 'upper-threshold': upperThreshold = 50, 'lower-threshold': lowerThreshold = 50, 'scroll-with-animation': scrollWithAnimation, 'refresher-enabled': refresherEnabled, 'refresher-default-style': refresherDefaultStyle, 'refresher-background': refresherBackground, 'show-scrollbar': showScrollbar = true, 'scroll-into-view': scrollIntoView = '', 'scroll-top': scrollTop = 0, 'scroll-left': scrollLeft = 0, 'refresher-triggered': refresherTriggered, 'enable-var': enableVar, 'external-var-context': externalVarContext, 'parent-font-size': parentFontSize, 'parent-width': parentWidth, 'parent-height': parentHeight, 'simultaneous-handlers': originSimultaneousHandlers, 'wait-for': waitFor, __selectRef } = props;
|
|
46
|
+
const simultaneousHandlers = flatGesture(originSimultaneousHandlers);
|
|
47
|
+
const waitForHandlers = flatGesture(waitFor);
|
|
46
48
|
const [refreshing, setRefreshing] = useState(true);
|
|
47
49
|
const snapScrollTop = useRef(0);
|
|
48
50
|
const snapScrollLeft = useRef(0);
|
|
@@ -58,6 +60,7 @@ const _ScrollView = forwardRef((scrollViewProps = {}, ref) => {
|
|
|
58
60
|
const hasCallScrollToLower = useRef(false);
|
|
59
61
|
const initialTimeout = useRef(null);
|
|
60
62
|
const intersectionObservers = useContext(IntersectionObserverContext);
|
|
63
|
+
const snapScrollIntoView = useRef('');
|
|
61
64
|
const { normalStyle, hasVarDec, varContextRef, hasSelfPercent, setWidth, setHeight } = useTransformStyle(style, { enableVar, externalVarContext, parentFontSize, parentWidth, parentHeight });
|
|
62
65
|
const { textStyle, innerStyle } = splitStyle(normalStyle);
|
|
63
66
|
const scrollViewRef = useAnimatedRef();
|
|
@@ -71,30 +74,42 @@ const _ScrollView = forwardRef((scrollViewProps = {}, ref) => {
|
|
|
71
74
|
fastDeceleration: false,
|
|
72
75
|
decelerationDisabled: false,
|
|
73
76
|
scrollTo: scrollToOffset
|
|
74
|
-
}
|
|
77
|
+
},
|
|
78
|
+
gestureRef: scrollViewRef
|
|
75
79
|
});
|
|
76
80
|
const { layoutRef, layoutStyle, layoutProps } = useLayout({ props, hasSelfPercent, setWidth, setHeight, nodeRef: scrollViewRef, onLayout });
|
|
77
81
|
if (scrollX && scrollY) {
|
|
78
82
|
warn('scroll-x and scroll-y cannot be set to true at the same time, Mpx will use the value of scroll-y as the criterion');
|
|
79
83
|
}
|
|
80
84
|
useEffect(() => {
|
|
81
|
-
if (snapScrollTop.current !==
|
|
82
|
-
snapScrollLeft.current !== props['scroll-left']) {
|
|
83
|
-
snapScrollTop.current = props['scroll-top'] || 0;
|
|
84
|
-
snapScrollLeft.current = props['scroll-left'] || 0;
|
|
85
|
+
if (snapScrollTop.current !== scrollTop || snapScrollLeft.current !== scrollLeft) {
|
|
85
86
|
initialTimeout.current = setTimeout(() => {
|
|
86
|
-
scrollToOffset(
|
|
87
|
+
scrollToOffset(scrollLeft, scrollTop);
|
|
87
88
|
}, 0);
|
|
88
89
|
return () => {
|
|
89
90
|
initialTimeout.current && clearTimeout(initialTimeout.current);
|
|
90
91
|
};
|
|
91
92
|
}
|
|
92
|
-
}, [
|
|
93
|
+
}, [scrollTop, scrollLeft]);
|
|
94
|
+
useEffect(() => {
|
|
95
|
+
if (refreshing !== refresherTriggered) {
|
|
96
|
+
setRefreshing(!!refresherTriggered);
|
|
97
|
+
}
|
|
98
|
+
}, [refresherTriggered]);
|
|
93
99
|
useEffect(() => {
|
|
94
|
-
if (
|
|
95
|
-
|
|
100
|
+
if (scrollIntoView && __selectRef && snapScrollIntoView.current !== scrollIntoView) {
|
|
101
|
+
snapScrollIntoView.current = scrollIntoView || '';
|
|
102
|
+
setTimeout(() => {
|
|
103
|
+
const refs = __selectRef(`#${scrollIntoView}`, 'node');
|
|
104
|
+
if (refs) {
|
|
105
|
+
const { nodeRef } = refs.getNodeInstance();
|
|
106
|
+
nodeRef.current?.measureLayout(scrollViewRef.current, (left, top) => {
|
|
107
|
+
scrollToOffset(left, top);
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
});
|
|
96
111
|
}
|
|
97
|
-
}, [
|
|
112
|
+
}, [scrollIntoView]);
|
|
98
113
|
function selectLength(size) {
|
|
99
114
|
return !scrollX ? size.height : size.width;
|
|
100
115
|
}
|
|
@@ -204,6 +219,8 @@ const _ScrollView = forwardRef((scrollViewProps = {}, ref) => {
|
|
|
204
219
|
scrollViewRef.current.scrollTo({ x, y, animated: !!scrollWithAnimation });
|
|
205
220
|
scrollOptions.current.scrollLeft = x;
|
|
206
221
|
scrollOptions.current.scrollTop = y;
|
|
222
|
+
snapScrollLeft.current = x;
|
|
223
|
+
snapScrollTop.current = y;
|
|
207
224
|
}
|
|
208
225
|
}
|
|
209
226
|
function onRefresh() {
|
|
@@ -212,7 +229,7 @@ const _ScrollView = forwardRef((scrollViewProps = {}, ref) => {
|
|
|
212
229
|
bindrefresherrefresh(getCustomEvent('refresherrefresh', {}, { layoutRef }, props));
|
|
213
230
|
}
|
|
214
231
|
function onScrollTouchStart(e) {
|
|
215
|
-
const {
|
|
232
|
+
const { bindtouchstart } = props;
|
|
216
233
|
bindtouchstart && bindtouchstart(e);
|
|
217
234
|
if (enhanced) {
|
|
218
235
|
binddragstart &&
|
|
@@ -226,7 +243,6 @@ const _ScrollView = forwardRef((scrollViewProps = {}, ref) => {
|
|
|
226
243
|
}
|
|
227
244
|
}
|
|
228
245
|
function onScrollTouchMove(e) {
|
|
229
|
-
const { binddragging, bindtouchmove, enhanced } = props;
|
|
230
246
|
bindtouchmove && bindtouchmove(e);
|
|
231
247
|
if (enhanced) {
|
|
232
248
|
binddragging &&
|
|
@@ -239,24 +255,23 @@ const _ScrollView = forwardRef((scrollViewProps = {}, ref) => {
|
|
|
239
255
|
}, props));
|
|
240
256
|
}
|
|
241
257
|
}
|
|
242
|
-
function
|
|
243
|
-
|
|
258
|
+
function onScrollTouchEnd(e) {
|
|
259
|
+
bindtouchend && bindtouchend(e);
|
|
244
260
|
if (enhanced) {
|
|
245
|
-
const { x: scrollLeft, y: scrollTop } = e.nativeEvent.contentOffset;
|
|
246
|
-
const { width: scrollWidth, height: scrollHeight } = e.nativeEvent.contentSize;
|
|
247
261
|
binddragend &&
|
|
248
262
|
binddragend(getCustomEvent('dragend', e, {
|
|
249
263
|
detail: {
|
|
250
|
-
scrollLeft: scrollLeft,
|
|
251
|
-
scrollTop: scrollTop
|
|
252
|
-
scrollHeight,
|
|
253
|
-
scrollWidth
|
|
264
|
+
scrollLeft: scrollOptions.current.scrollLeft || 0,
|
|
265
|
+
scrollTop: scrollOptions.current.scrollTop || 0
|
|
254
266
|
},
|
|
255
267
|
layoutRef
|
|
256
268
|
}, props));
|
|
257
|
-
updateScrollOptions(e, { scrollLeft, scrollTop });
|
|
258
269
|
}
|
|
259
270
|
}
|
|
271
|
+
function onScrollDrag(e) {
|
|
272
|
+
const { x: scrollLeft, y: scrollTop } = e.nativeEvent.contentOffset;
|
|
273
|
+
updateScrollOptions(e, { scrollLeft, scrollTop });
|
|
274
|
+
}
|
|
260
275
|
let scrollAdditionalProps = {
|
|
261
276
|
style: { ...innerStyle, ...layoutStyle },
|
|
262
277
|
pinchGestureEnabled: false,
|
|
@@ -269,11 +284,15 @@ const _ScrollView = forwardRef((scrollViewProps = {}, ref) => {
|
|
|
269
284
|
ref: scrollViewRef,
|
|
270
285
|
onScroll: onScroll,
|
|
271
286
|
onContentSizeChange: onContentSizeChange,
|
|
272
|
-
bindtouchstart: onScrollTouchStart,
|
|
273
|
-
bindtouchmove: onScrollTouchMove,
|
|
274
|
-
|
|
287
|
+
bindtouchstart: ((enhanced && binddragstart) || bindtouchstart) ? onScrollTouchStart : undefined,
|
|
288
|
+
bindtouchmove: ((enhanced && binddragging) || bindtouchend) ? onScrollTouchMove : undefined,
|
|
289
|
+
bindtouchend: ((enhanced && binddragend) || bindtouchend) ? onScrollTouchEnd : undefined,
|
|
290
|
+
onScrollBeginDrag: onScrollDrag,
|
|
291
|
+
onScrollEndDrag: onScrollDrag,
|
|
275
292
|
onMomentumScrollEnd: onScrollEnd,
|
|
276
|
-
...layoutProps
|
|
293
|
+
...layoutProps,
|
|
294
|
+
...(simultaneousHandlers ? { simultaneousHandlers } : {}),
|
|
295
|
+
...(waitForHandlers ? { waitFor: waitForHandlers } : {})
|
|
277
296
|
};
|
|
278
297
|
if (enhanced) {
|
|
279
298
|
scrollAdditionalProps = {
|
|
@@ -283,6 +302,7 @@ const _ScrollView = forwardRef((scrollViewProps = {}, ref) => {
|
|
|
283
302
|
};
|
|
284
303
|
}
|
|
285
304
|
const innerProps = useInnerProps(props, scrollAdditionalProps, [
|
|
305
|
+
'id',
|
|
286
306
|
'scroll-x',
|
|
287
307
|
'scroll-y',
|
|
288
308
|
'enable-back-to-top',
|
|
@@ -323,5 +343,5 @@ const _ScrollView = forwardRef((scrollViewProps = {}, ref) => {
|
|
|
323
343
|
})}
|
|
324
344
|
</ScrollView>);
|
|
325
345
|
});
|
|
326
|
-
_ScrollView.displayName = '
|
|
346
|
+
_ScrollView.displayName = 'MpxScrollView';
|
|
327
347
|
export default _ScrollView;
|
|
@@ -58,6 +58,13 @@ const _Switch = forwardRef((props, ref) => {
|
|
|
58
58
|
formValuesMap.set(props.name, { getValue, resetValue });
|
|
59
59
|
}
|
|
60
60
|
}
|
|
61
|
+
useEffect(() => {
|
|
62
|
+
return () => {
|
|
63
|
+
if (formValuesMap && props.name) {
|
|
64
|
+
formValuesMap.delete(props.name);
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
}, []);
|
|
61
68
|
const innerProps = useInnerProps(props, {
|
|
62
69
|
ref: nodeRef,
|
|
63
70
|
style: { ...normalStyle, ...layoutStyle },
|
|
@@ -76,5 +83,5 @@ const _Switch = forwardRef((props, ref) => {
|
|
|
76
83
|
}
|
|
77
84
|
return <Switch {...innerProps} style={normalStyle} value={isChecked} trackColor={{ false: '#FFF', true: color }} thumbColor={isChecked ? '#FFF' : '#f4f3f4'} ios_backgroundColor="#FFF"/>;
|
|
78
85
|
});
|
|
79
|
-
_Switch.displayName = '
|
|
86
|
+
_Switch.displayName = 'MpxSwitch';
|
|
80
87
|
export default _Switch;
|
|
@@ -23,5 +23,5 @@ const Textarea = forwardRef((props, ref) => {
|
|
|
23
23
|
]);
|
|
24
24
|
return (<Input ref={ref} multiline confirm-type='next' bindblur={() => Keyboard.dismiss()} {...restProps}/>);
|
|
25
25
|
});
|
|
26
|
-
Textarea.displayName = '
|
|
26
|
+
Textarea.displayName = 'MpxTextarea';
|
|
27
27
|
export default Textarea;
|
|
@@ -109,5 +109,5 @@ const _WebView = forwardRef((props, ref) => {
|
|
|
109
109
|
<WebView style={defaultWebViewStyle} source={{ uri: src }} ref={webViewRef} onLoad={_load} onError={_error} onMessage={_message} javaScriptEnabled={true}></WebView>
|
|
110
110
|
</Portal>);
|
|
111
111
|
});
|
|
112
|
-
_WebView.displayName = '
|
|
112
|
+
_WebView.displayName = 'MpxWebview';
|
|
113
113
|
export default _WebView;
|
|
@@ -45,19 +45,79 @@ const InitialValue = Object.assign({
|
|
|
45
45
|
transformOrigin: ['50%', '50%', 0]
|
|
46
46
|
}, TransformInitial);
|
|
47
47
|
const TransformOrigin = 'transformOrigin';
|
|
48
|
-
// deg 角度
|
|
49
|
-
// const isDeg = (key: RuleKey) => ['rotateX', 'rotateY', 'rotateZ', 'rotate', 'skewX', 'skewY'].includes(key)
|
|
50
|
-
// 背景色
|
|
51
|
-
// const isBg = (key: RuleKey) => key === 'backgroundColor'
|
|
52
48
|
// transform
|
|
53
49
|
const isTransform = (key) => Object.keys(TransformInitial).includes(key);
|
|
50
|
+
// parse string transform, eg: transform: 'rotateX(45deg) rotateZ(0.785398rad)'
|
|
51
|
+
const parseTransform = (transformStr) => {
|
|
52
|
+
const values = transformStr.trim().split(/\s+/);
|
|
53
|
+
const transform = [];
|
|
54
|
+
values.forEach(item => {
|
|
55
|
+
const match = item.match(/([/\w]+)\(([^)]+)\)/);
|
|
56
|
+
if (match && match.length >= 3) {
|
|
57
|
+
let key = match[1];
|
|
58
|
+
const val = match[2];
|
|
59
|
+
switch (key) {
|
|
60
|
+
case 'translateX':
|
|
61
|
+
case 'translateY':
|
|
62
|
+
case 'scaleX':
|
|
63
|
+
case 'scaleY':
|
|
64
|
+
case 'rotateX':
|
|
65
|
+
case 'rotateY':
|
|
66
|
+
case 'rotateZ':
|
|
67
|
+
case 'rotate':
|
|
68
|
+
case 'skewX':
|
|
69
|
+
case 'skewY':
|
|
70
|
+
case 'perspective':
|
|
71
|
+
// 单个值处理
|
|
72
|
+
transform.push({ [key]: global.__formatValue(val) });
|
|
73
|
+
break;
|
|
74
|
+
case 'matrix':
|
|
75
|
+
case 'matrix3d':
|
|
76
|
+
transform.push({ [key]: val.split(',').map(val => +val) });
|
|
77
|
+
break;
|
|
78
|
+
case 'translate':
|
|
79
|
+
case 'scale':
|
|
80
|
+
case 'skew':
|
|
81
|
+
case 'rotate3d': // x y z angle
|
|
82
|
+
case 'translate3d': // x y 支持 z不支持
|
|
83
|
+
case 'scale3d': // x y 支持 z不支持
|
|
84
|
+
{
|
|
85
|
+
// 2 个以上的值处理
|
|
86
|
+
key = key.replace('3d', '');
|
|
87
|
+
const vals = val.split(',', key === 'rotate' ? 4 : 3);
|
|
88
|
+
// scale(.5) === scaleX(.5) scaleY(.5) 这里处理一下
|
|
89
|
+
if (vals.length === 1 && key === 'scale') {
|
|
90
|
+
vals.push(vals[0]);
|
|
91
|
+
}
|
|
92
|
+
const xyz = ['X', 'Y', 'Z'];
|
|
93
|
+
transform.push(...vals.map((v, index) => {
|
|
94
|
+
return { [`${key}${xyz[index] || ''}`]: global.__formatValue(v.trim()) };
|
|
95
|
+
}));
|
|
96
|
+
break;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
return transform;
|
|
102
|
+
};
|
|
103
|
+
// format style
|
|
104
|
+
const formatStyle = (style) => {
|
|
105
|
+
if (!style.transform || Array.isArray(style.transform))
|
|
106
|
+
return style;
|
|
107
|
+
return Object.assign({}, style, {
|
|
108
|
+
transform: parseTransform(style.transform)
|
|
109
|
+
});
|
|
110
|
+
};
|
|
54
111
|
export default function useAnimationHooks(props) {
|
|
55
|
-
const { style
|
|
112
|
+
const { style = {}, animation } = props;
|
|
113
|
+
const originalStyle = formatStyle(style);
|
|
56
114
|
// id 标识
|
|
57
115
|
const id = animation?.id || -1;
|
|
58
116
|
// 有动画样式的 style key
|
|
59
117
|
const animatedStyleKeys = useSharedValue([]);
|
|
118
|
+
// 记录动画key的style样式值 没有的话设置为false
|
|
60
119
|
const animatedKeys = useRef({});
|
|
120
|
+
// const animatedKeys = useRef({} as {[propName: keyof ExtendedViewStyle]: boolean|number|string})
|
|
61
121
|
// ** 全量 style prop sharedValue
|
|
62
122
|
// 不能做增量的原因:
|
|
63
123
|
// 1 尝试用 useRef,但 useAnimatedStyle 访问后的 ref 不能在增加新的值,被冻结
|
|
@@ -80,6 +140,16 @@ export default function useAnimationHooks(props) {
|
|
|
80
140
|
// 驱动动画
|
|
81
141
|
createAnimation(keys);
|
|
82
142
|
}, [id]);
|
|
143
|
+
// 同步style更新
|
|
144
|
+
// useEffect(() => {
|
|
145
|
+
// Object.keys(animatedKeys.current).forEach(key => {
|
|
146
|
+
// const originVal = getOriginalStyleVal(key, isTransform(key))
|
|
147
|
+
// if (originVal && animatedKeys.current[key] !== originVal) {
|
|
148
|
+
// animatedKeys.current[key] = originVal
|
|
149
|
+
// shareValMap[key].value = originVal
|
|
150
|
+
// }
|
|
151
|
+
// })
|
|
152
|
+
// }, [style])
|
|
83
153
|
// ** 清空动画
|
|
84
154
|
useEffect(() => {
|
|
85
155
|
return () => {
|
|
@@ -115,7 +185,7 @@ export default function useAnimationHooks(props) {
|
|
|
115
185
|
animatedKeys.forEach(key => {
|
|
116
186
|
let toVal = (rules.get(key) || transform.get(key));
|
|
117
187
|
// key不存在,第一轮取shareValMap[key]value,非第一轮取上一轮的
|
|
118
|
-
if (
|
|
188
|
+
if (toVal === undefined) {
|
|
119
189
|
toVal = index > 0 ? lastValueMap[key] : shareValMap[key].value;
|
|
120
190
|
}
|
|
121
191
|
const animation = getAnimation({ key, value: toVal }, { delay, duration, easing }, needSetCallback ? setTransformOrigin : undefined);
|
|
@@ -143,9 +213,8 @@ export default function useAnimationHooks(props) {
|
|
|
143
213
|
: withTiming(value, { duration, easing });
|
|
144
214
|
return delay ? withDelay(delay, animation) : animation;
|
|
145
215
|
}
|
|
146
|
-
// 获取初始值(prop style or 默认值)
|
|
147
216
|
function getInitialVal(key, isTransform = false) {
|
|
148
|
-
if (isTransform && originalStyle.transform
|
|
217
|
+
if (isTransform && Array.isArray(originalStyle.transform)) {
|
|
149
218
|
let initialVal = InitialValue[key];
|
|
150
219
|
// 仅支持 { transform: [{rotateX: '45deg'}, {rotateZ: '0.785398rad'}] } 格式的初始样式
|
|
151
220
|
originalStyle.transform.forEach(item => {
|
|
@@ -156,12 +225,31 @@ export default function useAnimationHooks(props) {
|
|
|
156
225
|
}
|
|
157
226
|
return originalStyle[key] === undefined ? InitialValue[key] : originalStyle[key];
|
|
158
227
|
}
|
|
228
|
+
// 从 prop style 中获取样式初始值 没有为undefined
|
|
229
|
+
// function getOriginalStyleVal (key: keyof ExtendedViewStyle, isTransform = false) {
|
|
230
|
+
// if (isTransform && Array.isArray(originalStyle.transform)) {
|
|
231
|
+
// let initialVal = undefined // InitialValue[key]
|
|
232
|
+
// // 仅支持 { transform: [{rotateX: '45deg'}, {rotateZ: '0.785398rad'}] } 格式的初始样式
|
|
233
|
+
// originalStyle.transform.forEach(item => {
|
|
234
|
+
// if (item[key] !== undefined) initialVal = item[key]
|
|
235
|
+
// })
|
|
236
|
+
// return initialVal
|
|
237
|
+
// }
|
|
238
|
+
// return originalStyle[key] // === undefined ? InitialValue[key] : originalStyle[key]
|
|
239
|
+
// }
|
|
240
|
+
// 获取动画shareVal初始值(prop style or 默认值)
|
|
241
|
+
// function getInitialVal (key: keyof ExtendedViewStyle, isTransform = false) {
|
|
242
|
+
// const originalVal = getOriginalStyleVal(key, isTransform)
|
|
243
|
+
// return originalVal === undefined ? InitialValue[key] : originalStyle[key]
|
|
244
|
+
// }
|
|
159
245
|
// 循环 animation actions 获取所有有动画的 style prop name
|
|
160
246
|
function getAnimatedStyleKeys() {
|
|
161
247
|
return (animation?.actions || []).reduce((keyMap, action) => {
|
|
162
248
|
const { rules, transform } = action;
|
|
163
249
|
const ruleArr = [...rules.keys(), ...transform.keys()];
|
|
164
250
|
ruleArr.forEach(key => {
|
|
251
|
+
// const originalVal = getOriginalStyleVal(key, isTransform(key))
|
|
252
|
+
// if (!keyMap[key]) keyMap[key] = originalVal === undefined ? false : originalVal
|
|
165
253
|
if (!keyMap[key])
|
|
166
254
|
keyMap[key] = true;
|
|
167
255
|
});
|
|
@@ -9,7 +9,7 @@ export const URL_REGEX = /^\s*url\(["']?(.*?)["']?\)\s*$/;
|
|
|
9
9
|
export const BACKGROUND_REGEX = /^background(Image|Size|Repeat|Position)$/;
|
|
10
10
|
export const TEXT_PROPS_REGEX = /ellipsizeMode|numberOfLines/;
|
|
11
11
|
export const DEFAULT_FONT_SIZE = 16;
|
|
12
|
-
export const
|
|
12
|
+
export const HIDDEN_STYLE = {
|
|
13
13
|
opacity: 0
|
|
14
14
|
};
|
|
15
15
|
const varDecRegExp = /^--.*/;
|
|
@@ -88,7 +88,7 @@ export function isText(ele) {
|
|
|
88
88
|
if (isValidElement(ele)) {
|
|
89
89
|
const displayName = ele.type?.displayName;
|
|
90
90
|
const isCustomText = ele.type?.isCustomText;
|
|
91
|
-
return displayName === '
|
|
91
|
+
return displayName === 'MpxText' || displayName === 'Text' || !!isCustomText;
|
|
92
92
|
}
|
|
93
93
|
return false;
|
|
94
94
|
}
|
|
@@ -402,7 +402,7 @@ export function splitProps(props) {
|
|
|
402
402
|
export const useLayout = ({ props, hasSelfPercent, setWidth, setHeight, onLayout, nodeRef }) => {
|
|
403
403
|
const layoutRef = useRef({});
|
|
404
404
|
const hasLayoutRef = useRef(false);
|
|
405
|
-
const layoutStyle = !hasLayoutRef.current && hasSelfPercent ?
|
|
405
|
+
const layoutStyle = !hasLayoutRef.current && hasSelfPercent ? HIDDEN_STYLE : {};
|
|
406
406
|
const layoutProps = {};
|
|
407
407
|
const enableOffset = props['enable-offset'];
|
|
408
408
|
if (hasSelfPercent || onLayout || enableOffset) {
|
|
@@ -444,3 +444,12 @@ export function wrapChildren(props = {}, { hasVarDec, varContext, textStyle, tex
|
|
|
444
444
|
}
|
|
445
445
|
return children;
|
|
446
446
|
}
|
|
447
|
+
export function flatGesture(gestures = []) {
|
|
448
|
+
return (gestures && gestures.flatMap((gesture) => {
|
|
449
|
+
if (gesture && gesture.nodeRefs) {
|
|
450
|
+
return gesture.nodeRefs
|
|
451
|
+
.map((item) => item.getNodeInstance()?.instance?.gestureRef || {});
|
|
452
|
+
}
|
|
453
|
+
return gesture?.current ? [gesture] : [];
|
|
454
|
+
})) || [];
|
|
455
|
+
}
|