@mpxjs/webpack-plugin 2.10.4 → 2.10.5-beta.1

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 (100) hide show
  1. package/lib/index.js +10 -1
  2. package/lib/json-compiler/helper.js +1 -4
  3. package/lib/platform/json/wx/index.js +0 -1
  4. package/lib/platform/style/wx/index.js +22 -21
  5. package/lib/platform/template/wx/component-config/button.js +1 -1
  6. package/lib/platform/template/wx/component-config/index.js +5 -1
  7. package/lib/platform/template/wx/component-config/input.js +1 -1
  8. package/lib/platform/template/wx/component-config/sticky-header.js +23 -0
  9. package/lib/platform/template/wx/component-config/sticky-section.js +23 -0
  10. package/lib/platform/template/wx/index.js +21 -1
  11. package/lib/react/processJSON.js +7 -6
  12. package/lib/react/processScript.js +9 -1
  13. package/lib/react/script-helper.js +5 -1
  14. package/lib/resolver/PackageEntryPlugin.js +3 -1
  15. package/lib/runtime/components/react/context.ts +12 -3
  16. package/lib/runtime/components/react/dist/context.js +4 -1
  17. package/lib/runtime/components/react/dist/event.config.js +0 -2
  18. package/lib/runtime/components/react/dist/getInnerListeners.js +127 -153
  19. package/lib/runtime/components/react/dist/mpx-button.jsx +11 -7
  20. package/lib/runtime/components/react/dist/mpx-canvas/Image.js +2 -4
  21. package/lib/runtime/components/react/dist/mpx-canvas/index.jsx +23 -21
  22. package/lib/runtime/components/react/dist/mpx-checkbox-group.jsx +9 -4
  23. package/lib/runtime/components/react/dist/mpx-checkbox.jsx +9 -5
  24. package/lib/runtime/components/react/dist/mpx-form.jsx +2 -2
  25. package/lib/runtime/components/react/dist/mpx-icon/index.jsx +9 -4
  26. package/lib/runtime/components/react/dist/mpx-image.jsx +11 -4
  27. package/lib/runtime/components/react/dist/mpx-input.jsx +24 -13
  28. package/lib/runtime/components/react/dist/mpx-keyboard-avoiding-view.jsx +23 -30
  29. package/lib/runtime/components/react/dist/mpx-label.jsx +9 -5
  30. package/lib/runtime/components/react/dist/mpx-movable-area.jsx +9 -4
  31. package/lib/runtime/components/react/dist/mpx-movable-view.jsx +77 -43
  32. package/lib/runtime/components/react/dist/mpx-navigator.jsx +11 -3
  33. package/lib/runtime/components/react/dist/mpx-picker/index.jsx +12 -14
  34. package/lib/runtime/components/react/dist/mpx-picker-view/index.jsx +10 -10
  35. package/lib/runtime/components/react/dist/mpx-picker-view-column/index.jsx +28 -10
  36. package/lib/runtime/components/react/dist/mpx-radio-group.jsx +11 -4
  37. package/lib/runtime/components/react/dist/mpx-radio.jsx +9 -5
  38. package/lib/runtime/components/react/dist/mpx-rich-text/index.jsx +9 -4
  39. package/lib/runtime/components/react/dist/mpx-scroll-view.jsx +31 -11
  40. package/lib/runtime/components/react/dist/mpx-simple-text.jsx +3 -2
  41. package/lib/runtime/components/react/dist/mpx-simple-view.jsx +3 -3
  42. package/lib/runtime/components/react/dist/mpx-sticky-header.jsx +115 -0
  43. package/lib/runtime/components/react/dist/mpx-sticky-section.jsx +45 -0
  44. package/lib/runtime/components/react/dist/mpx-swiper-item.jsx +15 -14
  45. package/lib/runtime/components/react/dist/mpx-swiper.jsx +86 -40
  46. package/lib/runtime/components/react/dist/mpx-switch.jsx +10 -7
  47. package/lib/runtime/components/react/dist/mpx-text.jsx +11 -9
  48. package/lib/runtime/components/react/dist/mpx-video.jsx +9 -4
  49. package/lib/runtime/components/react/dist/mpx-view.jsx +15 -10
  50. package/lib/runtime/components/react/dist/mpx-web-view.jsx +13 -13
  51. package/lib/runtime/components/react/dist/useAnimationHooks.js +27 -4
  52. package/lib/runtime/components/react/dist/utils.jsx +99 -98
  53. package/lib/runtime/components/react/event.config.ts +1 -8
  54. package/lib/runtime/components/react/getInnerListeners.ts +146 -192
  55. package/lib/runtime/components/react/mpx-button.tsx +16 -8
  56. package/lib/runtime/components/react/mpx-canvas/Image.ts +4 -4
  57. package/lib/runtime/components/react/mpx-canvas/index.tsx +47 -32
  58. package/lib/runtime/components/react/mpx-checkbox-group.tsx +13 -4
  59. package/lib/runtime/components/react/mpx-checkbox.tsx +17 -10
  60. package/lib/runtime/components/react/mpx-form.tsx +25 -19
  61. package/lib/runtime/components/react/mpx-icon/index.tsx +13 -4
  62. package/lib/runtime/components/react/mpx-image.tsx +42 -22
  63. package/lib/runtime/components/react/mpx-input.tsx +32 -16
  64. package/lib/runtime/components/react/mpx-keyboard-avoiding-view.tsx +31 -42
  65. package/lib/runtime/components/react/mpx-label.tsx +13 -6
  66. package/lib/runtime/components/react/mpx-movable-area.tsx +29 -14
  67. package/lib/runtime/components/react/mpx-movable-view.tsx +121 -81
  68. package/lib/runtime/components/react/mpx-navigator.tsx +4 -6
  69. package/lib/runtime/components/react/mpx-picker/index.tsx +24 -19
  70. package/lib/runtime/components/react/mpx-picker-view/index.tsx +39 -22
  71. package/lib/runtime/components/react/mpx-picker-view-column/index.tsx +36 -32
  72. package/lib/runtime/components/react/mpx-radio-group.tsx +24 -12
  73. package/lib/runtime/components/react/mpx-radio.tsx +17 -10
  74. package/lib/runtime/components/react/mpx-rich-text/index.tsx +25 -8
  75. package/lib/runtime/components/react/mpx-scroll-view.tsx +95 -60
  76. package/lib/runtime/components/react/mpx-simple-text.tsx +10 -3
  77. package/lib/runtime/components/react/mpx-simple-view.tsx +10 -4
  78. package/lib/runtime/components/react/mpx-sticky-header.tsx +179 -0
  79. package/lib/runtime/components/react/mpx-sticky-section.tsx +96 -0
  80. package/lib/runtime/components/react/mpx-swiper-item.tsx +42 -43
  81. package/lib/runtime/components/react/mpx-swiper.tsx +142 -79
  82. package/lib/runtime/components/react/mpx-switch.tsx +29 -16
  83. package/lib/runtime/components/react/mpx-text.tsx +26 -15
  84. package/lib/runtime/components/react/mpx-video.tsx +41 -35
  85. package/lib/runtime/components/react/mpx-view.tsx +38 -18
  86. package/lib/runtime/components/react/mpx-web-view.tsx +12 -12
  87. package/lib/runtime/components/react/types/getInnerListeners.d.ts +65 -35
  88. package/lib/runtime/components/react/useAnimationHooks.ts +30 -9
  89. package/lib/runtime/components/react/utils.tsx +107 -103
  90. package/lib/runtime/components/web/mpx-scroll-view.vue +21 -4
  91. package/lib/runtime/components/web/mpx-sticky-header.vue +91 -0
  92. package/lib/runtime/components/web/mpx-sticky-section.vue +15 -0
  93. package/lib/runtime/components/web/mpx-web-view.vue +1 -1
  94. package/lib/runtime/mpxGlobal.js +1 -0
  95. package/lib/runtime/optionProcessor.d.ts +5 -0
  96. package/lib/template-compiler/bind-this.js +8 -7
  97. package/lib/template-compiler/compiler.js +1 -1
  98. package/lib/wxs/pre-loader.js +1 -0
  99. package/package.json +3 -3
  100. package/LICENSE +0 -433
