@mpxjs/webpack-plugin 2.9.69 → 2.9.70

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 (111) hide show
  1. package/lib/parser.js +1 -1
  2. package/lib/platform/json/wx/index.js +21 -8
  3. package/lib/platform/style/wx/index.js +51 -54
  4. package/lib/platform/template/wx/component-config/fix-component-name.js +15 -12
  5. package/lib/platform/template/wx/component-config/index.js +1 -1
  6. package/lib/platform/template/wx/component-config/input.js +1 -1
  7. package/lib/platform/template/wx/component-config/rich-text.js +8 -0
  8. package/lib/platform/template/wx/component-config/swiper.js +1 -1
  9. package/lib/platform/template/wx/component-config/textarea.js +1 -1
  10. package/lib/platform/template/wx/component-config/unsupported.js +1 -1
  11. package/lib/react/processTemplate.js +3 -0
  12. package/lib/runtime/components/react/context.ts +4 -0
  13. package/lib/runtime/components/react/dist/context.js +1 -0
  14. package/lib/runtime/components/react/dist/event.config.js +24 -24
  15. package/lib/runtime/components/react/dist/getInnerListeners.js +183 -166
  16. package/lib/runtime/components/react/dist/mpx-button.jsx +35 -42
  17. package/lib/runtime/components/react/dist/mpx-canvas/html.js +2 -4
  18. package/lib/runtime/components/react/dist/mpx-canvas/index.jsx +35 -13
  19. package/lib/runtime/components/react/dist/mpx-checkbox-group.jsx +13 -19
  20. package/lib/runtime/components/react/dist/mpx-checkbox.jsx +29 -38
  21. package/lib/runtime/components/react/dist/mpx-form.jsx +16 -19
  22. package/lib/runtime/components/react/dist/mpx-icon.jsx +8 -16
  23. package/lib/runtime/components/react/dist/mpx-image.jsx +291 -0
  24. package/lib/runtime/components/react/dist/mpx-input.jsx +54 -27
  25. package/lib/runtime/components/react/dist/mpx-label.jsx +15 -22
  26. package/lib/runtime/components/react/dist/mpx-movable-area.jsx +13 -16
  27. package/lib/runtime/components/react/dist/mpx-movable-view.jsx +13 -13
  28. package/lib/runtime/components/react/dist/mpx-navigator.jsx +2 -4
  29. package/lib/runtime/components/react/dist/mpx-picker/date.jsx +6 -2
  30. package/lib/runtime/components/react/dist/mpx-picker/index.jsx +5 -3
  31. package/lib/runtime/components/react/dist/mpx-picker/multiSelector.jsx +6 -2
  32. package/lib/runtime/components/react/dist/mpx-picker/region.jsx +6 -2
  33. package/lib/runtime/components/react/dist/mpx-picker/selector.jsx +6 -2
  34. package/lib/runtime/components/react/dist/mpx-picker/time.jsx +10 -15
  35. package/lib/runtime/components/react/dist/mpx-picker-view-column.jsx +3 -1
  36. package/lib/runtime/components/react/dist/mpx-picker-view.jsx +5 -3
  37. package/lib/runtime/components/react/dist/mpx-radio-group.jsx +11 -19
  38. package/lib/runtime/components/react/dist/mpx-radio.jsx +27 -42
  39. package/lib/runtime/components/react/dist/mpx-rich-text/html.js +39 -0
  40. package/lib/runtime/components/react/dist/mpx-rich-text/index.jsx +63 -0
  41. package/lib/runtime/components/react/dist/mpx-root-portal.jsx +6 -4
  42. package/lib/runtime/components/react/dist/mpx-scroll-view.jsx +47 -41
  43. package/lib/runtime/components/react/dist/mpx-simple-text.jsx +11 -0
  44. package/lib/runtime/components/react/dist/mpx-swiper/carouse.jsx +4 -2
  45. package/lib/runtime/components/react/dist/mpx-swiper-item.jsx +4 -2
  46. package/lib/runtime/components/react/dist/mpx-switch.jsx +20 -10
  47. package/lib/runtime/components/react/dist/mpx-text.jsx +11 -10
  48. package/lib/runtime/components/react/dist/mpx-textarea.jsx +8 -3
  49. package/lib/runtime/components/react/dist/mpx-view.jsx +34 -46
  50. package/lib/runtime/components/react/dist/mpx-web-view.jsx +105 -42
  51. package/lib/runtime/components/react/dist/useAnimationHooks.js +35 -10
  52. package/lib/runtime/components/react/dist/utils.jsx +107 -82
  53. package/lib/runtime/components/react/event.config.ts +25 -26
  54. package/lib/runtime/components/react/getInnerListeners.ts +238 -188
  55. package/lib/runtime/components/react/mpx-button.tsx +64 -50
  56. package/lib/runtime/components/react/mpx-canvas/html.ts +2 -4
  57. package/lib/runtime/components/react/mpx-canvas/index.tsx +46 -48
  58. package/lib/runtime/components/react/mpx-checkbox-group.tsx +28 -25
  59. package/lib/runtime/components/react/mpx-checkbox.tsx +48 -49
  60. package/lib/runtime/components/react/mpx-form.tsx +25 -28
  61. package/lib/runtime/components/react/mpx-icon.tsx +12 -17
  62. package/lib/runtime/components/react/mpx-image.tsx +436 -0
  63. package/lib/runtime/components/react/mpx-input.tsx +77 -57
  64. package/lib/runtime/components/react/mpx-label.tsx +26 -27
  65. package/lib/runtime/components/react/mpx-movable-area.tsx +18 -23
  66. package/lib/runtime/components/react/mpx-movable-view.tsx +21 -25
  67. package/lib/runtime/components/react/mpx-navigator.tsx +2 -8
  68. package/lib/runtime/components/react/mpx-picker/date.tsx +5 -2
  69. package/lib/runtime/components/react/mpx-picker/index.tsx +3 -2
  70. package/lib/runtime/components/react/mpx-picker/multiSelector.tsx +5 -2
  71. package/lib/runtime/components/react/mpx-picker/region.tsx +5 -2
  72. package/lib/runtime/components/react/mpx-picker/selector.tsx +5 -2
  73. package/lib/runtime/components/react/mpx-picker/time.tsx +10 -15
  74. package/lib/runtime/components/react/mpx-picker/type.ts +48 -43
  75. package/lib/runtime/components/react/mpx-picker-view-column.tsx +4 -1
  76. package/lib/runtime/components/react/mpx-picker-view.tsx +7 -1
  77. package/lib/runtime/components/react/mpx-radio-group.tsx +24 -27
  78. package/lib/runtime/components/react/mpx-radio.tsx +45 -54
  79. package/lib/runtime/components/react/mpx-rich-text/html.ts +40 -0
  80. package/lib/runtime/components/react/mpx-rich-text/index.tsx +121 -0
  81. package/lib/runtime/components/react/mpx-root-portal.tsx +3 -5
  82. package/lib/runtime/components/react/mpx-scroll-view.tsx +72 -71
  83. package/lib/runtime/components/react/mpx-simple-text.tsx +18 -0
  84. package/lib/runtime/components/react/mpx-swiper/carouse.tsx +4 -2
  85. package/lib/runtime/components/react/mpx-swiper-item.tsx +3 -2
  86. package/lib/runtime/components/react/mpx-switch.tsx +29 -23
  87. package/lib/runtime/components/react/mpx-text.tsx +14 -18
  88. package/lib/runtime/components/react/mpx-textarea.tsx +11 -10
  89. package/lib/runtime/components/react/mpx-view.tsx +55 -65
  90. package/lib/runtime/components/react/mpx-web-view.tsx +108 -63
  91. package/lib/runtime/components/react/types/global.d.ts +3 -17
  92. package/lib/runtime/components/react/useAnimationHooks.ts +36 -12
  93. package/lib/runtime/components/react/utils.tsx +113 -82
  94. package/lib/runtime/components/web/getInnerListeners.js +6 -6
  95. package/lib/runtime/components/web/mpx-movable-view.vue +334 -344
  96. package/lib/runtime/components/web/mpx-picker-view-column.vue +75 -75
  97. package/lib/runtime/components/web/mpx-picker.vue +382 -385
  98. package/lib/runtime/components/web/mpx-web-view.vue +175 -161
  99. package/lib/runtime/optionProcessor.js +7 -38
  100. package/lib/runtime/utils.js +2 -0
  101. package/lib/style-compiler/plugins/scope-id.js +30 -2
  102. package/lib/template-compiler/bind-this.js +7 -2
  103. package/lib/template-compiler/compiler.js +77 -46
  104. package/lib/template-compiler/gen-node-react.js +2 -2
  105. package/lib/utils/pre-process-json.js +9 -5
  106. package/package.json +5 -4
  107. package/lib/runtime/components/react/dist/mpx-image/index.jsx +0 -226
  108. package/lib/runtime/components/react/dist/mpx-image/svg.jsx +0 -7
  109. package/lib/runtime/components/react/mpx-image/index.tsx +0 -345
  110. package/lib/runtime/components/react/mpx-image/svg.tsx +0 -22
  111. package/lib/runtime/components/web/event.js +0 -105
