@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.
Files changed (77) hide show
  1. package/lib/dependencies/RecordGlobalComponentsDependency.js +11 -12
  2. package/lib/dependencies/RecordRuntimeInfoDependency.js +1 -1
  3. package/lib/index.js +23 -7
  4. package/lib/json-compiler/index.js +2 -11
  5. package/lib/loader.js +24 -45
  6. package/lib/native-loader.js +49 -64
  7. package/lib/platform/json/wx/index.js +3 -10
  8. package/lib/platform/style/wx/index.js +15 -10
  9. package/lib/react/index.js +4 -3
  10. package/lib/react/processJSON.js +5 -13
  11. package/lib/react/processMainScript.js +7 -3
  12. package/lib/react/processScript.js +3 -4
  13. package/lib/react/processTemplate.js +2 -2
  14. package/lib/resolver/AddModePlugin.js +17 -4
  15. package/lib/runtime/components/react/dist/mpx-button.jsx +1 -1
  16. package/lib/runtime/components/react/dist/mpx-checkbox-group.jsx +30 -17
  17. package/lib/runtime/components/react/dist/mpx-checkbox.jsx +1 -1
  18. package/lib/runtime/components/react/dist/mpx-form.jsx +33 -24
  19. package/lib/runtime/components/react/dist/mpx-icon.jsx +1 -1
  20. package/lib/runtime/components/react/dist/mpx-image/index.jsx +1 -1
  21. package/lib/runtime/components/react/dist/mpx-input.jsx +44 -38
  22. package/lib/runtime/components/react/dist/mpx-label.jsx +10 -7
  23. package/lib/runtime/components/react/dist/mpx-movable-area.jsx +10 -17
  24. package/lib/runtime/components/react/dist/mpx-movable-view.jsx +378 -294
  25. package/lib/runtime/components/react/dist/mpx-navigator.jsx +1 -1
  26. package/lib/runtime/components/react/dist/mpx-radio-group.jsx +30 -17
  27. package/lib/runtime/components/react/dist/mpx-radio.jsx +1 -1
  28. package/lib/runtime/components/react/dist/mpx-root-portal.jsx +1 -1
  29. package/lib/runtime/components/react/dist/mpx-scroll-view.jsx +49 -29
  30. package/lib/runtime/components/react/dist/mpx-swiper/carouse.jsx +1 -1
  31. package/lib/runtime/components/react/dist/mpx-swiper/index.jsx +1 -1
  32. package/lib/runtime/components/react/dist/mpx-swiper-item.jsx +1 -1
  33. package/lib/runtime/components/react/dist/mpx-switch.jsx +8 -1
  34. package/lib/runtime/components/react/dist/mpx-text.jsx +1 -1
  35. package/lib/runtime/components/react/dist/mpx-textarea.jsx +1 -1
  36. package/lib/runtime/components/react/dist/mpx-view.jsx +1 -1
  37. package/lib/runtime/components/react/dist/mpx-web-view.jsx +1 -1
  38. package/lib/runtime/components/react/dist/useAnimationHooks.js +96 -8
  39. package/lib/runtime/components/react/dist/utils.jsx +12 -3
  40. package/lib/runtime/components/react/getInnerListeners.ts +1 -0
  41. package/lib/runtime/components/react/mpx-button.tsx +1 -1
  42. package/lib/runtime/components/react/mpx-checkbox-group.tsx +52 -29
  43. package/lib/runtime/components/react/mpx-checkbox.tsx +1 -1
  44. package/lib/runtime/components/react/mpx-form.tsx +42 -34
  45. package/lib/runtime/components/react/mpx-icon.tsx +1 -1
  46. package/lib/runtime/components/react/mpx-image/index.tsx +2 -3
  47. package/lib/runtime/components/react/mpx-input.tsx +68 -66
  48. package/lib/runtime/components/react/mpx-label.tsx +11 -8
  49. package/lib/runtime/components/react/mpx-movable-area.tsx +11 -19
  50. package/lib/runtime/components/react/mpx-movable-view.tsx +456 -334
  51. package/lib/runtime/components/react/mpx-navigator.tsx +1 -1
  52. package/lib/runtime/components/react/mpx-radio-group.tsx +55 -29
  53. package/lib/runtime/components/react/mpx-radio.tsx +1 -1
  54. package/lib/runtime/components/react/mpx-root-portal.tsx +1 -1
  55. package/lib/runtime/components/react/mpx-scroll-view.tsx +81 -36
  56. package/lib/runtime/components/react/mpx-swiper/carouse.tsx +2 -2
  57. package/lib/runtime/components/react/mpx-swiper/index.tsx +2 -1
  58. package/lib/runtime/components/react/mpx-swiper-item.tsx +1 -1
  59. package/lib/runtime/components/react/mpx-switch.tsx +10 -2
  60. package/lib/runtime/components/react/mpx-text.tsx +1 -1
  61. package/lib/runtime/components/react/mpx-textarea.tsx +1 -1
  62. package/lib/runtime/components/react/mpx-view.tsx +1 -1
  63. package/lib/runtime/components/react/mpx-web-view.tsx +1 -1
  64. package/lib/runtime/components/react/useAnimationHooks.ts +97 -13
  65. package/lib/runtime/components/react/useNodesRef.ts +1 -0
  66. package/lib/runtime/components/react/utils.tsx +18 -3
  67. package/lib/runtime/optionProcessorReact.js +0 -15
  68. package/lib/runtime/swanHelper.wxs +1 -1
  69. package/lib/style-compiler/index.js +1 -1
  70. package/lib/style-compiler/plugins/scope-id.js +1 -0
  71. package/lib/template-compiler/compiler.js +46 -16
  72. package/lib/template-compiler/index.js +4 -4
  73. package/lib/utils/pre-process-json.js +113 -0
  74. package/lib/web/index.js +5 -4
  75. package/lib/web/processJSON.js +5 -13
  76. package/lib/web/processTemplate.js +2 -2
  77. package/package.json +4 -4
