@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
@@ -8,7 +8,8 @@ import {
8
8
  ReactNode,
9
9
  useContext,
10
10
  useMemo,
11
- useEffect
11
+ useEffect,
12
+ createElement
12
13
  } from 'react'
13
14
  import {
14
15
  View,
@@ -20,7 +21,7 @@ import { warn } from '@mpxjs/utils'
20
21
  import { FormContext, FormFieldValue, RadioGroupContext, GroupValue } from './context'
21
22
  import useInnerProps, { getCustomEvent } from './getInnerListeners'
22
23
  import useNodesRef, { HandlerRef } from './useNodesRef'
23
- import { useLayout, useTransformStyle, wrapChildren } from './utils'
24
+ import { useLayout, useTransformStyle, wrapChildren, extendObject } from './utils'
24
25
 
25
26
  export interface RadioGroupProps {
26
27
  name: string
@@ -67,10 +68,7 @@ const radioGroup = forwardRef<
67
68
  flexWrap: 'wrap'
68
69
  }
69
70
 
70
- const styleObj = {
71
- ...defaultStyle,
72
- ...style
73
- }
71
+ const styleObj = extendObject({}, defaultStyle, style)
74
72
 
75
73
  const {
76
74
  hasSelfPercent,
@@ -82,7 +80,7 @@ const radioGroup = forwardRef<
82
80
  } = useTransformStyle(styleObj, { enableVar, externalVarContext, parentFontSize, parentWidth, parentHeight })
83
81
 
84
82
  const nodeRef = useRef(null)
85
- useNodesRef(props, ref, nodeRef, { defaultStyle })
83
+ useNodesRef(props, ref, nodeRef, { style: normalStyle })
86
84
 
87
85
  const { layoutRef, layoutStyle, layoutProps } = useLayout({ props, hasSelfPercent, setWidth, setHeight, nodeRef })
88
86
 
@@ -144,31 +142,30 @@ const radioGroup = forwardRef<
144
142
 
145
143
  const innerProps = useInnerProps(
146
144
  props,
147
- {
148
- ref: nodeRef,
149
- style: { ...normalStyle, ...layoutStyle },
150
- ...layoutProps
151
- },
152
- [],
145
+ extendObject(
146
+ {
147
+ ref: nodeRef,
148
+ style: extendObject({}, normalStyle, layoutStyle)
149
+ },
150
+ layoutProps
151
+ ),
152
+ ['name'],
153
153
  {
154
154
  layoutRef
155
155
  }
156
156
  )
157
157
 
158
- return (
159
- <View {...innerProps}>
160
- <RadioGroupContext.Provider value={contextValue}>
161
- {
162
- wrapChildren(
163
- props,
164
- {
165
- hasVarDec,
166
- varContext: varContextRef.current
167
- }
168
- )
169
- }
170
- </RadioGroupContext.Provider>
171
- </View>
158
+ return createElement(View, innerProps, createElement(
159
+ RadioGroupContext.Provider,
160
+ { value: contextValue },
161
+ wrapChildren(
162
+ props,
163
+ {
164
+ hasVarDec,
165
+ varContext: varContextRef.current
166
+ }
167
+ )
168
+ )
172
169
  )
173
170
  })
174
171
 
@@ -4,13 +4,13 @@
4
4
  * ✔ checked
5
5
  * ✔ color
6
6
  */
7
- import { JSX, useRef, useState, forwardRef, useEffect, ReactNode, useContext, Dispatch, SetStateAction } from 'react'
7
+ import { JSX, useRef, useState, forwardRef, useEffect, ReactNode, useContext, Dispatch, SetStateAction, createElement } from 'react'
8
8
  import { View, StyleSheet, ViewStyle, NativeSyntheticEvent } 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, { HandlerRef } 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
 
