@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
@@ -4,13 +4,13 @@
4
4
  * ✔ checked
5
5
  * ✔ color
6
6
  */
7
- import { useRef, useState, forwardRef, useEffect, useContext } from 'react';
7
+ import { useRef, useState, forwardRef, useEffect, useContext, createElement } from 'react';
8
8
  import { View, StyleSheet } from 'react-native';
9
9
  import { warn } from '@mpxjs/utils';
10
10
  import { LabelContext, RadioGroupContext } from './context';
11
11
  import useInnerProps, { getCustomEvent } from './getInnerListeners';
12
12
  import useNodesRef from './useNodesRef';
13
- import { splitProps, splitStyle, useLayout, useTransformStyle, wrapChildren } from './utils';
13
+ import { splitProps, splitStyle, useLayout, useTransformStyle, wrapChildren, extendObject } from './utils';
14
14
  import Icon from './mpx-icon';
15
15
  const styles = StyleSheet.create({
16
16
  container: {
@@ -47,21 +47,14 @@ const styles = StyleSheet.create({
47
47
  });
48
48
  const Radio = forwardRef((radioProps, ref) => {
49
49
  const { textProps, innerProps: props = {} } = splitProps(radioProps);
50
- const { value = '', disabled = false, checked = false, color = '#09BB07', style = [], 'enable-var': enableVar, 'external-var-context': externalVarContext, 'parent-font-size': parentFontSize, 'parent-width': parentWidth, 'parent-height': parentHeight, bindtap, catchtap } = props;
50
+ const { value = '', disabled = false, checked = false, color = '#09BB07', style = [], 'enable-var': enableVar, 'external-var-context': externalVarContext, 'parent-font-size': parentFontSize, 'parent-width': parentWidth, 'parent-height': parentHeight, bindtap } = props;
51
51
  const [isChecked, setIsChecked] = useState(!!checked);
52
52
  const groupContext = useContext(RadioGroupContext);
53
53
  let groupValue;
54
54
  let notifyChange;
55
55
  const labelContext = useContext(LabelContext);
56
- const defaultStyle = {
57
- ...styles.wrapper,
58
- ...(isChecked && styles.wrapperChecked),
59
- ...(disabled && styles.wrapperDisabled)
60
- };
61
- const styleObj = {
62
- ...styles.container,
63
- ...style
64
- };
56
+ const defaultStyle = extendObject({}, styles.wrapper, isChecked ? styles.wrapperChecked : {}, disabled ? styles.wrapperDisabled : {});
57
+ const styleObj = extendObject({}, styles.container, style);
65
58
  const onChange = (evt) => {
66
59
  if (disabled || isChecked)
67
60
  return;
@@ -77,24 +70,17 @@ const Radio = forwardRef((radioProps, ref) => {
77
70
  notifyChange && notifyChange(evt);
78
71
  };
79
72
  const onTap = (evt) => {
80
- if (disabled)
81
- return;
82
73
  bindtap && bindtap(getCustomEvent('tap', evt, { layoutRef }, props));
83
74
  onChange(evt);
84
75
  };
85
- const catchTap = (evt) => {
86
- if (disabled)
87
- return;
88
- catchtap && catchtap(getCustomEvent('tap', evt, { layoutRef }, props));
89
- };
90
76
  const { hasSelfPercent, normalStyle, hasVarDec, varContextRef, setWidth, setHeight } = useTransformStyle(styleObj, { enableVar, externalVarContext, parentFontSize, parentWidth, parentHeight });
91
- const { textStyle, backgroundStyle, innerStyle } = splitStyle(normalStyle);
77
+ const { textStyle, backgroundStyle, innerStyle = {} } = splitStyle(normalStyle);
92
78
  if (backgroundStyle) {
93
79
  warn('Radio does not support background image-related styles!');
94
80
  }
95
81
  const nodeRef = useRef(null);
96
82
  useNodesRef(props, ref, nodeRef, {
97
- defaultStyle,
83
+ style: extendObject({}, defaultStyle, normalStyle),
98
84
  change: onChange
99
85
  });
100
86
  const { layoutRef, layoutStyle, layoutProps } = useLayout({ props, hasSelfPercent, setWidth, setHeight, nodeRef });
@@ -105,13 +91,16 @@ const Radio = forwardRef((radioProps, ref) => {
105
91
  if (labelContext) {
106
92
  labelContext.current.triggerChange = onChange;
107
93
  }
108
- const innerProps = useInnerProps(props, {
94
+ const innerProps = useInnerProps(props, extendObject({
109
95
  ref: nodeRef,
110
- style: { ...innerStyle, ...layoutStyle },
111
- ...layoutProps,
112
- bindtap: onTap,
113
- catchtap: catchTap
114
- }, [], {
96
+ style: extendObject({}, innerStyle, layoutStyle)
97
+ }, layoutProps, {
98
+ bindtap: !disabled && onTap
99
+ }), [
100
+ 'value',
101
+ 'disabled',
102
+ 'checked'
103
+ ], {
115
104
  layoutRef
116
105
  });
117
106
  useEffect(() => {
@@ -135,21 +124,17 @@ const Radio = forwardRef((radioProps, ref) => {
135
124
  }
136
125
  }
137
126
  }, [checked]);
138
- return (<View {...innerProps}>
139
- <View style={defaultStyle}>
140
- <Icon type='success' size={24} color={disabled ? '#E1E1E1' : color} style={{
141
- ...styles.icon,
142
- ...(isChecked && styles.iconChecked),
143
- ...(disabled && styles.iconDisabled)
144
- }}/>
145
- </View>
146
- {wrapChildren(props, {
147
- hasVarDec,
148
- varContext: varContextRef.current,
149
- textStyle,
150
- textProps
151
- })}
152
- </View>);
127
+ return createElement(View, innerProps, createElement(View, { style: defaultStyle }, createElement(Icon, {
128
+ type: 'success',
129
+ size: 24,
130
+ color: disabled ? '#E1E1E1' : color,
131
+ style: extendObject({}, styles.icon, isChecked && styles.iconChecked, disabled && styles.iconDisabled)
132
+ })), wrapChildren(props, {
133
+ hasVarDec,
134
+ varContext: varContextRef.current,
135
+ textStyle,
136
+ textProps
137
+ }));
153
138
  });
154
139
  Radio.displayName = 'MpxRadio';
155
140
  export default Radio;
@@ -0,0 +1,39 @@
1
+ export const generateHTML = (html) => {
2
+ return `<html><head>
3
+ <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scaleable=no" name="viewport">
4
+ <style>
5
+ html {
6
+ -ms-content-zooming: none;
7
+ -ms-touch-action: pan-x pan-y;
8
+ }
9
+ body {
10
+ position: fixed;
11
+ top: 0;
12
+ right: 0;
13
+ bottom: 0;
14
+ left: 0;
15
+ overflow: hidden;
16
+ }
17
+ html,body {
18
+ margin: 0;
19
+ padding: 0;
20
+ }
21
+ * {
22
+ user-select: none;
23
+ -ms-user-select: none;
24
+ -moz-user-select: none;
25
+ -webkit-user-select: none;
26
+ }
27
+ </style>
28
+ </head>
29
+ <body><div id="rich-text">${html}</div>
30
+ <script>
31
+ function sendHeight() {
32
+ const dom = document.getElementById('rich-text')
33
+ window.ReactNativeWebView.postMessage(dom.scrollHeight);
34
+ }
35
+ window.onload = sendHeight;
36
+ </script>
37
+ </body
38
+ ></html>`;
39
+ };
@@ -0,0 +1,63 @@
1
+ /**
2
+ * ✔ nodes
3
+ */
4
+ import { View } from 'react-native';
5
+ import { useRef, forwardRef, useState } from 'react';
6
+ import useInnerProps from '../getInnerListeners';
7
+ import useNodesRef from '../useNodesRef'; // 引入辅助函数
8
+ import { useTransformStyle, useLayout } from '../utils';
9
+ import { WebView } from 'react-native-webview';
10
+ import { generateHTML } from './html';
11
+ function jsonToHtmlStr(elements) {
12
+ let htmlStr = '';
13
+ for (const element of elements) {
14
+ if (element.type === 'text') {
15
+ htmlStr += element.text;
16
+ return htmlStr;
17
+ }
18
+ const { name, attrs = {}, children = [] } = element;
19
+ let attrStr = '';
20
+ for (const [key, value] of Object.entries(attrs))
21
+ attrStr += ` ${key}="${value}"`;
22
+ let childrenStr = '';
23
+ for (const child of children)
24
+ childrenStr += jsonToHtmlStr([child]);
25
+ htmlStr += `<${name}${attrStr}>${childrenStr}</${name}>`;
26
+ }
27
+ return htmlStr;
28
+ }
29
+ const _RichText = forwardRef((props, ref) => {
30
+ const { style = {}, nodes, 'enable-var': enableVar, 'external-var-context': externalVarContext, 'parent-font-size': parentFontSize, 'parent-width': parentWidth, 'parent-height': parentHeight } = props;
31
+ const nodeRef = useRef(null);
32
+ const [webViewHeight, setWebViewHeight] = useState(0);
33
+ const { normalStyle, hasSelfPercent, setWidth, setHeight } = useTransformStyle(Object.assign({
34
+ width: '100%',
35
+ height: webViewHeight
36
+ }, style), {
37
+ enableVar,
38
+ externalVarContext,
39
+ parentFontSize,
40
+ parentWidth,
41
+ parentHeight
42
+ });
43
+ const { layoutRef, layoutStyle, layoutProps } = useLayout({ props, hasSelfPercent, setWidth, setHeight, nodeRef });
44
+ useNodesRef(props, ref, nodeRef, {
45
+ layoutRef
46
+ });
47
+ const innerProps = useInnerProps(props, {
48
+ ref: nodeRef,
49
+ style: { ...normalStyle, ...layoutStyle },
50
+ ...layoutProps
51
+ }, [], {
52
+ layoutRef
53
+ });
54
+ const html = typeof nodes === 'string' ? nodes : jsonToHtmlStr(nodes);
55
+ return (<View {...innerProps}>
56
+ <WebView source={{ html: generateHTML(html) }} onMessage={(event) => {
57
+ setWebViewHeight(+event.nativeEvent.data);
58
+ }}>
59
+ </WebView>
60
+ </View>);
61
+ });
62
+ _RichText.displayName = 'mpx-rich-text';
63
+ export default _RichText;
@@ -1,3 +1,7 @@
1
+ /**
2
+ * ✔ enable
3
+ */
4
+ import { createElement, Fragment } from 'react';
1
5
  import { Portal } from '@ant-design/react-native';
2
6
  import { warn } from '@mpxjs/utils';
3
7
  const _RootPortal = (props) => {
@@ -6,10 +10,8 @@ const _RootPortal = (props) => {
6
10
  warn('The root-portal component does not support the style prop.');
7
11
  }
8
12
  return enable
9
- ? <Portal>
10
- {children}
11
- </Portal>
12
- : <>{children}</>;
13
+ ? createElement(Portal, null, children)
14
+ : createElement(Fragment, null, children);
13
15
  };
14
16
  _RootPortal.displayName = 'MpxRootPortal';
15
17
  export default _RootPortal;
@@ -33,12 +33,12 @@
33
33
  */
34
34
  import { ScrollView } from 'react-native-gesture-handler';
35
35
  import { RefreshControl } from 'react-native';
36
- import { useRef, useState, useEffect, forwardRef, useContext } from 'react';
36
+ import { useRef, useState, useEffect, forwardRef, useContext, createElement } from 'react';
37
37
  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, flatGesture } from './utils';
41
+ import { splitProps, splitStyle, useTransformStyle, useLayout, wrapChildren, extendObject, flatGesture } from './utils';
42
42
  import { IntersectionObserverContext } from './context';
43
43
  const _ScrollView = forwardRef((scrollViewProps = {}, ref) => {
44
44
  const { textProps, innerProps: props = {} } = splitProps(scrollViewProps);
@@ -60,11 +60,12 @@ const _ScrollView = forwardRef((scrollViewProps = {}, ref) => {
60
60
  const hasCallScrollToLower = useRef(false);
61
61
  const initialTimeout = useRef(null);
62
62
  const intersectionObservers = useContext(IntersectionObserverContext);
63
- const snapScrollIntoView = useRef('');
63
+ const firstScrollIntoViewChange = useRef(false);
64
64
  const { normalStyle, hasVarDec, varContextRef, hasSelfPercent, setWidth, setHeight } = useTransformStyle(style, { enableVar, externalVarContext, parentFontSize, parentWidth, parentHeight });
65
- const { textStyle, innerStyle } = splitStyle(normalStyle);
65
+ const { textStyle, innerStyle = {} } = splitStyle(normalStyle);
66
66
  const scrollViewRef = useAnimatedRef();
67
67
  useNodesRef(props, ref, scrollViewRef, {
68
+ style: normalStyle,
68
69
  scrollOffset: scrollOptions,
69
70
  node: {
70
71
  scrollEnabled: scrollX || scrollY,
@@ -97,19 +98,25 @@ const _ScrollView = forwardRef((scrollViewProps = {}, ref) => {
97
98
  }
98
99
  }, [refresherTriggered]);
99
100
  useEffect(() => {
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
- });
101
+ if (scrollIntoView && __selectRef) {
102
+ if (!firstScrollIntoViewChange.current) {
103
+ setTimeout(handleScrollIntoView);
104
+ }
105
+ else {
106
+ handleScrollIntoView();
107
+ }
111
108
  }
109
+ firstScrollIntoViewChange.current = true;
112
110
  }, [scrollIntoView]);
111
+ function handleScrollIntoView() {
112
+ const refs = __selectRef(`#${scrollIntoView}`, 'node');
113
+ if (!refs)
114
+ return;
115
+ const { nodeRef } = refs.getNodeInstance();
116
+ nodeRef.current?.measureLayout(scrollViewRef.current, (left, top) => {
117
+ scrollToOffset(left, top);
118
+ });
119
+ }
113
120
  function selectLength(size) {
114
121
  return !scrollX ? size.height : size.width;
115
122
  }
@@ -164,14 +171,13 @@ const _ScrollView = forwardRef((scrollViewProps = {}, ref) => {
164
171
  const visibleLength = selectLength(e.nativeEvent.layoutMeasurement);
165
172
  const contentLength = selectLength(e.nativeEvent.contentSize);
166
173
  const offset = selectOffset(e.nativeEvent.contentOffset);
167
- scrollOptions.current = {
168
- ...scrollOptions.current,
174
+ extendObject(scrollOptions.current, {
169
175
  contentLength,
170
176
  offset,
171
177
  scrollLeft: position.scrollLeft,
172
178
  scrollTop: position.scrollTop,
173
179
  visibleLength
174
- };
180
+ });
175
181
  }
176
182
  function onScroll(e) {
177
183
  const { bindscroll } = props;
@@ -272,8 +278,8 @@ const _ScrollView = forwardRef((scrollViewProps = {}, ref) => {
272
278
  const { x: scrollLeft, y: scrollTop } = e.nativeEvent.contentOffset;
273
279
  updateScrollOptions(e, { scrollLeft, scrollTop });
274
280
  }
275
- let scrollAdditionalProps = {
276
- style: { ...innerStyle, ...layoutStyle },
281
+ const scrollAdditionalProps = extendObject({
282
+ style: extendObject({}, innerStyle, layoutStyle),
277
283
  pinchGestureEnabled: false,
278
284
  horizontal: scrollX && !scrollY,
279
285
  scrollEventThrottle: scrollEventThrottle,
@@ -284,22 +290,18 @@ const _ScrollView = forwardRef((scrollViewProps = {}, ref) => {
284
290
  ref: scrollViewRef,
285
291
  onScroll: onScroll,
286
292
  onContentSizeChange: onContentSizeChange,
287
- bindtouchstart: ((enhanced && binddragstart) || bindtouchstart) ? onScrollTouchStart : undefined,
288
- bindtouchmove: ((enhanced && binddragging) || bindtouchend) ? onScrollTouchMove : undefined,
289
- bindtouchend: ((enhanced && binddragend) || bindtouchend) ? onScrollTouchEnd : undefined,
293
+ bindtouchstart: ((enhanced && binddragstart) || bindtouchstart) && onScrollTouchStart,
294
+ bindtouchmove: ((enhanced && binddragging) || bindtouchend) && onScrollTouchMove,
295
+ bindtouchend: ((enhanced && binddragend) || bindtouchend) && onScrollTouchEnd,
290
296
  onScrollBeginDrag: onScrollDrag,
291
297
  onScrollEndDrag: onScrollDrag,
292
- onMomentumScrollEnd: onScrollEnd,
293
- ...layoutProps,
294
- ...(simultaneousHandlers ? { simultaneousHandlers } : {}),
295
- ...(waitForHandlers ? { waitFor: waitForHandlers } : {})
296
- };
298
+ onMomentumScrollEnd: onScrollEnd
299
+ }, (simultaneousHandlers ? { simultaneousHandlers } : {}), (waitForHandlers ? { waitFor: waitForHandlers } : {}), layoutProps);
297
300
  if (enhanced) {
298
- scrollAdditionalProps = {
299
- ...scrollAdditionalProps,
301
+ Object.assign(scrollAdditionalProps, {
300
302
  bounces,
301
303
  pagingEnabled
302
- };
304
+ });
303
305
  }
304
306
  const innerProps = useInnerProps(props, scrollAdditionalProps, [
305
307
  'id',
@@ -332,16 +334,20 @@ const _ScrollView = forwardRef((scrollViewProps = {}, ref) => {
332
334
  black: ['#000'],
333
335
  white: ['#fff']
334
336
  };
335
- return (<ScrollView {...innerProps} refreshControl={refresherEnabled
336
- ? (<RefreshControl progressBackgroundColor={refresherBackground} refreshing={refreshing} onRefresh={onRefresh} {...(refresherDefaultStyle && refresherDefaultStyle !== 'none' ? { colors: refreshColor[refresherDefaultStyle] } : {})}/>)
337
- : undefined}>
338
- {wrapChildren(props, {
339
- hasVarDec,
340
- varContext: varContextRef.current,
341
- textStyle,
342
- textProps
343
- })}
344
- </ScrollView>);
337
+ return createElement(ScrollView, extendObject({}, innerProps, {
338
+ refreshControl: refresherEnabled
339
+ ? createElement(RefreshControl, extendObject({
340
+ progressBackgroundColor: refresherBackground,
341
+ refreshing: refreshing,
342
+ onRefresh: onRefresh
343
+ }, (refresherDefaultStyle && refresherDefaultStyle !== 'none' ? { colors: refreshColor[refresherDefaultStyle] } : null)))
344
+ : undefined
345
+ }), wrapChildren(props, {
346
+ hasVarDec,
347
+ varContext: varContextRef.current,
348
+ textStyle,
349
+ textProps
350
+ }));
345
351
  });
346
352
  _ScrollView.displayName = 'MpxScrollView';
347
353
  export default _ScrollView;
@@ -0,0 +1,11 @@
1
+ import { Text } from 'react-native';
2
+ import { createElement } from 'react';
3
+ import { extendObject } from './utils';
4
+ const _Text2 = (props) => {
5
+ const { allowFontScaling = false } = props;
6
+ return createElement(Text, extendObject({}, props, {
7
+ allowFontScaling
8
+ }));
9
+ };
10
+ _Text2.displayName = 'MpxSimpleText';
11
+ export default _Text2;
@@ -44,7 +44,7 @@ const _Carouse = forwardRef((props, ref) => {
44
44
  // 默认取水平方向的width
45
45
  const { width } = Dimensions.get('window');
46
46
  const { style, previousMargin = 0, nextMargin = 0, enableVar, externalVarContext, parentFontSize, parentWidth, parentHeight } = props;
47
- // 计算transfrom之类的
47
+ // 计算transform之类的
48
48
  const { normalStyle, hasVarDec, varContextRef, hasSelfPercent, setWidth, setHeight } = useTransformStyle(style, {
49
49
  enableVar,
50
50
  externalVarContext,
@@ -72,7 +72,9 @@ const _Carouse = forwardRef((props, ref) => {
72
72
  // 内部存储上一次的offset值
73
73
  const autoplayTimerRef = useRef(null);
74
74
  const scrollViewRef = useRef(null);
75
- useNodesRef(props, ref, scrollViewRef, {});
75
+ useNodesRef(props, ref, scrollViewRef, {
76
+ style: normalStyle
77
+ });
76
78
  const {
77
79
  // 存储layout布局信息
78
80
  layoutRef, layoutProps, layoutStyle } = useLayout({ props, hasSelfPercent, setWidth, setHeight, nodeRef: scrollViewRef, onLayout: onWrapperLayout });
@@ -4,12 +4,14 @@ import useInnerProps from './getInnerListeners';
4
4
  import useNodesRef from './useNodesRef'; // 引入辅助函数
5
5
  import { useTransformStyle, splitStyle, splitProps, wrapChildren, useLayout } from './utils';
6
6
  const _SwiperItem = forwardRef((props, ref) => {
7
- const { 'enable-offset': enableOffset, 'enable-var': enableVar, 'external-var-context': externalVarContext, style } = props;
7
+ const { 'enable-var': enableVar, 'external-var-context': externalVarContext, style } = props;
8
8
  const { textProps } = splitProps(props);
9
9
  const nodeRef = useRef(null);
10
- useNodesRef(props, ref, nodeRef, {});
11
10
  const { normalStyle, hasVarDec, varContextRef, hasSelfPercent, setWidth, setHeight } = useTransformStyle(style, { enableVar, externalVarContext });
12
11
  const { textStyle, innerStyle } = splitStyle(normalStyle);
12
+ useNodesRef(props, ref, nodeRef, {
13
+ style: normalStyle
14
+ });
13
15
  const {
14
16
  // 存储layout布局信息
15
17
  layoutRef, layoutProps, layoutStyle } = useLayout({ props, hasSelfPercent, setWidth, setHeight, nodeRef: nodeRef });
@@ -5,13 +5,13 @@
5
5
  * ✔ color
6
6
  */
7
7
  import { Switch } from 'react-native';
8
- import { useRef, useEffect, forwardRef, useState, useContext } from 'react';
8
+ import { useRef, useEffect, forwardRef, useState, useContext, createElement } from 'react';
9
9
  import { warn } from '@mpxjs/utils';
10
10
  import useNodesRef from './useNodesRef'; // 引入辅助函数
11
11
  import useInnerProps, { getCustomEvent } from './getInnerListeners';
12
12
  import CheckBox from './mpx-checkbox';
13
13
  import { FormContext } from './context';
14
- import { useTransformStyle, useLayout } from './utils';
14
+ import { useTransformStyle, useLayout, extendObject } from './utils';
15
15
  const _Switch = forwardRef((props, ref) => {
16
16
  const { style = {}, checked = false, type = 'switch', disabled = false, color = '#04BE02', 'enable-var': enableVar, 'external-var-context': externalVarContext, 'parent-font-size': parentFontSize, 'parent-width': parentWidth, 'parent-height': parentHeight, bindchange, catchchange } = props;
17
17
  const [isChecked, setIsChecked] = useState(checked);
@@ -32,7 +32,9 @@ const _Switch = forwardRef((props, ref) => {
32
32
  setIsChecked(checked);
33
33
  }, [checked]);
34
34
  const nodeRef = useRef(null);
35
- useNodesRef(props, ref, nodeRef);
35
+ useNodesRef(props, ref, nodeRef, {
36
+ style: normalStyle
37
+ });
36
38
  const { layoutRef, layoutStyle, layoutProps } = useLayout({ props, hasSelfPercent, setWidth, setHeight, nodeRef });
37
39
  const onChange = (evt, { checked } = {}) => {
38
40
  if (type === 'switch') {
@@ -65,12 +67,10 @@ const _Switch = forwardRef((props, ref) => {
65
67
  }
66
68
  };
67
69
  }, []);
68
- const innerProps = useInnerProps(props, {
70
+ const innerProps = useInnerProps(props, extendObject({
69
71
  ref: nodeRef,
70
- style: { ...normalStyle, ...layoutStyle },
71
- ...layoutProps,
72
- ...!disabled ? { [type === 'switch' ? 'onValueChange' : '_onChange']: onChange } : {}
73
- }, [
72
+ style: extendObject({}, normalStyle, layoutStyle)
73
+ }, layoutProps, !disabled ? { [type === 'switch' ? 'onValueChange' : '_onChange']: onChange } : {}), [
74
74
  'checked',
75
75
  'disabled',
76
76
  'type',
@@ -79,9 +79,19 @@ const _Switch = forwardRef((props, ref) => {
79
79
  layoutRef
80
80
  });
81
81
  if (type === 'checkbox') {
82
- return <CheckBox {...innerProps} color={color} style={normalStyle} checked={isChecked}/>;
82
+ return createElement(CheckBox, extendObject({}, innerProps, {
83
+ color: color,
84
+ style: normalStyle,
85
+ checked: isChecked
86
+ }));
83
87
  }
84
- return <Switch {...innerProps} style={normalStyle} value={isChecked} trackColor={{ false: '#FFF', true: color }} thumbColor={isChecked ? '#FFF' : '#f4f3f4'} ios_backgroundColor="#FFF"/>;
88
+ return createElement(Switch, extendObject({}, innerProps, {
89
+ style: normalStyle,
90
+ value: isChecked,
91
+ trackColor: { false: '#FFF', true: color },
92
+ thumbColor: isChecked ? '#FFF' : '#f4f3f4',
93
+ ios_backgroundColor: '#FFF'
94
+ }));
85
95
  });
86
96
  _Switch.displayName = 'MpxSwitch';
87
97
  export default _Switch;
@@ -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;