@@ -9,7 +9,7 @@
9
9
  * ✔ bindlongtap
10
10
  * ✔ binderror
11
11
  */
12
- import React, { createElement, useRef, useState, useCallback, useEffect, forwardRef, JSX, TouchEvent, MutableRefObject } from 'react'
12
+ import { createElement, useRef, useState, useCallback, useEffect, forwardRef, JSX, TouchEvent, MutableRefObject } from 'react'
13
13
  import { View, Platform, StyleSheet, NativeSyntheticEvent } from 'react-native'
14
14
  import { WebView } from 'react-native-webview'
15
15
  import useNodesRef, { HandlerRef } from '../useNodesRef'
@@ -31,6 +31,7 @@ import './CanvasGradient'
31
31
  import { createImage as canvasCreateImage } from './Image'
32
32
  import { createImageData as canvasCreateImageData } from './ImageData'
33
33
  import { useConstructorsRegistry } from './constructorsRegistry'
34
+ import Portal from '../mpx-portal'
34
35
 
35
36
  const stylesheet = StyleSheet.create({
36
37
  container: { overflow: 'hidden', flex: 0 },
@@ -48,19 +49,19 @@ const stylesheet = StyleSheet.create({
48
49
  })
49
50
 
50
51
  interface CanvasProps {
51
- style?: Record<string, any>;
52
- originWhitelist?: Array<string>;
52
+ style?: Record<string, any>
53
+ originWhitelist?: Array<string>
53
54
  'enable-var'?: boolean
54
55
  'parent-font-size'?: number
55
56
  'parent-width'?: number
56
57
  'parent-height'?: number
57
58
  'external-var-context'?: Record<string, any>
58
- bindtouchstart?: (event: NativeSyntheticEvent<TouchEvent>) => void;
59
- bindtouchmove?: (event: NativeSyntheticEvent<TouchEvent>) => void;
60
- bindtouchend?: (event: NativeSyntheticEvent<TouchEvent>) => void;
61
- bindtouchcancel?: (event: NativeSyntheticEvent<TouchEvent>) => void;
62
- bindlongtap?: (event: NativeSyntheticEvent<TouchEvent>) => void;
63
- binderror?: (event: NativeSyntheticEvent<ErrorEvent>) => void;
59
+ bindtouchstart?: (event: NativeSyntheticEvent<TouchEvent>) => void
60
+ bindtouchmove?: (event: NativeSyntheticEvent<TouchEvent>) => void
61
+ bindtouchend?: (event: NativeSyntheticEvent<TouchEvent>) => void
62
+ bindtouchcancel?: (event: NativeSyntheticEvent<TouchEvent>) => void
63
+ bindlongtap?: (event: NativeSyntheticEvent<TouchEvent>) => void
64
+ binderror?: (event: NativeSyntheticEvent<ErrorEvent>) => void
64
65
  }
65
66
 
66
67
  const _Canvas = forwardRef<HandlerRef<CanvasProps & View, CanvasProps>, CanvasProps>((props: CanvasProps = {}, ref): JSX.Element => {
@@ -71,6 +72,7 @@ const _Canvas = forwardRef<HandlerRef<CanvasProps & View, CanvasProps>, CanvasPr
71
72
  const {
72
73
  normalStyle,
73
74
  hasSelfPercent,
75
+ hasPositionFixed,
74
76
  setWidth,
75
77
  setHeight
76
78
  } = useTransformStyle(extendObject({}, style, stylesheet.container), {
@@ -91,13 +93,21 @@ const _Canvas = forwardRef<HandlerRef<CanvasProps & View, CanvasProps>, CanvasPr
91
93
  const { register } = useConstructorsRegistry()
92
94
 
93
95
  const { layoutRef, layoutStyle, layoutProps } = useLayout({ props, hasSelfPercent, setWidth, setHeight, nodeRef })
94
- const innerProps = useInnerProps(props, {
95
- ref: nodeRef,
96
- style: extendObject({}, normalStyle, layoutStyle, { opacity: isLoaded ? 1 : 0 }),
97
- ...layoutProps
98
- }, [], {
99
- layoutRef
100
- })
96
+ const innerProps = useInnerProps(
97
+ extendObject(
98
+ {},
99
+ props,
100
+ layoutProps,
101
+ {
102
+ ref: nodeRef,
103
+ style: extendObject({}, normalStyle, layoutStyle, { opacity: isLoaded ? 1 : 0 })
104
+ }
105
+ ),
106
+ [],
107
+ {
108
+ layoutRef
109
+ }
110
+ )
101
111
 
102
112
  const context2D = new CanvasRenderingContext2D(canvasRef.current) as any
103
113
 
@@ -158,10 +168,7 @@ const _Canvas = forwardRef<HandlerRef<CanvasProps & View, CanvasProps>, CanvasPr
158
168
 
159
169
  const postMessage = useCallback(async (message: WebviewMessage) => {
160
170
  if (!canvasRef.current?.bus) return
161
- const { type, payload } = await canvasRef.current.bus.post({
162
- id: ID(),
163
- ...message
164
- })
171
+ const { type, payload } = await canvasRef.current.bus.post(extendObject({ id: ID() }, message))
165
172
 
166
173
  switch (type) {
167
174
  case 'error': {
@@ -196,7 +203,7 @@ const _Canvas = forwardRef<HandlerRef<CanvasProps & View, CanvasProps>, CanvasPr
196
203
  }
197
204
 
198
205
  const onMessage = useCallback((e: { nativeEvent: { data: string } }) => {
199
- let data = JSON.parse(e.nativeEvent.data)
206
+ const data = JSON.parse(e.nativeEvent.data)
200
207
  switch (data.type) {
201
208
  case 'error': {
202
209
  const { binderror } = props
@@ -212,27 +219,27 @@ const _Canvas = forwardRef<HandlerRef<CanvasProps & View, CanvasProps>, CanvasPr
212
219
  break
213
220
  }
214
221
  default: {
222
+ const newData: { payload?: unknown } = {}
223
+ // createLinearGradient 方法调用需要在 constructors 中需要注册 CanvasGradient
224
+ const constructor = constructors[data.meta.constructor]
215
225
  if (data.payload) {
216
- // createLinearGradient 方法调用需要在 constructors 中需要注册 CanvasGradient
217
- const constructor = constructors[data.meta.constructor]
218
226
  if (constructor) {
219
227
  const { args, payload } = data
220
228
  // RN 端同步生成一个 CanvasGradient 的实例
221
229
  const object = constructor.constructLocally(canvasRef.current, ...args)
222
- Object.assign(object, payload, {
230
+ extendObject(object, payload, {
223
231
  [WEBVIEW_TARGET]: data.meta.target
224
232
  })
225
- data = {
226
- ...data,
233
+ extendObject(newData, data, {
227
234
  payload: object
228
- }
235
+ })
229
236
  }
230
237
  for (const listener of canvasRef.current.listeners) {
231
- listener(data.payload)
238
+ listener(constructor ? newData.payload : data.payload)
232
239
  }
233
240
  }
234
241
  if (canvasRef.current.bus) {
235
- canvasRef.current.bus.handle(data)
242
+ canvasRef.current.bus.handle(constructor && data.payload ? newData : data)
236
243
  }
237
244
  }
238
245
  }
@@ -251,9 +258,11 @@ const _Canvas = forwardRef<HandlerRef<CanvasProps & View, CanvasProps>, CanvasPr
251
258
  context: context2D
252
259
  })
253
260
 
254
- if (__mpx_mode__ !== 'ios') {
261
+ let canvasComponent
262
+
263
+ if (__mpx_mode__ === 'android') {
255
264
  const isAndroid9 = Platform.Version as number >= 28
256
- return createElement(View, innerProps, createElement(
265
+ canvasComponent = createElement(View, innerProps, createElement(
257
266
  WebView,
258
267
  {
259
268
  ref: (element) => {
@@ -280,7 +289,7 @@ const _Canvas = forwardRef<HandlerRef<CanvasProps & View, CanvasProps>, CanvasPr
280
289
  )
281
290
  }
282
291
 
283
- return createElement(View, innerProps, createElement(WebView, {
292
+ canvasComponent = createElement(View, innerProps, createElement(WebView, {
284
293
  ref: (element) => {
285
294
  if (canvasRef.current) {
286
295
  canvasRef.current.webview = element
@@ -293,6 +302,12 @@ const _Canvas = forwardRef<HandlerRef<CanvasProps & View, CanvasProps>, CanvasPr
293
302
  onLoad: onLoad,
294
303
  scrollEnabled: false
295
304
  }))
305
+
306
+ if (hasPositionFixed) {
307
+ canvasComponent = createElement(Portal, null, canvasComponent)
308
+ }
309
+
310
+ return canvasComponent
296
311
  })
297
312
 
298
313
  _Canvas.displayName = 'mpxCanvas'
@@ -21,6 +21,7 @@ import { FormContext, FormFieldValue, CheckboxGroupContext, GroupValue } from '.
21
21
  import useInnerProps, { getCustomEvent } from './getInnerListeners'
22
22
  import useNodesRef, { HandlerRef } from './useNodesRef'
23
23
  import { useLayout, useTransformStyle, wrapChildren, extendObject } from './utils'
24
+ import Portal from './mpx-portal'
24
25
 
25
26
  export interface CheckboxGroupProps {
26
27
  name: string
@@ -68,6 +69,7 @@ const CheckboxGroup = forwardRef<
68
69
  const styleObj = extendObject({}, defaultStyle, style)
69
70
 
70
71
  const {
72
+ hasPositionFixed,
71
73
  hasSelfPercent,
72
74
  normalStyle,
73
75
  hasVarDec,
@@ -116,13 +118,14 @@ const CheckboxGroup = forwardRef<
116
118
  }, [])
117
119
 
118
120
  const innerProps = useInnerProps(
119
- props,
120
121
  extendObject(
122
+ {},
123
+ props,
124
+ layoutProps,
121
125
  {
122
126
  ref: nodeRef,
123
127
  style: extendObject({}, normalStyle, layoutStyle)
124
- },
125
- layoutProps
128
+ }
126
129
  ),
127
130
  [
128
131
  'name'
@@ -158,7 +161,7 @@ const CheckboxGroup = forwardRef<
158
161
  }
159
162
  }, [])
160
163
 
161
- return createElement(
164
+ const finalComponent = createElement(
162
165
  View,
163
166
  innerProps,
164
167
  createElement(
@@ -173,6 +176,12 @@ const CheckboxGroup = forwardRef<
173
176
  )
174
177
  )
175
178
  )
179
+
180
+ if (hasPositionFixed) {
181
+ return createElement(Portal, null, finalComponent)
182
+ }
183
+
184
+ return finalComponent
176
185
  })
177
186
 
178
187
  CheckboxGroup.displayName = 'MpxCheckboxGroup'
@@ -28,6 +28,7 @@ import useNodesRef, { HandlerRef } from './useNodesRef'
28
28
  import Icon from './mpx-icon'
29
29
  import { splitProps, splitStyle, useLayout, useTransformStyle, wrapChildren, extendObject } from './utils'
30
30
  import { CheckboxGroupContext, LabelContext } from './context'
31
+ import Portal from './mpx-portal'
31
32
 
32
33
  interface Selection {
33
34
  value?: string
@@ -42,9 +43,9 @@ export interface CheckboxProps extends Selection {
42
43
  'enable-offset'?: boolean
43
44
  'enable-var'?: boolean
44
45
  'external-var-context'?: Record<string, any>
45
- 'parent-font-size'?: number;
46
- 'parent-width'?: number;
47
- 'parent-height'?: number;
46
+ 'parent-font-size'?: number
47
+ 'parent-width'?: number
48
+ 'parent-height'?: number
48
49
  children?: ReactNode
49
50
  bindtap?: (evt: NativeSyntheticEvent<TouchEvent> | unknown) => void
50
51
  _onChange?: (evt: NativeSyntheticEvent<TouchEvent> | unknown, { checked }: { checked: boolean }) => void
@@ -99,7 +100,7 @@ const Checkbox = forwardRef<HandlerRef<View, CheckboxProps>, CheckboxProps>(
99
100
  const [isChecked, setIsChecked] = useState<boolean>(!!checked)
100
101
 
101
102
  const groupContext = useContext(CheckboxGroupContext)
102
- let groupValue: { [key: string]: { checked: boolean; setValue: Dispatch<SetStateAction<boolean>>; } } | undefined
103
+ let groupValue: { [key: string]: { checked: boolean; setValue: Dispatch<SetStateAction<boolean>> } } | undefined
103
104
  let notifyChange: (evt: NativeSyntheticEvent<TouchEvent>) => void | undefined
104
105
 
105
106
  const defaultStyle = extendObject(
@@ -128,6 +129,7 @@ const Checkbox = forwardRef<HandlerRef<View, CheckboxProps>, CheckboxProps>(
128
129
  }
129
130
 
130
131
  const {
132
+ hasPositionFixed,
131
133
  hasSelfPercent,
132
134
  normalStyle,
133
135
  hasVarDec,
@@ -163,14 +165,13 @@ const Checkbox = forwardRef<HandlerRef<View, CheckboxProps>, CheckboxProps>(
163
165
  }
164
166
 
165
167
  const innerProps = useInnerProps(
166
- props,
167
168
  extendObject(
168
- {
169
- ref: nodeRef,
170
- style: extendObject({}, innerStyle, layoutStyle)
171
- },
169
+ {},
170
+ props,
172
171
  layoutProps,
173
172
  {
173
+ ref: nodeRef,
174
+ style: extendObject({}, innerStyle, layoutStyle),
174
175
  bindtap: !disabled && onTap
175
176
  }
176
177
  ),
@@ -207,7 +208,7 @@ const Checkbox = forwardRef<HandlerRef<View, CheckboxProps>, CheckboxProps>(
207
208
  }
208
209
  }, [checked])
209
210
 
210
- return createElement(View, innerProps,
211
+ const finalComponent = createElement(View, innerProps,
211
212
  createElement(
212
213
  View,
213
214
  { style: defaultStyle },
@@ -228,6 +229,12 @@ const Checkbox = forwardRef<HandlerRef<View, CheckboxProps>, CheckboxProps>(
228
229
  }
229
230
  )
230
231
  )
232
+
233
+ if (hasPositionFixed) {
234
+ return createElement(Portal, null, finalComponent)
235
+ }
236
+
237
+ return finalComponent
231
238
  }
232
239
  )
233
240
 
@@ -11,20 +11,20 @@ import useInnerProps, { getCustomEvent } from './getInnerListeners'
11
11
  import { FormContext } from './context'
12
12
  import { useTransformStyle, splitProps, splitStyle, useLayout, wrapChildren, extendObject } from './utils'
13
13
  interface FormProps {
14
- style?: Record<string, any>;
15
- children?: ReactNode;
16
- 'enable-offset'?: boolean;
14
+ style?: Record<string, any>
15
+ children?: ReactNode
16
+ 'enable-offset'?: boolean
17
17
  'enable-var'?: boolean
18
- 'external-var-context'?: Record<string, any>;
19
- 'parent-font-size'?: number;
20
- 'parent-width'?: number;
21
- 'parent-height'?: number;
18
+ 'external-var-context'?: Record<string, any>
19
+ 'parent-font-size'?: number
20
+ 'parent-width'?: number
21
+ 'parent-height'?: number
22
22
  bindsubmit?: (evt: {
23
23
  detail: {
24
- value: any;
25
- };
26
- }) => void;
27
- bindreset?: () => void;
24
+ value: any
25
+ }
26
+ }) => void
27
+ bindreset?: () => void
28
28
  }
29
29
 
30
30
  const _Form = forwardRef<HandlerRef<View, FormProps>, FormProps>((fromProps: FormProps, ref): JSX.Element => {
@@ -59,14 +59,20 @@ const _Form = forwardRef<HandlerRef<View, FormProps>, FormProps>((fromProps: For
59
59
 
60
60
  const { layoutRef, layoutStyle, layoutProps } = useLayout({ props, hasSelfPercent, setWidth, setHeight, nodeRef: formRef })
61
61
 
62
- const innerProps = useInnerProps(props, extendObject({
63
- style: extendObject({}, innerStyle, layoutStyle),
64
- ref: formRef
65
- }, layoutProps)
66
- , [
67
- 'bindsubmit',
68
- 'bindreset'
69
- ], { layoutRef })
62
+ const innerProps = useInnerProps(
63
+ extendObject(
64
+ {},
65
+ props,
66
+ layoutProps,
67
+ {
68
+ style: extendObject({}, innerStyle, layoutStyle),
69
+ ref: formRef
70
+ }
71
+ )
72
+ , [
73
+ 'bindsubmit',
74
+ 'bindreset'
75
+ ], { layoutRef })
70
76
 
71
77
  const contextValue = useMemo(() => {
72
78
  const formValuesMap = new Map()
@@ -17,6 +17,7 @@ import Cancel from './icons/cancel.png'
17
17
  import Download from './icons/download.png'
18
18
  import Search from './icons/search.png'
19
19
  import Clear from './icons/clear.png'
20
+ import Portal from '../mpx-portal'
20
21
 
21
22
  export type IconType =
22
23
  | 'success'
@@ -75,6 +76,7 @@ const Icon = forwardRef<HandlerRef<Text, IconProps>, IconProps>(
75
76
  const styleObj = extendObject({}, defaultStyle, style)
76
77
 
77
78
  const {
79
+ hasPositionFixed,
78
80
  hasSelfPercent,
79
81
  normalStyle,
80
82
  setWidth,
@@ -87,14 +89,15 @@ const Icon = forwardRef<HandlerRef<Text, IconProps>, IconProps>(
87
89
  const { layoutRef, layoutStyle, layoutProps } = useLayout({ props, hasSelfPercent, setWidth, setHeight, nodeRef })
88
90
 
89
91
  const innerProps = useInnerProps(
90
- props,
91
92
  extendObject(
93
+ {},
94
+ props,
95
+ layoutProps,
92
96
  {
93
97
  ref: nodeRef,
94
98
  source,
95
99
  style: extendObject({}, normalStyle, layoutStyle, { tintColor: color })
96
- },
97
- layoutProps
100
+ }
98
101
  ),
99
102
  [],
100
103
  {
@@ -102,7 +105,13 @@ const Icon = forwardRef<HandlerRef<Text, IconProps>, IconProps>(
102
105
  }
103
106
  )
104
107
 
105
- return createElement(Image, innerProps)
108
+ const finalComponent = createElement(Image, innerProps)
109
+
110
+ if (hasPositionFixed) {
111
+ return createElement(Portal, null, finalComponent)
112
+ }
113
+
114
+ return finalComponent
106
115
  }
107
116
  )
108
117
 
@@ -27,6 +27,7 @@ import { SvgCssUri } from 'react-native-svg/css'
27
27
  import useInnerProps, { getCustomEvent } from './getInnerListeners'
28
28
  import useNodesRef, { HandlerRef } from './useNodesRef'
29
29
  import { SVG_REGEXP, useLayout, useTransformStyle, renderImage, extendObject } from './utils'
30
+ import Portal from './mpx-portal'
30
31
 
31
32
  export type Mode =
32
33
  | 'scaleToFill'
@@ -159,7 +160,13 @@ const Image = forwardRef<HandlerRef<RNImage, ImageProps>, ImageProps>((props, re
159
160
  }
160
161
  }
161
162
 
162
- const { normalStyle, hasSelfPercent, setWidth, setHeight } = useTransformStyle(styleObj, { enableVar, externalVarContext, parentFontSize, parentWidth, parentHeight })
163
+ const {
164
+ hasPositionFixed,
165
+ hasSelfPercent,
166
+ normalStyle,
167
+ setWidth,
168
+ setHeight
169
+ } = useTransformStyle(styleObj, { enableVar, externalVarContext, parentFontSize, parentWidth, parentHeight })
163
170
 
164
171
  const { layoutRef, layoutStyle, layoutProps } = useLayout({
165
172
  props,
@@ -356,31 +363,39 @@ const Image = forwardRef<HandlerRef<RNImage, ImageProps>, ImageProps>((props, re
356
363
 
357
364
  useEffect(() => {
358
365
  if (!isSvg && isLayoutMode) {
359
- RNImage.getSize(src, (width: number, height: number) => {
360
- state.current.imageWidth = width
361
- state.current.imageHeight = height
362
- state.current.ratio = !width ? 0 : height / width
363
-
364
- if (isWidthFixMode
365
- ? state.current.viewWidth
366
- : isHeightFixMode
367
- ? state.current.viewHeight
368
- : state.current.viewWidth && state.current.viewHeight) {
369
- state.current.viewWidth && setViewWidth(state.current.viewWidth)
370
- state.current.viewHeight && setViewHeight(state.current.viewHeight)
371
- setRatio(!width ? 0 : height / width)
372
- setImageWidth(width)
373
- setImageHeight(height)
374
- state.current = {}
366
+ RNImage.getSize(
367
+ src,
368
+ (width: number, height: number) => {
369
+ state.current.imageWidth = width
370
+ state.current.imageHeight = height
371
+ state.current.ratio = !width ? 0 : height / width
372
+
373
+ if (isWidthFixMode
374
+ ? state.current.viewWidth
375
+ : isHeightFixMode
376
+ ? state.current.viewHeight
377
+ : state.current.viewWidth && state.current.viewHeight) {
378
+ state.current.viewWidth && setViewWidth(state.current.viewWidth)
379
+ state.current.viewHeight && setViewHeight(state.current.viewHeight)
380
+ setRatio(!width ? 0 : height / width)
381
+ setImageWidth(width)
382
+ setImageHeight(height)
383
+ state.current = {}
384
+ setLoaded(true)
385
+ }
386
+ },
387
+ () => {
375
388
  setLoaded(true)
376
389
  }
377
- })
390
+ )
378
391
  }
379
392
  }, [src, isSvg, isLayoutMode])
380
393
 
381
394
  const innerProps = useInnerProps(
382
- props,
383
395
  extendObject(
396
+ {},
397
+ props,
398
+ layoutProps,
384
399
  {
385
400
  ref: nodeRef,
386
401
  style: extendObject(
@@ -390,8 +405,7 @@ const Image = forwardRef<HandlerRef<RNImage, ImageProps>, ImageProps>((props, re
390
405
  isHeightFixMode ? { width: fixedWidth } : {},
391
406
  isWidthFixMode ? { height: fixedHeight } : {}
392
407
  )
393
- },
394
- layoutProps
408
+ }
395
409
  ),
396
410
  [
397
411
  'src',
@@ -440,7 +454,13 @@ const Image = forwardRef<HandlerRef<RNImage, ImageProps>, ImageProps>((props, re
440
454
 
441
455
  const LayoutImage = createElement(View, innerProps, loaded && BaseImage)
442
456
 
443
- return isSvg ? SvgImage : isLayoutMode ? LayoutImage : BaseImage
457
+ const finalComponent = isSvg ? SvgImage : isLayoutMode ? LayoutImage : BaseImage
458
+
459
+ if (hasPositionFixed) {
460
+ return createElement(Portal, null, finalComponent)
461
+ }
462
+
463
+ return finalComponent
444
464
  })
445
465
 
446
466
  Image.displayName = 'mpx-image'
@@ -39,7 +39,6 @@
39
39
  */
40
40
  import { JSX, forwardRef, useRef, useState, useContext, useEffect, createElement } from 'react'
41
41
  import {
42
- Platform,
43
42
  TextInput,
44
43
  TextStyle,
45
44
  ViewStyle,
@@ -51,13 +50,15 @@ import {
51
50
  TextInputSelectionChangeEventData,
52
51
  TextInputFocusEventData,
53
52
  TextInputChangeEventData,
54
- TextInputSubmitEditingEventData
53
+ TextInputSubmitEditingEventData,
54
+ NativeTouchEvent
55
55
  } from 'react-native'
56
56
  import { warn } from '@mpxjs/utils'
57
57
  import { useUpdateEffect, useTransformStyle, useLayout, extendObject, isIOS } from './utils'
58
58
  import useInnerProps, { getCustomEvent } from './getInnerListeners'
59
59
  import useNodesRef, { HandlerRef } from './useNodesRef'
60
60
  import { FormContext, FormFieldValue, KeyboardAvoidContext } from './context'
61
+ import Portal from './mpx-portal'
61
62
 
62
63
  type InputStyle = Omit<
63
64
  TextStyle & ViewStyle & Pick<FlexStyle, 'minHeight'>,
@@ -191,7 +192,7 @@ const Input = forwardRef<HandlerRef<TextInput, FinalInputProps>, FinalInputProps
191
192
 
192
193
  const [inputValue, setInputValue] = useState(defaultValue)
193
194
  const [contentHeight, setContentHeight] = useState(0)
194
- const [selection, setSelection] = useState({ start: -1, end: -1 })
195
+ const [selection, setSelection] = useState({ start: -1, end: tmpValue.current.length })
195
196
 
196
197
  const styleObj = extendObject(
197
198
  { padding: 0, backgroundColor: '#fff' },
@@ -202,6 +203,7 @@ const Input = forwardRef<HandlerRef<TextInput, FinalInputProps>, FinalInputProps
202
203
  )
203
204
 
204
205
  const {
206
+ hasPositionFixed,
205
207
  hasSelfPercent,
206
208
  normalStyle,
207
209
  setWidth,
@@ -217,15 +219,17 @@ const Input = forwardRef<HandlerRef<TextInput, FinalInputProps>, FinalInputProps
217
219
 
218
220
  useEffect(() => {
219
221
  if (inputValue !== value) {
220
- setInputValue(parseValue(value))
222
+ const parsed = parseValue(value)
223
+ tmpValue.current = parsed
224
+ setInputValue(parsed)
221
225
  }
222
226
  }, [value])
223
227
 
224
228
  useEffect(() => {
225
- if (typeof cursor === 'number') {
229
+ if (selectionStart > -1) {
230
+ setSelection({ start: selectionStart, end: selectionEnd === -1 ? tmpValue.current.length : selectionEnd })
231
+ } else if (typeof cursor === 'number') {
226
232
  setSelection({ start: cursor, end: cursor })
227
- } else if (selectionStart >= 0 && selectionEnd >= 0 && selectionStart !== selectionEnd) {
228
- setSelection({ start: selectionStart, end: selectionEnd })
229
233
  }
230
234
  }, [cursor, selectionStart, selectionEnd])
231
235
 
@@ -286,6 +290,10 @@ const Input = forwardRef<HandlerRef<TextInput, FinalInputProps>, FinalInputProps
286
290
  setKeyboardAvoidContext()
287
291
  }
288
292
 
293
+ const onTouchEnd = (evt: NativeSyntheticEvent<NativeTouchEvent & { origin?: string }>) => {
294
+ evt.nativeEvent.origin = 'input'
295
+ }
296
+
289
297
  const onFocus = (evt: NativeSyntheticEvent<TextInputFocusEventData>) => {
290
298
  setKeyboardAvoidContext()
291
299
  bindfocus && bindfocus(
@@ -384,6 +392,7 @@ const Input = forwardRef<HandlerRef<TextInput, FinalInputProps>, FinalInputProps
384
392
  }
385
393
 
386
394
  const resetValue = () => {
395
+ tmpValue.current = ''
387
396
  setInputValue('')
388
397
  }
389
398
 
@@ -423,8 +432,10 @@ const Input = forwardRef<HandlerRef<TextInput, FinalInputProps>, FinalInputProps
423
432
  }, [focus])
424
433
 
425
434
  const innerProps = useInnerProps(
426
- props,
427
435
  extendObject(
436
+ {},
437
+ props,
438
+ layoutProps,
428
439
  {
429
440
  ref: nodeRef,
430
441
  style: extendObject({}, normalStyle, layoutStyle),
@@ -436,25 +447,23 @@ const Input = forwardRef<HandlerRef<TextInput, FinalInputProps>, FinalInputProps
436
447
  maxLength: maxlength === -1 ? undefined : maxlength,
437
448
  editable: !disabled,
438
449
  autoFocus: !!autoFocus || !!focus,
439
- selection: selection,
450
+ selection: selectionStart > -1 || typeof cursor === 'number' ? selection : undefined,
440
451
  selectionColor: cursorColor,
441
452
  blurOnSubmit: !multiline && !confirmHold,
442
453
  underlineColorAndroid: 'rgba(0,0,0,0)',
443
454
  textAlignVertical: textAlignVertical,
444
455
  placeholderTextColor: placeholderStyle?.color,
445
- multiline: !!multiline
446
- },
447
- !!multiline && confirmType === 'return' ? {} : { enterKeyHint: confirmType },
448
- layoutProps,
449
- {
456
+ multiline: !!multiline,
450
457
  onTouchStart,
458
+ onTouchEnd,
451
459
  onFocus,
452
460
  onBlur,
453
461
  onChange,
454
462
  onSelectionChange,
455
463
  onContentSizeChange,
456
464
  onSubmitEditing: bindconfirm && !multiline && onSubmitEditing
457
- }
465
+ },
466
+ !!multiline && confirmType === 'return' ? {} : { enterKeyHint: confirmType }
458
467
  ),
459
468
  [
460
469
  'type',
@@ -474,7 +483,14 @@ const Input = forwardRef<HandlerRef<TextInput, FinalInputProps>, FinalInputProps
474
483
  layoutRef
475
484
  }
476
485
  )
477
- return createElement(TextInput, innerProps)
486
+
487
+ const finalComponent = createElement(TextInput, innerProps)
488
+
489
+ if (hasPositionFixed) {
490
+ return createElement(Portal, null, finalComponent)
491
+ }
492
+
493
+ return finalComponent
478
494
  })
479
495
 
480
496
  Input.displayName = 'MpxInput'