16
16
  export interface RadioProps {
@@ -27,7 +27,6 @@ export interface RadioProps {
27
27
  'parent-height'?: number;
28
28
  children: ReactNode
29
29
  bindtap?: (evt: NativeSyntheticEvent<TouchEvent> | unknown) => void
30
- catchtap?: (evt: NativeSyntheticEvent<TouchEvent> | unknown) => void
31
30
  }
32
31
 
33
32
  const styles = StyleSheet.create({
@@ -79,8 +78,7 @@ const Radio = forwardRef<HandlerRef<View, RadioProps>, RadioProps>(
79
78
  'parent-font-size': parentFontSize,
80
79
  'parent-width': parentWidth,
81
80
  'parent-height': parentHeight,
82
- bindtap,
83
- catchtap
81
+ bindtap
84
82
  } = props
85
83
 
86
84
  const [isChecked, setIsChecked] = useState<boolean>(!!checked)
@@ -91,16 +89,14 @@ const Radio = forwardRef<HandlerRef<View, RadioProps>, RadioProps>(
91
89
 
92
90
  const labelContext = useContext(LabelContext)
93
91
 
94
- const defaultStyle = {
95
- ...styles.wrapper,
96
- ...(isChecked && styles.wrapperChecked),
97
- ...(disabled && styles.wrapperDisabled)
98
- }
92
+ const defaultStyle = extendObject(
93
+ {},
94
+ styles.wrapper,
95
+ isChecked ? styles.wrapperChecked : {},
96
+ disabled ? styles.wrapperDisabled : {}
97
+ )
99
98
 
100
- const styleObj = {
101
- ...styles.container,
102
- ...style
103
- }
99
+ const styleObj = extendObject({}, styles.container, style)
104
100
 
105
101
  const onChange = (evt: NativeSyntheticEvent<TouchEvent>) => {
106
102
  if (disabled || isChecked) return
@@ -116,16 +112,10 @@ const Radio = forwardRef<HandlerRef<View, RadioProps>, RadioProps>(
116
112
  }
117
113
 
118
114
  const onTap = (evt: NativeSyntheticEvent<TouchEvent>) => {
119
- if (disabled) return
120
115
  bindtap && bindtap(getCustomEvent('tap', evt, { layoutRef }, props))
121
116
  onChange(evt)
122
117
  }
123
118
 
124
- const catchTap = (evt: NativeSyntheticEvent<TouchEvent>) => {
125
- if (disabled) return
126
- catchtap && catchtap(getCustomEvent('tap', evt, { layoutRef }, props))
127
- }
128
-
129
119
  const {
130
120
  hasSelfPercent,
131
121
  normalStyle,
@@ -135,7 +125,7 @@ const Radio = forwardRef<HandlerRef<View, RadioProps>, RadioProps>(
135
125
  setHeight
136
126
  } = useTransformStyle(styleObj, { enableVar, externalVarContext, parentFontSize, parentWidth, parentHeight })
137
127
 
138
- const { textStyle, backgroundStyle, innerStyle } = splitStyle(normalStyle)
128
+ const { textStyle, backgroundStyle, innerStyle = {} } = splitStyle(normalStyle)
139
129
 
140
130
  if (backgroundStyle) {
141
131
  warn('Radio does not support background image-related styles!')
@@ -143,7 +133,7 @@ const Radio = forwardRef<HandlerRef<View, RadioProps>, RadioProps>(
143
133
 
144
134
  const nodeRef = useRef(null)
145
135
  useNodesRef(props, ref, nodeRef, {
146
- defaultStyle,
136
+ style: extendObject({}, defaultStyle, normalStyle),
147
137
  change: onChange
148
138
  })
149
139
 
@@ -160,14 +150,21 @@ const Radio = forwardRef<HandlerRef<View, RadioProps>, RadioProps>(
160
150
 
161
151
  const innerProps = useInnerProps(
162
152
  props,
163
- {
164
- ref: nodeRef,
165
- style: { ...innerStyle, ...layoutStyle },
166
- ...layoutProps,
167
- bindtap: onTap,
168
- catchtap: catchTap
169
- },
170
- [],
153
+ extendObject(
154
+ {
155
+ ref: nodeRef,
156
+ style: extendObject({}, innerStyle, layoutStyle)
157
+ },
158
+ layoutProps,
159
+ {
160
+ bindtap: !disabled && onTap
161
+ }
162
+ ),
163
+ [
164
+ 'value',
165
+ 'disabled',
166
+ 'checked'
167
+ ],
171
168
  {
172
169
  layoutRef
173
170
  }
@@ -196,32 +193,26 @@ const Radio = forwardRef<HandlerRef<View, RadioProps>, RadioProps>(
196
193
  }
197
194
  }, [checked])
198
195
 
199
- return (
200
- <View {...innerProps}>
201
- <View style={defaultStyle}>
202
- <Icon
203
- type='success'
204
- size={24}
205
- color={disabled ? '#E1E1E1' : color}
206
- style={{
207
- ...styles.icon,
208
- ...(isChecked && styles.iconChecked),
209
- ...(disabled && styles.iconDisabled)
210
- }}
211
- />
212
- </View>
196
+ return createElement(View, innerProps,
197
+ createElement(
198
+ View,
199
+ { style: defaultStyle },
200
+ createElement(Icon, {
201
+ type: 'success',
202
+ size: 24,
203
+ color: disabled ? '#E1E1E1' : color,
204
+ style: extendObject({}, styles.icon, isChecked && styles.iconChecked, disabled && styles.iconDisabled)
205
+ })
206
+ ),
207
+ wrapChildren(
208
+ props,
213
209
  {
214
- wrapChildren(
215
- props,
216
- {
217
- hasVarDec,
218
- varContext: varContextRef.current,
219
- textStyle,
220
- textProps
221
- }
222
- )
210
+ hasVarDec,
211
+ varContext: varContextRef.current,
212
+ textStyle,
213
+ textProps
223
214
  }
224
- </View>
215
+ )
225
216
  )
226
217
  }
227
218
  )
@@ -0,0 +1,40 @@
1
+
2
+ export const generateHTML = (html: string) => {
3
+ return `<html><head>
4
+ <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scaleable=no" name="viewport">
5
+ <style>
6
+ html {
7
+ -ms-content-zooming: none;
8
+ -ms-touch-action: pan-x pan-y;
9
+ }
10
+ body {
11
+ position: fixed;
12
+ top: 0;
13
+ right: 0;
14
+ bottom: 0;
15
+ left: 0;
16
+ overflow: hidden;
17
+ }
18
+ html,body {
19
+ margin: 0;
20
+ padding: 0;
21
+ }
22
+ * {
23
+ user-select: none;
24
+ -ms-user-select: none;
25
+ -moz-user-select: none;
26
+ -webkit-user-select: none;
27
+ }
28
+ </style>
29
+ </head>
30
+ <body><div id="rich-text">${html}</div>
31
+ <script>
32
+ function sendHeight() {
33
+ const dom = document.getElementById('rich-text')
34
+ window.ReactNativeWebView.postMessage(dom.scrollHeight);
35
+ }
36
+ window.onload = sendHeight;
37
+ </script>
38
+ </body
39
+ ></html>`
40
+ }
@@ -0,0 +1,121 @@
1
+
2
+ /**
3
+ * ✔ nodes
4
+ */
5
+ import { View, ViewProps, ViewStyle } from 'react-native'
6
+ import { useRef, forwardRef, JSX, useState } from 'react'
7
+ import useInnerProps from '../getInnerListeners'
8
+ import useNodesRef, { HandlerRef } from '../useNodesRef' // 引入辅助函数
9
+ import { useTransformStyle, useLayout } from '../utils'
10
+ import { WebView, WebViewMessageEvent } from 'react-native-webview'
11
+ import { generateHTML } from './html'
12
+
13
+ type Node = {
14
+ type: 'node' | 'text'
15
+ name?: string
16
+ attrs?: any
17
+ children?: Array<Node>
18
+ text: string
19
+ }
20
+
21
+ interface _RichTextProps extends ViewProps {
22
+ style?: ViewStyle
23
+ nodes: string | Array<Node>
24
+ 'enable-var'?: boolean
25
+ 'external-var-context'?: Record<string, any>
26
+ 'parent-font-size'?: number
27
+ 'parent-width'?: number
28
+ 'parent-height'?: number
29
+ }
30
+
31
+ function jsonToHtmlStr (elements: Array<Node>) {
32
+ let htmlStr = ''
33
+
34
+ for (const element of elements) {
35
+ if (element.type === 'text') {
36
+ htmlStr += element.text
37
+ return htmlStr
38
+ }
39
+
40
+ const { name, attrs = {}, children = [] } = element
41
+
42
+ let attrStr = ''
43
+ for (const [key, value] of Object.entries(attrs)) attrStr += ` ${key}="${value}"`
44
+
45
+ let childrenStr = ''
46
+ for (const child of children) childrenStr += jsonToHtmlStr([child])
47
+
48
+ htmlStr += `<${name}${attrStr}>${childrenStr}</${name}>`
49
+ }
50
+
51
+ return htmlStr
52
+ }
53
+
54
+ const _RichText = forwardRef<HandlerRef<View, _RichTextProps>, _RichTextProps>((props, ref): JSX.Element => {
55
+ const {
56
+ style = {},
57
+ nodes,
58
+ 'enable-var': enableVar,
59
+ 'external-var-context': externalVarContext,
60
+ 'parent-font-size': parentFontSize,
61
+ 'parent-width': parentWidth,
62
+ 'parent-height': parentHeight
63
+ } = props
64
+
65
+ const nodeRef = useRef(null)
66
+ const [webViewHeight, setWebViewHeight] = useState(0)
67
+
68
+ const {
69
+ normalStyle,
70
+ hasSelfPercent,
71
+ setWidth,
72
+ setHeight
73
+ } = useTransformStyle(Object.assign({
74
+ width: '100%',
75
+ height: webViewHeight
76
+ }, style), {
77
+ enableVar,
78
+ externalVarContext,
79
+ parentFontSize,
80
+ parentWidth,
81
+ parentHeight
82
+ })
83
+
84
+ const {
85
+ layoutRef,
86
+ layoutStyle,
87
+ layoutProps
88
+ } = useLayout({ props, hasSelfPercent, setWidth, setHeight, nodeRef })
89
+
90
+ useNodesRef<View, _RichTextProps>(props, ref, nodeRef, {
91
+ layoutRef
92
+ })
93
+
94
+ const innerProps = useInnerProps(props, {
95
+ ref: nodeRef,
96
+ style: { ...normalStyle, ...layoutStyle },
97
+ ...layoutProps
98
+ }, [], {
99
+ layoutRef
100
+ })
101
+
102
+ const html: string = typeof nodes === 'string' ? nodes : jsonToHtmlStr(nodes)
103
+
104
+ return (
105
+ <View
106
+ {...innerProps}
107
+ >
108
+ <WebView
109
+ source={{ html: generateHTML(html) }}
110
+ onMessage={(event: WebViewMessageEvent) => {
111
+ setWebViewHeight(+event.nativeEvent.data)
112
+ }}
113
+ >
114
+ </WebView>
115
+ </View>
116
+ )
117
+ })
118
+
119
+ _RichText.displayName = 'mpx-rich-text'
120
+
121
+ export default _RichText
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * ✔ enable
3
3
  */
4
- import { ReactNode } from 'react'
4
+ import { ReactNode, createElement, Fragment } from 'react'
5
5
  import { Portal } from '@ant-design/react-native'
6
6
  import { warn } from '@mpxjs/utils'
7
7
  interface RootPortalProps {
@@ -16,10 +16,8 @@ const _RootPortal = (props: RootPortalProps) => {
16
16
  warn('The root-portal component does not support the style prop.')
17
17
  }
18
18
  return enable
19
- ? <Portal>
20
- {children}
21
- </Portal>
22
- : <>{children}</>
19
+ ? createElement(Portal, null, children)
20
+ : createElement(Fragment, null, children)
23
21
  }
24
22
 
25
23
  _RootPortal.displayName = 'MpxRootPortal'
@@ -33,12 +33,12 @@
33
33
  */
34
34
  import { ScrollView } from 'react-native-gesture-handler'
35
35
  import { View, RefreshControl, NativeSyntheticEvent, NativeScrollEvent, LayoutChangeEvent, ViewStyle } from 'react-native'
36
- import { JSX, ReactNode, RefObject, useRef, useState, useEffect, forwardRef, useContext } from 'react'
36
+ import { JSX, ReactNode, RefObject, 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, { HandlerRef } from './useNodesRef'
41
- import { splitProps, splitStyle, useTransformStyle, useLayout, wrapChildren, flatGesture, GestureHandler } from './utils'
41
+ import { splitProps, splitStyle, useTransformStyle, useLayout, wrapChildren, extendObject, flatGesture, GestureHandler } from './utils'
42
42
  import { IntersectionObserverContext } from './context'
43
43
 
44
44
  interface ScrollViewProps {
@@ -165,7 +165,7 @@ const _ScrollView = forwardRef<HandlerRef<ScrollView & View, ScrollViewProps>, S
165
165
  const initialTimeout = useRef<ReturnType<typeof setTimeout> | null>(null)
166
166
  const intersectionObservers = useContext(IntersectionObserverContext)
167
167
 
168
- const snapScrollIntoView = useRef<string>('')
168
+ const firstScrollIntoViewChange = useRef<boolean>(false)
169
169
 
170
170
  const {
171
171
  normalStyle,
@@ -176,10 +176,11 @@ const _ScrollView = forwardRef<HandlerRef<ScrollView & View, ScrollViewProps>, S
176
176
  setHeight
177
177
  } = useTransformStyle(style, { enableVar, externalVarContext, parentFontSize, parentWidth, parentHeight })
178
178
 
179
- const { textStyle, innerStyle } = splitStyle(normalStyle)
179
+ const { textStyle, innerStyle = {} } = splitStyle(normalStyle)
180
180
 
181
181
  const scrollViewRef = useAnimatedRef<ScrollView>()
182
182
  useNodesRef(props, ref, scrollViewRef, {
183
+ style: normalStyle,
183
184
  scrollOffset: scrollOptions,
184
185
  node: {
185
186
  scrollEnabled: scrollX || scrollY,
@@ -219,23 +220,28 @@ const _ScrollView = forwardRef<HandlerRef<ScrollView & View, ScrollViewProps>, S
219
220
  }, [refresherTriggered])
220
221
 
221
222
  useEffect(() => {
222
- if (scrollIntoView && __selectRef && snapScrollIntoView.current !== scrollIntoView) {
223
- snapScrollIntoView.current = scrollIntoView || ''
224
- setTimeout(() => {
225
- const refs = __selectRef(`#${scrollIntoView}`, 'node')
226
- if (refs) {
227
- const { nodeRef } = refs.getNodeInstance()
228
- nodeRef.current?.measureLayout(
229
- scrollViewRef.current,
230
- (left: number, top:number) => {
231
- scrollToOffset(left, top)
232
- }
233
- )
234
- }
235
- })
223
+ if (scrollIntoView && __selectRef) {
224
+ if (!firstScrollIntoViewChange.current) {
225
+ setTimeout(handleScrollIntoView)
226
+ } else {
227
+ handleScrollIntoView()
228
+ }
236
229
  }
230
+ firstScrollIntoViewChange.current = true
237
231
  }, [scrollIntoView])
238
232
 
233
+ function handleScrollIntoView () {
234
+ const refs = __selectRef!(`#${scrollIntoView}`, 'node')
235
+ if (!refs) return
236
+ const { nodeRef } = refs.getNodeInstance()
237
+ nodeRef.current?.measureLayout(
238
+ scrollViewRef.current,
239
+ (left: number, top:number) => {
240
+ scrollToOffset(left, top)
241
+ }
242
+ )
243
+ }
244
+
239
245
  function selectLength (size: { height: number; width: number }) {
240
246
  return !scrollX ? size.height : size.width
241
247
  }
@@ -298,14 +304,13 @@ const _ScrollView = forwardRef<HandlerRef<ScrollView & View, ScrollViewProps>, S
298
304
  const visibleLength = selectLength(e.nativeEvent.layoutMeasurement)
299
305
  const contentLength = selectLength(e.nativeEvent.contentSize)
300
306
  const offset = selectOffset(e.nativeEvent.contentOffset)
301
- scrollOptions.current = {
302
- ...scrollOptions.current,
307
+ extendObject(scrollOptions.current, {
303
308
  contentLength,
304
309
  offset,
305
310
  scrollLeft: position.scrollLeft,
306
311
  scrollTop: position.scrollTop,
307
312
  visibleLength
308
- }
313
+ })
309
314
  }
310
315
 
311
316
  function onScroll (e: NativeSyntheticEvent<NativeScrollEvent>) {
@@ -426,34 +431,36 @@ const _ScrollView = forwardRef<HandlerRef<ScrollView & View, ScrollViewProps>, S
426
431
  updateScrollOptions(e, { scrollLeft, scrollTop })
427
432
  }
428
433
 
429
- let scrollAdditionalProps: ScrollAdditionalProps = {
430
- style: { ...innerStyle, ...layoutStyle },
431
- pinchGestureEnabled: false,
432
- horizontal: scrollX && !scrollY,
433
- scrollEventThrottle: scrollEventThrottle,
434
- scrollsToTop: enableBackToTop,
435
- showsHorizontalScrollIndicator: scrollX && showScrollbar,
436
- showsVerticalScrollIndicator: scrollY && showScrollbar,
437
- scrollEnabled: scrollX || scrollY,
438
- ref: scrollViewRef,
439
- onScroll: onScroll,
440
- onContentSizeChange: onContentSizeChange,
441
- bindtouchstart: ((enhanced && binddragstart) || bindtouchstart) ? onScrollTouchStart : undefined,
442
- bindtouchmove: ((enhanced && binddragging) || bindtouchend) ? onScrollTouchMove : undefined,
443
- bindtouchend: ((enhanced && binddragend) || bindtouchend) ? onScrollTouchEnd : undefined,
444
- onScrollBeginDrag: onScrollDrag,
445
- onScrollEndDrag: onScrollDrag,
446
- onMomentumScrollEnd: onScrollEnd,
447
- ...layoutProps,
448
- ...(simultaneousHandlers ? { simultaneousHandlers } : {}),
449
- ...(waitForHandlers ? { waitFor: waitForHandlers } : {})
450
- }
434
+ const scrollAdditionalProps: ScrollAdditionalProps = extendObject(
435
+ {
436
+ style: extendObject({}, innerStyle, layoutStyle),
437
+ pinchGestureEnabled: false,
438
+ horizontal: scrollX && !scrollY,
439
+ scrollEventThrottle: scrollEventThrottle,
440
+ scrollsToTop: enableBackToTop,
441
+ showsHorizontalScrollIndicator: scrollX && showScrollbar,
442
+ showsVerticalScrollIndicator: scrollY && showScrollbar,
443
+ scrollEnabled: scrollX || scrollY,
444
+ ref: scrollViewRef,
445
+ onScroll: onScroll,
446
+ onContentSizeChange: onContentSizeChange,
447
+ bindtouchstart: ((enhanced && binddragstart) || bindtouchstart) && onScrollTouchStart,
448
+ bindtouchmove: ((enhanced && binddragging) || bindtouchend) && onScrollTouchMove,
449
+ bindtouchend: ((enhanced && binddragend) || bindtouchend) && onScrollTouchEnd,
450
+ onScrollBeginDrag: onScrollDrag,
451
+ onScrollEndDrag: onScrollDrag,
452
+ onMomentumScrollEnd: onScrollEnd
453
+ },
454
+ (simultaneousHandlers ? { simultaneousHandlers } : {}),
455
+ (waitForHandlers ? { waitFor: waitForHandlers } : {}),
456
+ layoutProps
457
+ )
458
+
451
459
  if (enhanced) {
452
- scrollAdditionalProps = {
453
- ...scrollAdditionalProps,
460
+ Object.assign(scrollAdditionalProps, {
454
461
  bounces,
455
462
  pagingEnabled
456
- }
463
+ })
457
464
  }
458
465
 
459
466
  const innerProps = useInnerProps(props, scrollAdditionalProps, [
@@ -489,32 +496,26 @@ const _ScrollView = forwardRef<HandlerRef<ScrollView & View, ScrollViewProps>, S
489
496
  white: ['#fff']
490
497
  }
491
498
 
492
- return (
493
- <ScrollView
494
- {...innerProps}
495
- refreshControl={refresherEnabled
496
- ? (
497
- <RefreshControl
498
- progressBackgroundColor={refresherBackground}
499
- refreshing={refreshing}
500
- onRefresh={onRefresh}
501
- {...(refresherDefaultStyle && refresherDefaultStyle !== 'none' ? { colors: refreshColor[refresherDefaultStyle] } : {})}
502
- />
503
- )
504
- : undefined}
505
- >
506
- {
507
- wrapChildren(
508
- props,
509
- {
510
- hasVarDec,
511
- varContext: varContextRef.current,
512
- textStyle,
513
- textProps
514
- }
515
- )
499
+ return createElement(
500
+ ScrollView,
501
+ extendObject({}, innerProps, {
502
+ refreshControl: refresherEnabled
503
+ ? createElement(RefreshControl, extendObject({
504
+ progressBackgroundColor: refresherBackground,
505
+ refreshing: refreshing,
506
+ onRefresh: onRefresh
507
+ }, (refresherDefaultStyle && refresherDefaultStyle !== 'none' ? { colors: refreshColor[refresherDefaultStyle] } : null)))
508
+ : undefined
509
+ }),
510
+ wrapChildren(
511
+ props,
512
+ {
513
+ hasVarDec,
514
+ varContext: varContextRef.current,
515
+ textStyle,
516
+ textProps
516
517
  }
517
- </ScrollView>
518
+ )
518
519
  )
519
520
  })
520
521
 
@@ -0,0 +1,18 @@
1
+ import { Text, TextProps } from 'react-native'
2
+ import { JSX, createElement } from 'react'
3
+
4
+ import { extendObject } from './utils'
5
+
6
+ const _Text2 = (props: TextProps): JSX.Element => {
7
+ const {
8
+ allowFontScaling = false
9
+ } = props
10
+
11
+ return createElement(Text, extendObject({}, props, {
12
+ allowFontScaling
13
+ }))
14
+ }
15
+
16
+ _Text2.displayName = 'MpxSimpleText'
17
+
18
+ export default _Text2