@@ -5,12 +5,13 @@
5
5
  * ✔ hover-stay-time
6
6
  */
7
7
  import { View, StyleSheet, Image } from 'react-native';
8
- import { useRef, useState, useEffect, forwardRef } from 'react';
8
+ import { useRef, useState, useEffect, forwardRef, createElement } from 'react';
9
9
  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, renderImage, pickStyle } from './utils';
13
+ import { parseUrl, PERCENT_REGEX, splitStyle, splitProps, useTransformStyle, wrapChildren, useLayout, renderImage, pickStyle, extendObject } from './utils';
14
+ import { error } from '@mpxjs/utils';
14
15
  import LinearGradient from 'react-native-linear-gradient';
15
16
  const linearMap = new Map([
16
17
  ['top', 0],
@@ -148,10 +149,7 @@ function backgroundPosition(imageProps, preImageInfo, imageSize, layoutInfo) {
148
149
  style[key] = val;
149
150
  }
150
151
  }
151
- imageProps.style = {
152
- ...imageProps.style,
153
- ...style
154
- };
152
+ extendObject(imageProps.style, style);
155
153
  }
156
154
  // background-size 转换
157
155
  function backgroundSize(imageProps, preImageInfo, imageSize, layoutInfo) {
@@ -209,10 +207,7 @@ function backgroundSize(imageProps, preImageInfo, imageSize, layoutInfo) {
209
207
  }
210
208
  }
