@mpxjs/webpack-plugin 2.9.69 → 2.9.70-alpha.0

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 (138) hide show
  1. package/README.md +1 -1
  2. package/lib/config.js +14 -0
  3. package/lib/dependencies/AddEntryDependency.js +24 -0
  4. package/lib/dependencies/ResolveDependency.js +5 -0
  5. package/lib/index.js +38 -7
  6. package/lib/json-compiler/helper.js +3 -3
  7. package/lib/loader.js +53 -0
  8. package/lib/platform/template/wx/component-config/button.js +14 -2
  9. package/lib/platform/template/wx/component-config/image.js +4 -0
  10. package/lib/platform/template/wx/component-config/input.js +5 -1
  11. package/lib/platform/template/wx/component-config/rich-text.js +4 -0
  12. package/lib/platform/template/wx/component-config/scroll-view.js +4 -0
  13. package/lib/platform/template/wx/component-config/swiper.js +1 -1
  14. package/lib/platform/template/wx/component-config/switch.js +4 -0
  15. package/lib/platform/template/wx/component-config/text.js +4 -0
  16. package/lib/platform/template/wx/component-config/textarea.js +6 -1
  17. package/lib/platform/template/wx/component-config/view.js +4 -0
  18. package/lib/platform/template/wx/index.js +127 -1
  19. package/lib/react/processTemplate.js +3 -0
  20. package/lib/resolve-loader.js +4 -1
  21. package/lib/runtime/components/react/context.ts +4 -0
  22. package/lib/runtime/components/react/dist/context.js +1 -0
  23. package/lib/runtime/components/react/dist/event.config.js +24 -24
  24. package/lib/runtime/components/react/dist/getInnerListeners.js +183 -165
  25. package/lib/runtime/components/react/dist/mpx-button.jsx +35 -42
  26. package/lib/runtime/components/react/dist/mpx-canvas/index.jsx +30 -12
  27. package/lib/runtime/components/react/dist/mpx-checkbox-group.jsx +13 -19
  28. package/lib/runtime/components/react/dist/mpx-checkbox.jsx +29 -38
  29. package/lib/runtime/components/react/dist/mpx-form.jsx +16 -19
  30. package/lib/runtime/components/react/dist/mpx-icon.jsx +8 -16
  31. package/lib/runtime/components/react/dist/mpx-image.jsx +291 -0
  32. package/lib/runtime/components/react/dist/mpx-input.jsx +54 -27
  33. package/lib/runtime/components/react/dist/mpx-label.jsx +15 -22
  34. package/lib/runtime/components/react/dist/mpx-movable-area.jsx +13 -16
  35. package/lib/runtime/components/react/dist/mpx-movable-view.jsx +13 -13
  36. package/lib/runtime/components/react/dist/mpx-navigator.jsx +2 -4
  37. package/lib/runtime/components/react/dist/mpx-picker/date.jsx +6 -2
  38. package/lib/runtime/components/react/dist/mpx-picker/index.jsx +5 -3
  39. package/lib/runtime/components/react/dist/mpx-picker/multiSelector.jsx +6 -2
  40. package/lib/runtime/components/react/dist/mpx-picker/region.jsx +6 -2
  41. package/lib/runtime/components/react/dist/mpx-picker/selector.jsx +6 -2
  42. package/lib/runtime/components/react/dist/mpx-picker/time.jsx +10 -15
  43. package/lib/runtime/components/react/dist/mpx-picker-view-column-item.jsx +39 -0
  44. package/lib/runtime/components/react/dist/mpx-picker-view-column.jsx +110 -97
  45. package/lib/runtime/components/react/dist/mpx-picker-view.jsx +32 -29
  46. package/lib/runtime/components/react/dist/mpx-radio-group.jsx +11 -19
  47. package/lib/runtime/components/react/dist/mpx-radio.jsx +27 -42
  48. package/lib/runtime/components/react/dist/mpx-rich-text/html.js +39 -0
  49. package/lib/runtime/components/react/dist/mpx-rich-text/index.jsx +63 -0
  50. package/lib/runtime/components/react/dist/mpx-root-portal.jsx +6 -4
  51. package/lib/runtime/components/react/dist/mpx-scroll-view.jsx +47 -41
  52. package/lib/runtime/components/react/dist/mpx-simple-text.jsx +11 -0
  53. package/lib/runtime/components/react/dist/mpx-swiper-item.jsx +4 -2
  54. package/lib/runtime/components/react/dist/mpx-swiper.jsx +606 -0
  55. package/lib/runtime/components/react/dist/mpx-switch.jsx +20 -10
  56. package/lib/runtime/components/react/dist/mpx-text.jsx +11 -10
  57. package/lib/runtime/components/react/dist/mpx-textarea.jsx +8 -3
  58. package/lib/runtime/components/react/dist/mpx-view.jsx +29 -44
  59. package/lib/runtime/components/react/dist/mpx-web-view.jsx +105 -42
  60. package/lib/runtime/components/react/dist/pickerFaces.js +12 -6
  61. package/lib/runtime/components/react/dist/pickerVIewContext.js +9 -0
  62. package/lib/runtime/components/react/dist/pickerViewMask.jsx +18 -0
  63. package/lib/runtime/components/react/dist/{pickerOverlay.jsx → pickerViewOverlay.jsx} +5 -3
  64. package/lib/runtime/components/react/dist/useAnimationHooks.js +35 -9
  65. package/lib/runtime/components/react/dist/utils.jsx +20 -24
  66. package/lib/runtime/components/react/getInnerListeners.ts +35 -28
  67. package/lib/runtime/components/react/mpx-button.tsx +55 -36
  68. package/lib/runtime/components/react/mpx-canvas/index.tsx +2 -2
  69. package/lib/runtime/components/react/mpx-checkbox-group.tsx +13 -12
  70. package/lib/runtime/components/react/mpx-checkbox.tsx +28 -28
  71. package/lib/runtime/components/react/mpx-form.tsx +10 -8
  72. package/lib/runtime/components/react/mpx-icon.tsx +10 -15
  73. package/lib/runtime/components/react/mpx-image.tsx +396 -0
  74. package/lib/runtime/components/react/mpx-input.tsx +61 -33
  75. package/lib/runtime/components/react/mpx-label.tsx +14 -13
  76. package/lib/runtime/components/react/mpx-movable-area.tsx +8 -7
  77. package/lib/runtime/components/react/mpx-movable-view.tsx +1 -1
  78. package/lib/runtime/components/react/mpx-picker/date.tsx +5 -2
  79. package/lib/runtime/components/react/mpx-picker/index.tsx +3 -2
  80. package/lib/runtime/components/react/mpx-picker/multiSelector.tsx +5 -2
  81. package/lib/runtime/components/react/mpx-picker/region.tsx +5 -2
  82. package/lib/runtime/components/react/mpx-picker/selector.tsx +5 -2
  83. package/lib/runtime/components/react/mpx-picker/time.tsx +10 -15
  84. package/lib/runtime/components/react/mpx-picker/type.ts +48 -43
  85. package/lib/runtime/components/react/mpx-picker-view-column.tsx +4 -1
  86. package/lib/runtime/components/react/mpx-picker-view.tsx +7 -1
  87. package/lib/runtime/components/react/mpx-radio-group.tsx +11 -12
  88. package/lib/runtime/components/react/mpx-radio.tsx +26 -29
  89. package/lib/runtime/components/react/mpx-scroll-view.tsx +32 -30
  90. package/lib/runtime/components/react/mpx-simple-text.tsx +18 -0
  91. package/lib/runtime/components/react/mpx-swiper/carouse.tsx +4 -2
  92. package/lib/runtime/components/react/mpx-swiper-item.tsx +3 -2
  93. package/lib/runtime/components/react/mpx-switch.tsx +10 -8
  94. package/lib/runtime/components/react/mpx-text.tsx +6 -2
  95. package/lib/runtime/components/react/mpx-view.tsx +37 -45
  96. package/lib/runtime/components/react/mpx-web-view.tsx +25 -15
  97. package/lib/runtime/components/react/types/global.d.ts +1 -16
  98. package/lib/runtime/components/react/utils.tsx +24 -24
  99. package/lib/runtime/components/tenon/getInnerListeners.js +334 -0
  100. package/lib/runtime/components/tenon/tenon-button.vue +309 -0
  101. package/lib/runtime/components/tenon/tenon-image.vue +66 -0
  102. package/lib/runtime/components/tenon/tenon-input.vue +171 -0
  103. package/lib/runtime/components/tenon/tenon-rich-text.vue +26 -0
  104. package/lib/runtime/components/tenon/tenon-scroll-view.vue +127 -0
  105. package/lib/runtime/components/tenon/tenon-switch.vue +96 -0
  106. package/lib/runtime/components/tenon/tenon-text.vue +70 -0
  107. package/lib/runtime/components/tenon/tenon-textarea.vue +86 -0
  108. package/lib/runtime/components/tenon/tenon-view.vue +93 -0
  109. package/lib/runtime/components/web/getInnerListeners.js +6 -6
  110. package/lib/runtime/components/web/mpx-movable-view.vue +334 -344
  111. package/lib/runtime/components/web/mpx-picker-view-column.vue +75 -75
  112. package/lib/runtime/components/web/mpx-picker.vue +382 -385
  113. package/lib/runtime/components/web/mpx-web-view.vue +162 -162
  114. package/lib/runtime/optionProcessor.js +7 -16
  115. package/lib/runtime/optionProcessor.tenon.js +84 -0
  116. package/lib/runtime/utils.js +2 -0
  117. package/lib/style-compiler/index.js +1 -1
  118. package/lib/style-compiler/plugins/hm.js +20 -0
  119. package/lib/template-compiler/bind-this.js +7 -2
  120. package/lib/template-compiler/compiler.js +67 -40
  121. package/lib/template-compiler/gen-node-react.js +2 -2
  122. package/lib/tenon/index.js +117 -0
  123. package/lib/tenon/processJSON.js +352 -0
  124. package/lib/tenon/processScript.js +203 -0
  125. package/lib/tenon/processStyles.js +21 -0
  126. package/lib/tenon/processTemplate.js +126 -0
  127. package/lib/tenon/script-helper.js +223 -0
  128. package/lib/utils/env.js +6 -1
  129. package/lib/utils/get-relative-path.js +25 -0
  130. package/package.json +7 -3
  131. package/LICENSE +0 -433
  132. package/lib/runtime/components/react/dist/mpx-image/index.jsx +0 -226
  133. package/lib/runtime/components/react/dist/mpx-image/svg.jsx +0 -7
  134. package/lib/runtime/components/react/dist/mpx-swiper/carouse.jsx +0 -478
  135. package/lib/runtime/components/react/dist/mpx-swiper/index.jsx +0 -68
  136. package/lib/runtime/components/react/dist/mpx-swiper/type.js +0 -1
  137. package/lib/runtime/components/react/mpx-image/index.tsx +0 -345
  138. package/lib/runtime/components/react/mpx-image/svg.tsx +0 -22