@@ -31,5 +31,5 @@ const _Navigator = forwardRef((props, ref) => {
31
31
  {children}
32
32
  </MpxView>);
33
33
  });
34
- _Navigator.displayName = 'mpx-navigator';
34
+ _Navigator.displayName = 'MpxNavigator';
35
35
  export default _Navigator;
@@ -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, bindchange } = props;
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 getSelectionValue = () => {
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
- const notifyChange = (evt) => {
56
- bindchange &&
57
- bindchange(getCustomEvent('tap', evt, {
58
- layoutRef,
59
- detail: {
60
- value: getSelectionValue()
61
- }
62
- }, props));
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={{ groupValue, notifyChange }}>
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 = 'mpx-radio-group';
93
+ radioGroup.displayName = 'MpxRadioGroup';
81
94
  export default radioGroup;
@@ -151,5 +151,5 @@ const Radio = forwardRef((radioProps, ref) => {
151
151
  })}
152
152
  </View>);
153
153
  });
154
- Radio.displayName = 'mpx-radio';
154
+ Radio.displayName = 'MpxRadio';
155
155
  export default Radio;
@@ -11,5 +11,5 @@ const _RootPortal = (props) => {
11
11
  </Portal>
12
12
  : <>{children}</>;
13
13
  };
14
- _RootPortal.displayName = 'mpx-root-portal';
14
+ _RootPortal.displayName = 'MpxRootPortal';
15
15
  export default _RootPortal;
@@ -5,7 +5,7 @@
5
5
  * ✔ lower-threshold
6
6
  * ✔ scroll-top
7
7
  * ✔ scroll-left
8
- * scroll-into-view
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 !== props['scroll-top'] ||
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(snapScrollLeft.current, snapScrollTop.current);
87
+ scrollToOffset(scrollLeft, scrollTop);
87
88
  }, 0);
