@mpxjs/webpack-plugin 2.9.66 → 2.9.69

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 (112) hide show
  1. package/lib/dependencies/RecordGlobalComponentsDependency.js +11 -12
  2. package/lib/dependencies/RecordRuntimeInfoDependency.js +1 -1
  3. package/lib/index.js +29 -8
  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/platform/template/wx/component-config/canvas.js +8 -0
  10. package/lib/platform/template/wx/component-config/unsupported.js +1 -1
  11. package/lib/react/index.js +4 -3
  12. package/lib/react/processJSON.js +5 -13
  13. package/lib/react/processMainScript.js +7 -3
  14. package/lib/react/processScript.js +3 -4
  15. package/lib/react/processStyles.js +14 -4
  16. package/lib/react/processTemplate.js +2 -2
  17. package/lib/resolver/AddModePlugin.js +20 -7
  18. package/lib/runtime/components/react/context.ts +2 -0
  19. package/lib/runtime/components/react/dist/context.js +1 -0
  20. package/lib/runtime/components/react/dist/getInnerListeners.js +3 -12
  21. package/lib/runtime/components/react/dist/mpx-button.jsx +44 -9
  22. package/lib/runtime/components/react/dist/mpx-canvas/Bus.js +60 -0
  23. package/lib/runtime/components/react/dist/mpx-canvas/CanvasGradient.js +15 -0
  24. package/lib/runtime/components/react/dist/mpx-canvas/CanvasRenderingContext2D.js +84 -0
  25. package/lib/runtime/components/react/dist/mpx-canvas/Image.js +87 -0
  26. package/lib/runtime/components/react/dist/mpx-canvas/ImageData.js +15 -0
  27. package/lib/runtime/components/react/dist/mpx-canvas/constructorsRegistry.js +28 -0
  28. package/lib/runtime/components/react/dist/mpx-canvas/html.js +343 -0
  29. package/lib/runtime/components/react/dist/mpx-canvas/index.jsx +214 -0
  30. package/lib/runtime/components/react/dist/mpx-canvas/utils.jsx +89 -0
  31. package/lib/runtime/components/react/dist/mpx-checkbox-group.jsx +30 -17
  32. package/lib/runtime/components/react/dist/mpx-checkbox.jsx +1 -1
  33. package/lib/runtime/components/react/dist/mpx-form.jsx +33 -24
  34. package/lib/runtime/components/react/dist/mpx-icon.jsx +1 -1
  35. package/lib/runtime/components/react/dist/mpx-image/index.jsx +1 -1
  36. package/lib/runtime/components/react/dist/mpx-input.jsx +44 -38
  37. package/lib/runtime/components/react/dist/mpx-label.jsx +10 -7
  38. package/lib/runtime/components/react/dist/mpx-movable-area.jsx +10 -17
  39. package/lib/runtime/components/react/dist/mpx-movable-view.jsx +378 -294
  40. package/lib/runtime/components/react/dist/mpx-navigator.jsx +1 -1
  41. package/lib/runtime/components/react/dist/mpx-picker-view-column.jsx +143 -84
  42. package/lib/runtime/components/react/dist/mpx-picker-view.jsx +69 -113
  43. package/lib/runtime/components/react/dist/mpx-radio-group.jsx +30 -17
  44. package/lib/runtime/components/react/dist/mpx-radio.jsx +1 -1
  45. package/lib/runtime/components/react/dist/mpx-root-portal.jsx +1 -1
  46. package/lib/runtime/components/react/dist/mpx-scroll-view.jsx +49 -29
  47. package/lib/runtime/components/react/dist/mpx-swiper/carouse.jsx +1 -1
  48. package/lib/runtime/components/react/dist/mpx-swiper/index.jsx +1 -1
  49. package/lib/runtime/components/react/dist/mpx-swiper-item.jsx +1 -1
  50. package/lib/runtime/components/react/dist/mpx-switch.jsx +8 -1
  51. package/lib/runtime/components/react/dist/mpx-text.jsx +1 -1
  52. package/lib/runtime/components/react/dist/mpx-textarea.jsx +1 -1
  53. package/lib/runtime/components/react/dist/mpx-view.jsx +46 -27
  54. package/lib/runtime/components/react/dist/mpx-web-view.jsx +20 -6
  55. package/lib/runtime/components/react/dist/pickerFaces.js +75 -0
  56. package/lib/runtime/components/react/dist/pickerOverlay.jsx +21 -0
  57. package/lib/runtime/components/react/dist/useAnimationHooks.js +96 -8
  58. package/lib/runtime/components/react/dist/utils.jsx +66 -6
  59. package/lib/runtime/components/react/getInnerListeners.ts +3 -16
  60. package/lib/runtime/components/react/mpx-button.tsx +42 -9
  61. package/lib/runtime/components/react/mpx-canvas/Bus.ts +70 -0
  62. package/lib/runtime/components/react/mpx-canvas/CanvasGradient.ts +18 -0
  63. package/lib/runtime/components/react/mpx-canvas/CanvasRenderingContext2D.ts +87 -0
  64. package/lib/runtime/components/react/mpx-canvas/Image.ts +102 -0
  65. package/lib/runtime/components/react/mpx-canvas/ImageData.ts +23 -0
  66. package/lib/runtime/components/react/mpx-canvas/constructorsRegistry.ts +38 -0
  67. package/lib/runtime/components/react/mpx-canvas/html.ts +343 -0
  68. package/lib/runtime/components/react/mpx-canvas/index.tsx +302 -0
  69. package/lib/runtime/components/react/mpx-canvas/utils.tsx +150 -0
  70. package/lib/runtime/components/react/mpx-checkbox-group.tsx +52 -29
  71. package/lib/runtime/components/react/mpx-checkbox.tsx +1 -1
  72. package/lib/runtime/components/react/mpx-form.tsx +42 -34
  73. package/lib/runtime/components/react/mpx-icon.tsx +1 -1
  74. package/lib/runtime/components/react/mpx-image/index.tsx +2 -3
  75. package/lib/runtime/components/react/mpx-input.tsx +68 -66
  76. package/lib/runtime/components/react/mpx-label.tsx +11 -8
  77. package/lib/runtime/components/react/mpx-movable-area.tsx +11 -19
  78. package/lib/runtime/components/react/mpx-movable-view.tsx +456 -334
  79. package/lib/runtime/components/react/mpx-navigator.tsx +1 -1
  80. package/lib/runtime/components/react/mpx-picker-view-column.tsx +232 -103
  81. package/lib/runtime/components/react/mpx-picker-view.tsx +126 -122
  82. package/lib/runtime/components/react/mpx-radio-group.tsx +55 -29
  83. package/lib/runtime/components/react/mpx-radio.tsx +1 -1
  84. package/lib/runtime/components/react/mpx-root-portal.tsx +1 -1
  85. package/lib/runtime/components/react/mpx-scroll-view.tsx +81 -36
  86. package/lib/runtime/components/react/mpx-swiper/carouse.tsx +2 -2
  87. package/lib/runtime/components/react/mpx-swiper/index.tsx +2 -1
  88. package/lib/runtime/components/react/mpx-swiper-item.tsx +1 -1
  89. package/lib/runtime/components/react/mpx-switch.tsx +10 -2
  90. package/lib/runtime/components/react/mpx-text.tsx +1 -1
  91. package/lib/runtime/components/react/mpx-textarea.tsx +1 -1
  92. package/lib/runtime/components/react/mpx-view.tsx +58 -28
  93. package/lib/runtime/components/react/mpx-web-view.tsx +23 -6
  94. package/lib/runtime/components/react/pickerFaces.ts +104 -0
  95. package/lib/runtime/components/react/pickerOverlay.tsx +32 -0
  96. package/lib/runtime/components/react/types/common.ts +2 -0
  97. package/lib/runtime/components/react/types/global.d.ts +2 -0
  98. package/lib/runtime/components/react/useAnimationHooks.ts +97 -13
  99. package/lib/runtime/components/react/useNodesRef.ts +1 -0
  100. package/lib/runtime/components/react/utils.tsx +94 -8
  101. package/lib/runtime/optionProcessorReact.js +0 -15
  102. package/lib/runtime/swanHelper.wxs +1 -1
  103. package/lib/style-compiler/index.js +1 -1
  104. package/lib/style-compiler/plugins/scope-id.js +1 -0
  105. package/lib/template-compiler/compiler.js +47 -16
  106. package/lib/template-compiler/gen-node-react.js +2 -2
  107. package/lib/template-compiler/index.js +4 -4
  108. package/lib/utils/pre-process-json.js +113 -0
  109. package/lib/web/index.js +5 -4
  110. package/lib/web/processJSON.js +5 -13
  111. package/lib/web/processTemplate.js +2 -2
  112. package/package.json +5 -4