@@ -4,12 +4,12 @@
4
4
  * ✘ decode
5
5
  */
6
6
  import { Text } from 'react-native';
7
- import { useRef, forwardRef } from 'react';
7
+ import { useRef, forwardRef, createElement } from 'react';
8
8
  import useInnerProps from './getInnerListeners';
9
9
  import useNodesRef from './useNodesRef'; // 引入辅助函数
10
10
  import { useTransformStyle, wrapChildren } from './utils';
11
11
  const _Text = forwardRef((props, ref) => {
12
- const { style = {}, selectable, 'enable-var': enableVar, 'external-var-context': externalVarContext, 'user-select': userSelect, 'parent-font-size': parentFontSize, 'parent-width': parentWidth, 'parent-height': parentHeight } = props;
12
+ const { style = {}, allowFontScaling = false, selectable, 'enable-var': enableVar, 'external-var-context': externalVarContext, 'user-select': userSelect, 'parent-font-size': parentFontSize, 'parent-width': parentWidth, 'parent-height': parentHeight } = props;
13
13
  const layoutRef = useRef({});
14
14
  const { normalStyle, hasVarDec, varContextRef } = useTransformStyle(style, {
15
15
  enableVar,
@@ -19,22 +19,23 @@ const _Text = forwardRef((props, ref) => {
19
19
  parentHeight
20
20
  });
21
21
  const nodeRef = useRef(null);
22
- useNodesRef(props, ref, nodeRef);
22
+ useNodesRef(props, ref, nodeRef, {
23
+ style: normalStyle
24
+ });
23
25
  const innerProps = useInnerProps(props, {
24
26
  ref: nodeRef,
25
27
  style: normalStyle,
26
- selectable: !!selectable || !!userSelect
28
+ selectable: !!selectable || !!userSelect,
29
+ allowFontScaling
27
30
  }, [
28
31
  'user-select'
29
32
  ], {
30
33
  layoutRef
31
34
  });
32
- return (<Text {...innerProps}>
33
- {wrapChildren(props, {
34
- hasVarDec,
35
- varContext: varContextRef.current
36
- })}
37
- </Text>);
35
+ return createElement(Text, innerProps, wrapChildren(props, {
36
+ hasVarDec,
37
+ varContext: varContextRef.current
38
+ }));
38
39
  });
39
40
  _Text.displayName = 'MpxText';
40
41
  export default _Text;
@@ -9,10 +9,10 @@
9
9
  * ✘ show-confirm-bar
10
10
  * ✔ bindlinechange: No `heightRpx` info.
11
11
  */
12
- import { forwardRef } from 'react';
12
+ import { forwardRef, createElement } from 'react';
13
13
  import { Keyboard } from 'react-native';
14
14
  import Input from './mpx-input';
15
- import { omit } from './utils';
15
+ import { omit, extendObject } from './utils';
16
16
  const Textarea = forwardRef((props, ref) => {
17
17
  const restProps = omit(props, [
18
18
  'ref',
@@ -21,7 +21,12 @@ const Textarea = forwardRef((props, ref) => {
21
21
  'multiline',
22
22
  'confirm-hold'
23
23
  ]);
24
- return (<Input ref={ref} multiline confirm-type='next' bindblur={() => Keyboard.dismiss()} {...restProps}/>);
24
+ return createElement(Input, extendObject({
25
+ ref: ref,
26
+ multiline: true,
27
+ confirmType: 'next',
28
+ bindblur: () => Keyboard.dismiss()
29
+ }, restProps));
25
30
  });
26
31
  Textarea.displayName = 'MpxTextarea';
27
32
  export default Textarea;
@@ -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)
@@ -549,20 +543,15 @@ const _View = forwardRef((viewProps, ref) => {
549
543
  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
544
  const [isHover, setIsHover] = useState(false);
551
545
  // 默认样式
552
- const defaultStyle = {
553
- // flex 布局相关的默认样式
554
- ...style.display === 'flex' && {
546
+ const defaultStyle = style.display === 'flex'
547
+ ? {
555
548
  flexDirection: 'row',
556
549
  flexBasis: 'auto',
557
550
  flexShrink: 1,
558
551
  flexWrap: 'nowrap'
559
552
  }
560
- };
561
- const styleObj = {
562
- ...defaultStyle,
563
- ...style,
564
- ...(isHover ? hoverStyle : null)
565
- };
553
+ : {};
554
+ const styleObj = extendObject({}, defaultStyle, style, isHover ? hoverStyle : {});
566
555
  const { normalStyle, hasSelfPercent, hasVarDec, varContextRef, setWidth, setHeight } = useTransformStyle(styleObj, {
567
556
  enableVar,
568
557
  externalVarContext,
@@ -570,15 +559,15 @@ const _View = forwardRef((viewProps, ref) => {
570
559
  parentWidth,
571
560
  parentHeight
572
561
  });
573
- const { textStyle, backgroundStyle, innerStyle } = splitStyle(normalStyle);
562
+ const { textStyle, backgroundStyle, innerStyle = {} } = splitStyle(normalStyle);
574
563
  enableBackground = enableBackground || !!backgroundStyle;
575
564
  const enableBackgroundRef = useRef(enableBackground);
576
565
  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.');
566
+ error('[Mpx runtime error]: background use should be stable in the component lifecycle, or you can set [enable-background] with true.');
578
567
  }
579
568
  const nodeRef = useRef(null);
580
569
  useNodesRef(props, ref, nodeRef, {
581
- defaultStyle
570
+ style: normalStyle
582
571
  });
583
572
  const dataRef = useRef({});
584
573
  useEffect(() => {
@@ -611,27 +600,27 @@ const _View = forwardRef((viewProps, ref) => {
611
600
  setStayTimer();
612
601
  }
613
602
  const { layoutRef, layoutStyle, layoutProps } = useLayout({ props, hasSelfPercent, setWidth, setHeight, nodeRef });
614
- const viewStyle = Object.assign({}, innerStyle, layoutStyle);
603
+ const viewStyle = extendObject({}, innerStyle, layoutStyle);
615
604
  enableAnimation = enableAnimation || !!animation;
616
605
  const enableAnimationRef = useRef(enableAnimation);
617
606
  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.');
607
+ error('[Mpx runtime error]: animation use should be stable in the component lifecycle, or you can set [enable-animation] with true.');
619
608
  }
620
- const finalStyle = enableAnimation
621
- ? useAnimationHooks({
622
- animation,
623
- style: viewStyle
624
- })
609
+ const finalStyle = enableAnimationRef.current
610
+ ? [viewStyle, useAnimationHooks({
611
+ animation,
612
+ style: viewStyle
613
+ })]
625
614
  : viewStyle;
626
- const innerProps = useInnerProps(props, {
615
+ const innerProps = useInnerProps(props, extendObject({
627
616
  ref: nodeRef,
628
- style: finalStyle,
629
- ...layoutProps,
630
- ...(hoverStyle && {
617
+ style: finalStyle
618
+ }, layoutProps, hoverStyle
619
+ ? {
631
620
  bindtouchstart: onTouchStart,
632
621
  bindtouchend: onTouchEnd
633
- })
634
- }, [
622
+ }
623
+ : {}), [
635
624
  'hover-start-time',
636
625
  'hover-stay-time',
637
626
  'hover-style',
@@ -650,12 +639,8 @@ const _View = forwardRef((viewProps, ref) => {
650
639
  enableFastImage
651
640
  });
652
641
  return enableAnimation
653
- ? (<Animated.View {...innerProps}>
654
- {childNode}
655
- </Animated.View>)
656
- : (<View {...innerProps}>
657
- {childNode}
658
- </View>);
642
+ ? createElement(Animated.View, innerProps, childNode)
643
+ : createElement(View, innerProps, childNode);
659
644
  });
660
645
  _View.displayName = 'MpxView';
661
646
  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;
@@ -30,6 +30,9 @@ export const createFaces = (itemHeight, visibleCount) => {
30
30
  for (let i = 0; i < index; i++) {
31
31
  offset += freeSpaces[i];
32
32
  }
33
+ if (index === 0) {
34
+ offset *= 0.6;
35
+ }
33
36
  return offset;
34
37
  });
35
38
  return [screenHeights, offsets];
@@ -37,15 +40,16 @@ export const createFaces = (itemHeight, visibleCount) => {
37
40
  const getOpacity = (index) => {
38
41
  const map = {
39
42
  0: 0,
40
- 1: 0.2,
41
- 2: 0.35,
42
- 3: 0.45,
43
- 4: 0.5
43
+ 1: 0.8,
44
+ 2: 0.9 // 0.35
45
+ // 3: 0.45, // 0.45
46
+ // 4: 0.5 // 0.5
44
47
  };
45
- return map[index] ?? Math.min(1, map[4] + index * 0.5);
48
+ return map[index] ?? Math.min(1, map[2] + index * 0.05);
46
49
  };
47
50
  const degrees = getDegreesRelativeCenter();
48
51
  const [screenHeight, offsets] = getScreenHeightsAndOffsets(degrees);
52
+ const scales = [1, 0.925, 0.8];
49
53
  return [
50
54
  // top items
51
55
  ...degrees
@@ -55,12 +59,13 @@ export const createFaces = (itemHeight, visibleCount) => {
55
59
  deg: degree,
56
60
  opacity: getOpacity(degrees.length - 1 - index),
57
61
  offsetY: -1 * offsets[index],
62
+ scale: scales[index],
58
63
  screenHeight: screenHeight[index]
59
64
  };
60
65
  })
61
66
  .reverse(),
62
67
  // center item
63
- { index: 0, deg: 0, opacity: 1, offsetY: 0, screenHeight: itemHeight },
68
+ { index: 0, deg: 0, opacity: 1, offsetY: 0, scale: 1.031, screenHeight: itemHeight },
64
69
  // bottom items
65
70
  ...degrees.map((degree, index) => {
66
71
  return {
@@ -68,6 +73,7 @@ export const createFaces = (itemHeight, visibleCount) => {
68
73
  deg: -1 * degree,
69
74
  opacity: getOpacity(degrees.length - 1 - index),
70
75
  offsetY: offsets[index],
76
+ scale: scales[index],
71
77
  screenHeight: screenHeight[index]
72
78
  };
73
79
  })
@@ -0,0 +1,9 @@
1
+ import { createContext, useContext } from 'react';
2
+ export const PickerViewColumnAnimationContext = createContext(undefined);
3
+ export const usePickerViewColumnAnimationContext = () => {
4
+ const value = useContext(PickerViewColumnAnimationContext);
5
+ if (value === undefined) {
6
+ throw new Error('usePickerViewColumnAnimationContext must be called from within PickerViewColumnAnimationContext.Provider!');
7
+ }
8
+ return value;
9
+ };
@@ -0,0 +1,18 @@
1
+ import React from 'react';
2
+ import { StyleSheet, View } from 'react-native';
3
+ import LinearGradient from 'react-native-linear-gradient';
4
+ const _PickerViewMask = ({ itemHeight, maskContainerStyle }) => {
5
+ return (<View style={[styles.overlayContainer, maskContainerStyle]} pointerEvents={'none'}>
6
+ <LinearGradient colors={['rgba(255,255,255,1)', 'rgba(255,255,255,0.5)']} style={{ flex: 1 }}/>
7
+ <View style={{ height: itemHeight }}/>
8
+ <LinearGradient colors={['rgba(255,255,255,0.5)', 'rgba(255,255,255,1)']} style={{ flex: 1 }}/>
9
+ </View>);
10
+ };
11
+ const styles = StyleSheet.create({
12
+ overlayContainer: {
13
+ ...StyleSheet.absoluteFillObject,
14
+ zIndex: 100
15
+ }
16
+ });
17
+ _PickerViewMask.displayName = 'MpxPickerViewMask';
18
+ export default _PickerViewMask;
@@ -1,6 +1,6 @@
1
1
  import React from 'react';
2
2
  import { StyleSheet, View } from 'react-native';
3
- const Overlay = ({ itemHeight, overlayItemStyle, overlayContainerStyle }) => {
3
+ const _PickerViewOverlay = ({ itemHeight, overlayItemStyle, overlayContainerStyle }) => {
4
4
  return (<View style={[styles.overlayContainer, overlayContainerStyle]} pointerEvents={'none'}>
5
5
  <View style={[styles.selection, { height: itemHeight }, overlayItemStyle]}/>
6
6
  </View>);
@@ -9,7 +9,8 @@ const styles = StyleSheet.create({
9
9
  overlayContainer: {
10
10
  ...StyleSheet.absoluteFillObject,
11
11
  justifyContent: 'center',
12
- alignItems: 'center'
12
+ alignItems: 'center',
13
+ zIndex: 200
13
14
  },
14
15
  selection: {
15
16
  borderTopWidth: 1,
@@ -18,4 +19,5 @@ const styles = StyleSheet.create({
18
19
  alignSelf: 'stretch'
19
20
  }
20
21
  });
21
- export default React.memo(Overlay);
22
+ _PickerViewOverlay.displayName = 'MpxPickerViewOverlay';
23
+ export default _PickerViewOverlay;
@@ -47,9 +47,32 @@ 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
78
  const match = item.match(/([/\w]+)\(([^)]+)\)/);
@@ -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,14 @@ 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));
187
209
  // key不存在,第一轮取shareValMap[key]value,非第一轮取上一轮的
188
- if (toVal === undefined) {
189
- toVal = index > 0 ? lastValueMap[key] : shareValMap[key].value;
190
- }
210
+ const toVal = rules.get(key) !== undefined
211
+ ? rules.get(key)
212
+ : transform.get(key) !== undefined
213
+ ? transform.get(key)
214
+ : index > 0
215
+ ? lastValueMap[key]
216
+ : shareValMap[key].value;
191
217
  const animation = getAnimation({ key, value: toVal }, { delay, duration, easing }, needSetCallback ? setTransformOrigin : undefined);
192
218
  needSetCallback = false;
193
219
  if (!sequence[key]) {
@@ -298,6 +324,6 @@ export default function useAnimationHooks(props) {
298
324
  styles[key] = shareValMap[key].value;
299
325
  }
300
326
  return styles;
301
- }, Object.assign({}, originalStyle));
327
+ }, {});
302
328
  });
303
329
  }