88
89
  return () => {
89
90
  initialTimeout.current && clearTimeout(initialTimeout.current);
90
91
  };
91
92
  }
92
- }, [props['scroll-top'], props['scroll-left']]);
93
+ }, [scrollTop, scrollLeft]);
94
+ useEffect(() => {
95
+ if (refreshing !== refresherTriggered) {
96
+ setRefreshing(!!refresherTriggered);
97
+ }
98
+ }, [refresherTriggered]);
93
99
  useEffect(() => {
94
- if (refreshing !== props['refresher-triggered']) {
95
- setRefreshing(!!props['refresher-triggered']);
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
- }, [props['refresher-triggered']]);
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 { binddragstart, bindtouchstart, enhanced } = props;
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 onScrollEndDrag(e) {
243
- const { binddragend, enhanced } = props;
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
- onScrollEndDrag,
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 = 'mpx-scroll-view';
346
+ _ScrollView.displayName = 'MpxScrollView';
327
347
  export default _ScrollView;
@@ -474,5 +474,5 @@ const _Carouse = forwardRef((props, ref) => {
474
474
  {props.showsPagination && renderPagination()}
475
475
  </View>);
476
476
  });
477
- _Carouse.displayName = '_Carouse';
477
+ _Carouse.displayName = 'MpxCarouse';
478
478
  export default _Carouse;
@@ -64,5 +64,5 @@ const _SwiperWrapper = forwardRef((props, ref) => {
64
64
  {children}
65
65
  </Carouse>;
66
66
  });
67
- _SwiperWrapper.displayName = 'mpx-swiper';
67
+ _SwiperWrapper.displayName = 'MpxSwiper';
68
68
  export default _SwiperWrapper;
@@ -30,5 +30,5 @@ const _SwiperItem = forwardRef((props, ref) => {
30
30
  })}
31
31
  </View>);
32
32
  });
33
- _SwiperItem.displayName = 'mpx-swiper-item';
33
+ _SwiperItem.displayName = 'MpxSwiperItem';
34
34
  export default _SwiperItem;
@@ -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 = 'mpx-switch';
86
+ _Switch.displayName = 'MpxSwitch';
80
87
  export default _Switch;
@@ -36,5 +36,5 @@ const _Text = forwardRef((props, ref) => {
36
36
  })}
37
37
  </Text>);
38
38
  });
39
- _Text.displayName = 'mpx-text';
39
+ _Text.displayName = 'MpxText';
40
40
  export default _Text;
@@ -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 = 'mpx-textarea';
26
+ Textarea.displayName = 'MpxTextarea';
27
27
  export default Textarea;
@@ -638,5 +638,5 @@ const _View = forwardRef((viewProps, ref) => {
638
638
  {childNode}
639
639
  </View>);
640
640
  });
641
- _View.displayName = 'mpx-view';
641
+ _View.displayName = 'MpxView';
642
642
  export default _View;
@@ -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 = 'mpx-web-view';
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: originalStyle = {}, animation } = props;
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 (!toVal) {
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?.length) {
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 DEFAULT_UNLAY_STYLE = {
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 === 'mpx-text' || displayName === 'Text' || !!isCustomText;
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 ? DEFAULT_UNLAY_STYLE : {};
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
+ }
@@ -1,4 +1,5 @@
1
1
  import { useRef } from 'react'
2
+ import { NativeSyntheticEvent } from 'react-native'
2
3
  import { omit } from './utils'
3
4
  import eventConfigMap from './event.config'
4
5
  import {
@@ -408,6 +408,6 @@ const Button = forwardRef<HandlerRef<View, ButtonProps>, ButtonProps>((buttonPro
408
408
  )
409
409
  })
410
410
 
411
- Button.displayName = 'mpx-button'
411
+ Button.displayName = 'MpxButton'
412
412
 
413
413
  export default Button