211
209
  // 样式合并
212
- imageProps.style = {
213
- ...imageProps.style,
214
- ...dimensions
215
- };
210
+ extendObject(imageProps.style, dimensions);
216
211
  }
217
212
  // background-image转换为source
218
213
  function backgroundImage(imageProps, preImageInfo) {
@@ -385,10 +380,9 @@ function parseLinearGradient(text) {
385
380
  !isNaN(numberVal) && locations.push(numberVal);
386
381
  return prev;
387
382
  }, { colors: [], locations: [] });
388
- return {
389
- ...linearInfo,
383
+ return extendObject({}, linearInfo, {
390
384
  direction: direction.trim()
391
- };
385
+ });
392
386
  }
393
387
  function parseBgImage(text) {
394
388
  if (!text)
@@ -447,7 +441,7 @@ function inheritStyle(innerStyle = {}) {
447
441
  }
448
442
  : undefined);
449
443
  }
450
- function wrapImage(imageStyle, innerStyle, enableFastImage) {
444
+ function useWrapImage(imageStyle, innerStyle, enableFastImage) {
451
445
  // 预处理数据
452
446
  const preImageInfo = preParseImage(imageStyle);
453
447
  // 预解析
@@ -540,7 +534,8 @@ function wrapWithChildren(props, { hasVarDec, enableBackground, textStyle, backg
540
534
  textProps
541
535
  });
542
536
  return [
543
- enableBackground ? wrapImage(backgroundStyle, innerStyle, enableFastImage) : null,
537
+ // eslint-disable-next-line react-hooks/rules-of-hooks
538
+ enableBackground ? useWrapImage(backgroundStyle, innerStyle, enableFastImage) : null,
544
539
  children
545
540
  ];
546
541
  }
@@ -549,20 +544,15 @@ const _View = forwardRef((viewProps, ref) => {
549
544
  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;
550
545
  const [isHover, setIsHover] = useState(false);
551
546
  // 默认样式
552
- const defaultStyle = {
553
- // flex 布局相关的默认样式
554
- ...style.display === 'flex' && {
547
+ const defaultStyle = style.display === 'flex'
548
+ ? {
555
549
  flexDirection: 'row',
556
550
  flexBasis: 'auto',
557
551
  flexShrink: 1,
558
552
  flexWrap: 'nowrap'
559
553
  }
560
- };
561
- const styleObj = {
562
- ...defaultStyle,
563
- ...style,
564
- ...(isHover ? hoverStyle : null)
565
- };
554
+ : {};
555
+ const styleObj = extendObject({}, defaultStyle, style, isHover ? hoverStyle : {});
566
556
  const { normalStyle, hasSelfPercent, hasVarDec, varContextRef, setWidth, setHeight } = useTransformStyle(styleObj, {
567
557
  enableVar,
568
558
  externalVarContext,
@@ -570,15 +560,15 @@ const _View = forwardRef((viewProps, ref) => {
570
560
  parentWidth,
571
561
  parentHeight
572
562
  });
573
- const { textStyle, backgroundStyle, innerStyle } = splitStyle(normalStyle);
563
+ const { textStyle, backgroundStyle, innerStyle = {} } = splitStyle(normalStyle);
574
564
  enableBackground = enableBackground || !!backgroundStyle;
575
565
  const enableBackgroundRef = useRef(enableBackground);
576
566
  if (enableBackgroundRef.current !== enableBackground) {
577
- throw new Error('[Mpx runtime error]: background use should be stable in the component lifecycle, or you can set [enable-background] with true.');
567
+ error('[Mpx runtime error]: background use should be stable in the component lifecycle, or you can set [enable-background] with true.');
578
568
  }
579
569
  const nodeRef = useRef(null);
580
570
  useNodesRef(props, ref, nodeRef, {
581
- defaultStyle
571
+ style: normalStyle
582
572
  });
583
573
  const dataRef = useRef({});
584
574
  useEffect(() => {
@@ -611,27 +601,29 @@ const _View = forwardRef((viewProps, ref) => {
611
601
  setStayTimer();
612
602
  }
613
603
  const { layoutRef, layoutStyle, layoutProps } = useLayout({ props, hasSelfPercent, setWidth, setHeight, nodeRef });
614
- const viewStyle = Object.assign({}, innerStyle, layoutStyle);
604
+ const viewStyle = extendObject({}, innerStyle, layoutStyle);
615
605
  enableAnimation = enableAnimation || !!animation;
616
606
  const enableAnimationRef = useRef(enableAnimation);
617
607
  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.');
608
+ error('[Mpx runtime error]: animation use should be stable in the component lifecycle, or you can set [enable-animation] with true.');
619
609
  }
620
- const finalStyle = enableAnimation
621
- ? useAnimationHooks({
622
- animation,
623
- style: viewStyle
624
- })
610
+ const finalStyle = enableAnimationRef.current
611
+ ? [viewStyle,
612
+ // eslint-disable-next-line react-hooks/rules-of-hooks
613
+ useAnimationHooks({
614
+ animation,
615
+ style: viewStyle
616
+ })]
625
617
  : viewStyle;
626
- const innerProps = useInnerProps(props, {
618
+ const innerProps = useInnerProps(props, extendObject({
627
619
  ref: nodeRef,
628
- style: finalStyle,
629
- ...layoutProps,
630
- ...(hoverStyle && {
620
+ style: finalStyle
621
+ }, layoutProps, hoverStyle
622
+ ? {
631
623
  bindtouchstart: onTouchStart,
632
624
  bindtouchend: onTouchEnd
633
- })
634
- }, [
625
+ }
626
+ : {}), [
635
627
  'hover-start-time',
636
628
  'hover-stay-time',
637
629
  'hover-style',
@@ -650,12 +642,8 @@ const _View = forwardRef((viewProps, ref) => {
650
642
  enableFastImage
651
643
  });
652
644
  return enableAnimation
653
- ? (<Animated.View {...innerProps}>
654
- {childNode}
655
- </Animated.View>)
656
- : (<View {...innerProps}>
657
- {childNode}
658
- </View>);
645
+ ? createElement(Animated.View, innerProps, childNode)
646
+ : createElement(View, innerProps, childNode);
659
647
  });
660
648
  _View.displayName = 'MpxView';
661
649
  export default _View;
@@ -1,19 +1,21 @@
1
- import { forwardRef, useEffect, useRef, useContext, useMemo } from 'react';
2
- import { noop, warn } from '@mpxjs/utils';
1
+ import { forwardRef, useRef, useContext, useMemo, createElement } from 'react';
2
+ import { warn, getFocusedNavigation, isFunction } 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';
8
+ import { getCurrentPage, extendObject } from './utils';
9
9
  import { RouteContext } from './context';
10
10
  const _WebView = forwardRef((props, ref) => {
11
- const { src = '', bindmessage = noop, bindload = noop, binderror = noop } = props;
11
+ const { src, bindmessage, bindload, binderror } = props;
12
+ const mpx = global.__mpx;
12
13
  if (props.style) {
13
14
  warn('The web-view component does not support the style prop.');
14
15
  }
15
16
  const pageId = useContext(RouteContext);
16
17
  const currentPage = useMemo(() => getCurrentPage(pageId), [pageId]);
18
+ const webViewRef = useRef(null);
17
19
  const defaultWebViewStyle = {
18
20
  position: 'absolute',
19
21
  left: 0,
@@ -21,31 +23,12 @@ const _WebView = forwardRef((props, ref) => {
21
23
  top: 0,
22
24
  bottom: 0
23
25
  };
24
- const webViewRef = useRef(null);
25
26
  useNodesRef(props, ref, webViewRef, {
26
- defaultStyle: defaultWebViewStyle
27
+ style: defaultWebViewStyle
27
28
  });
28
- const _messageList = useRef([]);
29
- const handleUnload = () => {
30
- // 这里是 WebView 销毁前执行的逻辑
31
- bindmessage(getCustomEvent('messsage', {}, {
32
- detail: {
33
- data: _messageList.current
34
- },
35
- layoutRef: webViewRef
36
- }));
37
- };
38
- useEffect(() => {
39
- if (currentPage) {
40
- currentPage.__webViewUrl = src;
41
- }
42
- }, [src, currentPage]);
43
- useEffect(() => {
44
- // 组件卸载时执行
45
- return () => {
46
- handleUnload();
47
- };
48
- }, []);
29
+ if (!src) {
30
+ return null;
31
+ }
49
32
  const _load = function (res) {
50
33
  const result = {
51
34
  type: 'load',
@@ -66,8 +49,33 @@ const _WebView = forwardRef((props, ref) => {
66
49
  };
67
50
  binderror(result);
68
51
  };
52
+ const injectedJavaScript = `
53
+ if (window.ReactNativeWebView && window.ReactNativeWebView.postMessage) {
54
+ var _documentTitle = document.title;
55
+ window.ReactNativeWebView.postMessage(JSON.stringify({
56
+ type: 'setTitle',
57
+ payload: {
58
+ _documentTitle: _documentTitle
59
+ }
60
+ }))
61
+ Object.defineProperty(document, 'title', {
62
+ set (val) {
63
+ _documentTitle = val
64
+ window.ReactNativeWebView.postMessage(JSON.stringify({
65
+ type: 'setTitle',
66
+ payload: {
67
+ _documentTitle: _documentTitle
68
+ }
69
+ }))
70
+ },
71
+ get () {
72
+ return _documentTitle
73
+ }
74
+ });
75
+ }
76
+ `;
69
77
  const _changeUrl = function (navState) {
70
- if (currentPage) {
78
+ if (navState.navigationType) { // navigationType这个事件在页面开始加载时和页面加载完成时都会被触发所以判断这个避免其他无效触发执行该逻辑
71
79
  currentPage.__webViewUrl = navState.url;
72
80
  }
73
81
  };
@@ -81,47 +89,102 @@ const _WebView = forwardRef((props, ref) => {
81
89
  data = JSON.parse(nativeEventData);
82
90
  }
83
91
  }
84
- catch (e) {
85
- data = {};
86
- }
92
+ catch (e) { }
93
+ const args = data.args;
87
94
  const postData = data.payload || {};
88
- switch (data.type) {
95
+ const params = Array.isArray(args) ? args : [postData];
96
+ const type = data.type;
97
+ switch (type) {
98
+ case 'setTitle':
99
+ { // case下不允许直接声明,包个块解决该问题
100
+ const title = postData._documentTitle;
101
+ if (title) {
102
+ const navigation = getFocusedNavigation();
103
+ navigation && navigation.setOptions({ title });
104
+ }
105
+ }
106
+ break;
89
107
  case 'postMessage':
90
- _messageList.current.push(postData.data);
108
+ bindmessage && bindmessage(getCustomEvent('messsage', {}, {
109
+ detail: {
110
+ data: params[0]?.data
111
+ }
112
+ }));
91
113
  asyncCallback = Promise.resolve({
92
114
  errMsg: 'invokeWebappApi:ok'
93
115
  });
94
116
  break;
95
117
  case 'navigateTo':
96
- asyncCallback = navObj.navigateTo(postData);
118
+ asyncCallback = navObj.navigateTo(...params);
97
119
  break;
98
120
  case 'navigateBack':
99
- asyncCallback = navObj.navigateBack(postData);
121
+ asyncCallback = navObj.navigateBack(...params);
100
122
  break;
101
123
  case 'redirectTo':
102
- asyncCallback = navObj.redirectTo(postData);
124
+ asyncCallback = navObj.redirectTo(...params);
103
125
  break;
104
126
  case 'switchTab':
105
- asyncCallback = navObj.switchTab(postData);
127
+ asyncCallback = navObj.switchTab(...params);
106
128
  break;
107
129
  case 'reLaunch':
108
- asyncCallback = navObj.reLaunch(postData);
130
+ asyncCallback = navObj.reLaunch(...params);
131
+ break;
132
+ default:
133
+ if (type) {
134
+ const implement = mpx.config.webviewConfig.apiImplementations && mpx.config.webviewConfig.apiImplementations[type];
135
+ if (isFunction(implement)) {
136
+ asyncCallback = Promise.resolve(implement(...params));
137
+ }
138
+ else {
139
+ /* eslint-disable prefer-promise-reject-errors */
140
+ asyncCallback = Promise.reject({
141
+ errMsg: `未在apiImplementations中配置${type}方法`
142
+ });
143
+ }
144
+ }
109
145
  break;
110
146
  }
111
147
  asyncCallback && asyncCallback.then((res) => {
112
148
  if (webViewRef.current?.postMessage) {
113
149
  const test = JSON.stringify({
114
- type: data.type,
150
+ type,
115
151
  callbackId: data.callbackId,
116
152
  result: res
117
153
  });
118
154
  webViewRef.current.postMessage(test);
119
155
  }
156
+ }).catch((error) => {
157
+ if (webViewRef.current?.postMessage) {
158
+ const test = JSON.stringify({
159
+ type,
160
+ callbackId: data.callbackId,
161
+ error
162
+ });
163
+ webViewRef.current.postMessage(test);
164
+ }
120
165
  });
121
166
  };
122
- return (<Portal>
123
- <WebView style={defaultWebViewStyle} source={{ uri: src }} ref={webViewRef} onLoad={_load} onError={_error} onMessage={_message} onNavigationStateChange={_changeUrl} javaScriptEnabled={true}></WebView>
124
- </Portal>);
167
+ const events = {};
168
+ if (bindload) {
169
+ extendObject(events, {
170
+ onLoad: _load
171
+ });
172
+ }
173
+ if (binderror) {
174
+ extendObject(events, {
175
+ onError: _error
176
+ });
177
+ }
178
+ extendObject(events, {
179
+ onMessage: _message
180
+ });
181
+ return createElement(Portal, null, createElement(WebView, extendObject({
182
+ style: defaultWebViewStyle,
183
+ source: { uri: src },
184
+ ref: webViewRef,
185
+ javaScriptEnabled: true,
186
+ onNavigationStateChange: _changeUrl
187
+ }, events)));
125
188
  });
126
189
  _WebView.displayName = 'MpxWebview';
127
190
  export default _WebView;
@@ -47,12 +47,35 @@ const InitialValue = Object.assign({
47
47
  const TransformOrigin = 'transformOrigin';
48
48
  // transform
49
49
  const isTransform = (key) => Object.keys(TransformInitial).includes(key);
50
+ // 多value解析
51
+ const parseValues = (str, char = ' ') => {
52
+ let stack = 0;
53
+ let temp = '';
54
+ const result = [];
55
+ for (let i = 0; i < str.length; i++) {
56
+ if (str[i] === '(') {
57
+ stack++;
58
+ }
59
+ else if (str[i] === ')') {
60
+ stack--;
61
+ }
62
+ // 非括号内 或者 非分隔字符且非空
63
+ if (stack !== 0 || (str[i] !== char && str[i] !== ' ')) {
64
+ temp += str[i];
65
+ }
66
+ if ((stack === 0 && str[i] === char) || i === str.length - 1) {
67
+ result.push(temp);
68
+ temp = '';
69
+ }
70
+ }
71
+ return result;
72
+ };
50
73
  // parse string transform, eg: transform: 'rotateX(45deg) rotateZ(0.785398rad)'
51
74
  const parseTransform = (transformStr) => {
52
- const values = transformStr.trim().split(/\s+/);
75
+ const values = parseValues(transformStr);
53
76
  const transform = [];
54
77
  values.forEach(item => {
55
- const match = item.match(/([/\w]+)\(([^)]+)\)/);
78
+ const match = item.match(/([/\w]+)\((.+)\)/);
56
79
  if (match && match.length >= 3) {
57
80
  let key = match[1];
58
81
  const val = match[2];
@@ -73,7 +96,7 @@ const parseTransform = (transformStr) => {
73
96
  break;
74
97
  case 'matrix':
75
98
  case 'matrix3d':
76
- transform.push({ [key]: val.split(',').map(val => +val) });
99
+ transform.push({ [key]: parseValues(val, ',').map(val => +val) });
77
100
  break;
78
101
  case 'translate':
79
102
  case 'scale':
@@ -84,8 +107,8 @@ const parseTransform = (transformStr) => {
84
107
  {
85
108
  // 2 个以上的值处理
86
109
  key = key.replace('3d', '');
87
- const vals = val.split(',', key === 'rotate' ? 4 : 3);
88
- // scale(.5) === scaleX(.5) scaleY(.5) 这里处理一下
110
+ const vals = parseValues(val, ',').splice(0, key === 'rotate' ? 4 : 3);
111
+ // scale(.5) === scaleX(.5) scaleY(.5)
89
112
  if (vals.length === 1 && key === 'scale') {
90
113
  vals.push(vals[0]);
91
114
  }
@@ -183,11 +206,13 @@ export default function useAnimationHooks(props) {
183
206
  }
184
207
  // 添加每个key的多次step动画
185
208
  animatedKeys.forEach(key => {
186
- let toVal = (rules.get(key) || transform.get(key));
209
+ const ruleV = isTransform(key) ? transform.get(key) : rules.get(key);
187
210
  // key不存在,第一轮取shareValMap[key]value,非第一轮取上一轮的
188
- if (toVal === undefined) {
189
- toVal = index > 0 ? lastValueMap[key] : shareValMap[key].value;
190
- }
211
+ const toVal = ruleV !== undefined
212
+ ? ruleV
213
+ : index > 0
214
+ ? lastValueMap[key]
215
+ : shareValMap[key].value;
191
216
  const animation = getAnimation({ key, value: toVal }, { delay, duration, easing }, needSetCallback ? setTransformOrigin : undefined);
192
217
  needSetCallback = false;
193
218
  if (!sequence[key]) {
@@ -298,6 +323,6 @@ export default function useAnimationHooks(props) {
298
323
  styles[key] = shareValMap[key].value;
299
324
  }
300
325
  return styles;
301
- }, Object.assign({}, originalStyle));
326
+ }, {});
302
327
  });
303
328
  }