@@ -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;
@@ -10,7 +10,7 @@ import useInnerProps from './getInnerListeners';
10
10
  import Animated from 'react-native-reanimated';
11
11
  import useAnimationHooks from './useAnimationHooks';
12
12
  import useNodesRef from './useNodesRef';
13
- import { parseUrl, PERCENT_REGEX, splitStyle, splitProps, useTransformStyle, wrapChildren, useLayout } from './utils';
13
+ import { parseUrl, PERCENT_REGEX, splitStyle, splitProps, useTransformStyle, wrapChildren, useLayout, renderImage, pickStyle } from './utils';
14
14
  import LinearGradient from 'react-native-linear-gradient';
15
15
  const linearMap = new Map([
16
16
  ['top', 0],
@@ -201,7 +201,7 @@ function backgroundSize(imageProps, preImageInfo, imageSize, layoutInfo) {
201
201
  }
202
202
  else { // 数值类型 ImageStyle
203
203
  // 数值类型设置为 stretch
204
- imageProps.style.resizeMode = 'stretch';
204
+ imageProps.resizeMode = 'stretch';
205
205
  dimensions = {
206
206
  width: isPercent(width) ? width : +width,
207
207
  height: isPercent(height) ? height : +height
@@ -216,8 +216,9 @@ function backgroundSize(imageProps, preImageInfo, imageSize, layoutInfo) {
216
216
  }
217
217
  // background-image转换为source
218
218
  function backgroundImage(imageProps, preImageInfo) {
219
- if (preImageInfo.src) {
220
- imageProps.src = preImageInfo.src;
219
+ const src = preImageInfo.src;
220
+ if (src) {
221
+ imageProps.source = { uri: src };
221
222
  }
222
223
  }
223
224
  // 渐变的转换
@@ -241,8 +242,8 @@ function linearGradient(imageProps, preImageInfo, imageSize, layoutInfo) {
241
242
  const imageStyleToProps = (preImageInfo, imageSize, layoutInfo) => {
242
243
  // 初始化
243
244
  const imageProps = {
245
+ resizeMode: 'cover',
244
246
  style: {
245
- resizeMode: 'cover',
246
247
  position: 'absolute'
247
248
  // ...StyleSheet.absoluteFillObject
248
249
  },
@@ -430,7 +431,23 @@ function preParseImage(imageStyle) {
430
431
  function isDiagonalAngle(linearInfo) {
431
432
  return !!(linearInfo?.direction && diagonalAngleMap[linearInfo.direction]);
432
433
  }
433
- function wrapImage(imageStyle) {
434
+ function inheritStyle(innerStyle = {}) {
435
+ const { borderWidth, borderRadius } = innerStyle;
436
+ const borderStyles = ['borderRadius', 'borderTopLeftRadius', 'borderTopRightRadius', 'borderBottomRightRadius', 'borderBottomLeftRadius'];
437
+ return pickStyle(innerStyle, borderStyles, borderWidth && borderRadius
438
+ ? (key, val) => {
439
+ // 盒子内圆角borderWith与borderRadius的关系
440
+ // 当borderRadius 小于 当borderWith 内边框为直角
441
+ // 当borderRadius 大于等于 当borderWith 内边框为圆角
442
+ if (borderStyles.includes(key)) {
443
+ const borderVal = +val - borderWidth;
444
+ return borderVal > 0 ? borderVal : 0;
445
+ }
446
+ return val;
447
+ }
448
+ : undefined);
449
+ }
450
+ function wrapImage(imageStyle, innerStyle, enableFastImage) {
434
451
  // 预处理数据
435
452
  const preImageInfo = preParseImage(imageStyle);
436
453
  // 预解析
@@ -510,12 +527,12 @@ function wrapImage(imageStyle) {
510
527
  setShow(true);
511
528
  }
512
529
  };
513
- return <View key='backgroundImage' {...needLayout ? { onLayout } : null} style={{ ...StyleSheet.absoluteFillObject, overflow: 'hidden' }}>
530
+ return <View key='backgroundImage' {...needLayout ? { onLayout } : null} style={{ ...inheritStyle(innerStyle), ...StyleSheet.absoluteFillObject, overflow: 'hidden' }}>
514
531
  {show && type === 'linear' && <LinearGradient useAngle={true} {...imageStyleToProps(preImageInfo, sizeInfo.current, layoutInfo.current)}/>}
515
- {show && type === 'image' && <Image {...imageStyleToProps(preImageInfo, sizeInfo.current, layoutInfo.current)}/>}
532
+ {show && type === 'image' && (renderImage(imageStyleToProps(preImageInfo, sizeInfo.current, layoutInfo.current), enableFastImage))}
516
533
  </View>;
517
534
  }
518
- function wrapWithChildren(props, { hasVarDec, enableBackground, textStyle, backgroundStyle, varContext, textProps }) {
535
+ function wrapWithChildren(props, { hasVarDec, enableBackground, textStyle, backgroundStyle, varContext, textProps, innerStyle, enableFastImage }) {
519
536
  const children = wrapChildren(props, {
520
537
  hasVarDec,
521
538
  varContext,
@@ -523,13 +540,13 @@ function wrapWithChildren(props, { hasVarDec, enableBackground, textStyle, backg
523
540
  textProps
524
541
  });
525
542
  return [
526
- enableBackground ? wrapImage(backgroundStyle) : null,
543
+ enableBackground ? wrapImage(backgroundStyle, innerStyle, enableFastImage) : null,
527
544
  children
528
545
  ];
529
546
  }
530
547
  const _View = forwardRef((viewProps, ref) => {
531
548
  const { textProps, innerProps: props = {} } = splitProps(viewProps);
532
- let { style = {}, 'hover-style': hoverStyle, 'hover-start-time': hoverStartTime = 50, 'hover-stay-time': hoverStayTime = 400, 'enable-var': enableVar, 'external-var-context': externalVarContext, 'enable-background': enableBackground, 'enable-animation': enableAnimation, 'parent-font-size': parentFontSize, 'parent-width': parentWidth, 'parent-height': parentHeight, animation } = props;
549
+ let { style = {}, 'hover-style': hoverStyle, 'hover-start-time': hoverStartTime = 50, 'hover-stay-time': hoverStayTime = 400, 'enable-var': enableVar, 'external-var-context': externalVarContext, 'enable-background': enableBackground, 'enable-fast-image': enableFastImage, 'enable-animation': enableAnimation, 'parent-font-size': parentFontSize, 'parent-width': parentWidth, 'parent-height': parentHeight, animation } = props;
533
550
  const [isHover, setIsHover] = useState(false);
534
551
  // 默认样式
535
552
  const defaultStyle = {
@@ -595,9 +612,20 @@ const _View = forwardRef((viewProps, ref) => {
595
612
  }
596
613
  const { layoutRef, layoutStyle, layoutProps } = useLayout({ props, hasSelfPercent, setWidth, setHeight, nodeRef });
597
614
  const viewStyle = Object.assign({}, innerStyle, layoutStyle);
615
+ enableAnimation = enableAnimation || !!animation;
616
+ const enableAnimationRef = useRef(enableAnimation);
617
+ if (enableAnimationRef.current !== enableAnimation) {
618
+ throw new Error('[Mpx runtime error]: animation use should be stable in the component lifecycle, or you can set [enable-animation] with true.');
619
+ }
620
+ const finalStyle = enableAnimation
621
+ ? useAnimationHooks({
622
+ animation,
623
+ style: viewStyle
624
+ })
625
+ : viewStyle;
598
626
  const innerProps = useInnerProps(props, {
599
627
  ref: nodeRef,
600
- style: viewStyle,
628
+ style: finalStyle,
601
629
  ...layoutProps,
602
630
  ...(hoverStyle && {
603
631
  bindtouchstart: onTouchStart,
@@ -611,32 +639,23 @@ const _View = forwardRef((viewProps, ref) => {
611
639
  ], {
612
640
  layoutRef
613
641
  });
614
- enableAnimation = enableAnimation || !!animation;
615
- const enableAnimationRef = useRef(enableAnimation);
616
- if (enableAnimationRef.current !== enableAnimation) {
617
- throw new Error('[Mpx runtime error]: animation use should be stable in the component lifecycle, or you can set [enable-animation] with true.');
618
- }
619
- const finalStyle = enableAnimation
620
- ? useAnimationHooks({
621
- animation,
622
- style: viewStyle
623
- })
624
- : viewStyle;
625
642
  const childNode = wrapWithChildren(props, {
626
643
  hasVarDec,
627
644
  enableBackground: enableBackgroundRef.current,
628
645
  textStyle,
629
646
  backgroundStyle,
630
647
  varContext: varContextRef.current,
631
- textProps
648
+ textProps,
649
+ innerStyle,
650
+ enableFastImage
632
651
  });
633
- return animation?.actions?.length
634
- ? (<Animated.View {...innerProps} style={finalStyle}>
652
+ return enableAnimation
653
+ ? (<Animated.View {...innerProps}>
635
654
  {childNode}
636
655
  </Animated.View>)
637
656
  : (<View {...innerProps}>
638
657
  {childNode}
639
658
  </View>);
640
659
  });
641
- _View.displayName = 'mpx-view';
660
+ _View.displayName = 'MpxView';
642
661
  export default _View;
@@ -1,15 +1,19 @@
1
- import { forwardRef, useEffect, useRef } from 'react';
1
+ import { forwardRef, useEffect, useRef, useContext, useMemo } from 'react';
2
2
  import { noop, warn } from '@mpxjs/utils';
3
3
  import { Portal } from '@ant-design/react-native';
4
4
  import { getCustomEvent } from './getInnerListeners';
5
5
  import { promisify, redirectTo, navigateTo, navigateBack, reLaunch, switchTab } from '@mpxjs/api-proxy';
6
6
  import { WebView } from 'react-native-webview';
7
7
  import useNodesRef from './useNodesRef';
8
+ import { getCurrentPage } from './utils';
9
+ import { RouteContext } from './context';
8
10
  const _WebView = forwardRef((props, ref) => {
9
11
  const { src = '', bindmessage = noop, bindload = noop, binderror = noop } = props;
10
12
  if (props.style) {
11
13
  warn('The web-view component does not support the style prop.');
12
14
  }
15
+ const pageId = useContext(RouteContext);
16
+ const currentPage = useMemo(() => getCurrentPage(pageId), [pageId]);
13
17
  const defaultWebViewStyle = {
14
18
  position: 'absolute',
15
19
  left: 0,
@@ -21,16 +25,21 @@ const _WebView = forwardRef((props, ref) => {
21
25
  useNodesRef(props, ref, webViewRef, {
22
26
  defaultStyle: defaultWebViewStyle
23
27
  });
24
- const _messageList = [];
28
+ const _messageList = useRef([]);
25
29
  const handleUnload = () => {
26
30
  // 这里是 WebView 销毁前执行的逻辑
27
31
  bindmessage(getCustomEvent('messsage', {}, {
28
32
  detail: {
29
- data: _messageList
33
+ data: _messageList.current
30
34
  },
31
35
  layoutRef: webViewRef
32
36
  }));
33
37
  };
38
+ useEffect(() => {
39
+ if (currentPage) {
40
+ currentPage.__webViewUrl = src;
41
+ }
42
+ }, [src, currentPage]);
34
43
  useEffect(() => {
35
44
  // 组件卸载时执行
36
45
  return () => {
@@ -57,6 +66,11 @@ const _WebView = forwardRef((props, ref) => {
57
66
  };
58
67
  binderror(result);
59
68
  };
69
+ const _changeUrl = function (navState) {
70
+ if (currentPage) {
71
+ currentPage.__webViewUrl = navState.url;
72
+ }
73
+ };
60
74
  const _message = function (res) {
61
75
  let data = {};
62
76
  let asyncCallback;
@@ -73,7 +87,7 @@ const _WebView = forwardRef((props, ref) => {
73
87
  const postData = data.payload || {};
74
88
  switch (data.type) {
75
89
  case 'postMessage':
76
- _messageList.push(postData.data);
90
+ _messageList.current.push(postData.data);
77
91
  asyncCallback = Promise.resolve({
78
92
  errMsg: 'invokeWebappApi:ok'
79
93
  });
@@ -106,8 +120,8 @@ const _WebView = forwardRef((props, ref) => {
106
120
  });
107
121
  };
108
122
  return (<Portal>
109
- <WebView style={defaultWebViewStyle} source={{ uri: src }} ref={webViewRef} onLoad={_load} onError={_error} onMessage={_message} javaScriptEnabled={true}></WebView>
123
+ <WebView style={defaultWebViewStyle} source={{ uri: src }} ref={webViewRef} onLoad={_load} onError={_error} onMessage={_message} onNavigationStateChange={_changeUrl} javaScriptEnabled={true}></WebView>
110
124
  </Portal>);
111
125
  });
112
- _WebView.displayName = 'mpx-web-view';
126
+ _WebView.displayName = 'MpxWebview';
113
127
  export default _WebView;
@@ -0,0 +1,75 @@
1
+ /**
2
+ * Borrowed from open-source code: https://github.com/quidone/react-native-wheel-picker
3
+ * Special thanks to the authors for their contribution to the open-source community.
4
+ */
5
+ export const degToRad = (deg) => (Math.PI * deg) / 180;
6
+ // Calculates the height of the element after rotating it relative to the user's screen.
7
+ const calcHeight = (degree, itemHeight) => itemHeight * Math.cos(degToRad(degree));
8
+ export const calcPickerHeight = (faces, itemHeight) => {
9
+ if (faces.length === 7) {
10
+ return itemHeight * 5;
11
+ }
12
+ return faces.reduce((r, v) => r + calcHeight(Math.abs(v.deg), itemHeight), 0);
13
+ };
14
+ export const createFaces = (itemHeight, visibleCount) => {
15
+ // e.g [30, 60, 90]
16
+ const getDegreesRelativeCenter = () => {
17
+ const maxStep = Math.trunc((visibleCount + 2) / 2); // + 2 because there are 2 more faces at 90 degrees
18
+ const stepDegree = 90 / maxStep;
19
+ const result = [];
20
+ for (let i = 1; i <= maxStep; i++) {
21
+ result.push(i * stepDegree);
22
+ }
23
+ return result;
24
+ };
25
+ const getScreenHeightsAndOffsets = (degrees) => {
26
+ const screenHeights = degrees.map((deg) => calcHeight(deg, itemHeight));
27
+ const freeSpaces = screenHeights.map((screenHeight) => itemHeight - screenHeight);
28
+ const offsets = freeSpaces.map((freeSpace, index) => {
29
+ let offset = freeSpace / 2;
30
+ for (let i = 0; i < index; i++) {
31
+ offset += freeSpaces[i];
32
+ }
33
+ return offset;
34
+ });
35
+ return [screenHeights, offsets];
36
+ };
37
+ const getOpacity = (index) => {
38
+ const map = {
39
+ 0: 0,
40
+ 1: 0.2,
41
+ 2: 0.35,
42
+ 3: 0.45,
43
+ 4: 0.5
44
+ };
45
+ return map[index] ?? Math.min(1, map[4] + index * 0.5);
46
+ };
47
+ const degrees = getDegreesRelativeCenter();
48
+ const [screenHeight, offsets] = getScreenHeightsAndOffsets(degrees);
49
+ return [
50
+ // top items
51
+ ...degrees
52
+ .map((degree, index) => {
53
+ return {
54
+ index: -1 * (index + 1),
55
+ deg: degree,
56
+ opacity: getOpacity(degrees.length - 1 - index),
57
+ offsetY: -1 * offsets[index],
58
+ screenHeight: screenHeight[index]
59
+ };
60
+ })
61
+ .reverse(),
62
+ // center item
63
+ { index: 0, deg: 0, opacity: 1, offsetY: 0, screenHeight: itemHeight },
64
+ // bottom items
65
+ ...degrees.map((degree, index) => {
66
+ return {
67
+ index: index + 1,
68
+ deg: -1 * degree,
69
+ opacity: getOpacity(degrees.length - 1 - index),
70
+ offsetY: offsets[index],
71
+ screenHeight: screenHeight[index]
72
+ };
73
+ })
74
+ ];
75
+ };
@@ -0,0 +1,21 @@
1
+ import React from 'react';
2
+ import { StyleSheet, View } from 'react-native';
3
+ const Overlay = ({ itemHeight, overlayItemStyle, overlayContainerStyle }) => {
4
+ return (<View style={[styles.overlayContainer, overlayContainerStyle]} pointerEvents={'none'}>
5
+ <View style={[styles.selection, { height: itemHeight }, overlayItemStyle]}/>
6
+ </View>);
7
+ };
8
+ const styles = StyleSheet.create({
9
+ overlayContainer: {
10
+ ...StyleSheet.absoluteFillObject,
11
+ justifyContent: 'center',
12
+ alignItems: 'center'
13
+ },
14
+ selection: {
15
+ borderTopWidth: 1,
16
+ borderBottomWidth: 1,
17
+ borderColor: 'rgba(0, 0, 0, 0.05)',
18
+ alignSelf: 'stretch'
19
+ }
20
+ });
21
+ export default React.memo(Overlay);