@mpxjs/webpack-plugin 2.9.66 → 2.9.69-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (158) hide show
  1. package/lib/dependencies/RecordGlobalComponentsDependency.js +11 -12
  2. package/lib/dependencies/RecordRuntimeInfoDependency.js +1 -1
  3. package/lib/index.js +29 -8
  4. package/lib/json-compiler/index.js +2 -11
  5. package/lib/loader.js +24 -45
  6. package/lib/native-loader.js +49 -64
  7. package/lib/platform/json/wx/index.js +24 -18
  8. package/lib/platform/style/wx/index.js +49 -47
  9. package/lib/platform/template/wx/component-config/canvas.js +8 -0
  10. package/lib/platform/template/wx/component-config/fix-component-name.js +15 -12
  11. package/lib/platform/template/wx/component-config/index.js +1 -1
  12. package/lib/platform/template/wx/component-config/input.js +1 -1
  13. package/lib/platform/template/wx/component-config/rich-text.js +8 -0
  14. package/lib/platform/template/wx/component-config/swiper.js +1 -1
  15. package/lib/platform/template/wx/component-config/textarea.js +1 -1
  16. package/lib/platform/template/wx/component-config/unsupported.js +1 -1
  17. package/lib/react/index.js +4 -3
  18. package/lib/react/processJSON.js +5 -13
  19. package/lib/react/processMainScript.js +7 -3
  20. package/lib/react/processScript.js +3 -4
  21. package/lib/react/processStyles.js +14 -4
  22. package/lib/react/processTemplate.js +5 -2
  23. package/lib/resolver/AddModePlugin.js +20 -7
  24. package/lib/runtime/components/react/context.ts +6 -0
  25. package/lib/runtime/components/react/dist/context.js +2 -0
  26. package/lib/runtime/components/react/dist/event.config.js +24 -24
  27. package/lib/runtime/components/react/dist/getInnerListeners.js +183 -174
  28. package/lib/runtime/components/react/dist/mpx-button.jsx +78 -50
  29. package/lib/runtime/components/react/dist/mpx-canvas/Bus.js +60 -0
  30. package/lib/runtime/components/react/dist/mpx-canvas/CanvasGradient.js +15 -0
  31. package/lib/runtime/components/react/dist/mpx-canvas/CanvasRenderingContext2D.js +84 -0
  32. package/lib/runtime/components/react/dist/mpx-canvas/Image.js +87 -0
  33. package/lib/runtime/components/react/dist/mpx-canvas/ImageData.js +15 -0
  34. package/lib/runtime/components/react/dist/mpx-canvas/constructorsRegistry.js +28 -0
  35. package/lib/runtime/components/react/dist/mpx-canvas/html.js +343 -0
  36. package/lib/runtime/components/react/dist/mpx-canvas/index.jsx +232 -0
  37. package/lib/runtime/components/react/dist/mpx-canvas/utils.jsx +89 -0
  38. package/lib/runtime/components/react/dist/mpx-checkbox-group.jsx +41 -34
  39. package/lib/runtime/components/react/dist/mpx-checkbox.jsx +30 -39
  40. package/lib/runtime/components/react/dist/mpx-form.jsx +47 -41
  41. package/lib/runtime/components/react/dist/mpx-icon.jsx +9 -17
  42. package/lib/runtime/components/react/dist/mpx-image.jsx +291 -0
  43. package/lib/runtime/components/react/dist/mpx-input.jsx +95 -62
  44. package/lib/runtime/components/react/dist/mpx-label.jsx +24 -28
  45. package/lib/runtime/components/react/dist/mpx-movable-area.jsx +20 -30
  46. package/lib/runtime/components/react/dist/mpx-movable-view.jsx +377 -293
  47. package/lib/runtime/components/react/dist/mpx-navigator.jsx +3 -5
  48. package/lib/runtime/components/react/dist/mpx-picker/date.jsx +6 -2
  49. package/lib/runtime/components/react/dist/mpx-picker/index.jsx +5 -3
  50. package/lib/runtime/components/react/dist/mpx-picker/multiSelector.jsx +6 -2
  51. package/lib/runtime/components/react/dist/mpx-picker/region.jsx +6 -2
  52. package/lib/runtime/components/react/dist/mpx-picker/selector.jsx +6 -2
  53. package/lib/runtime/components/react/dist/mpx-picker/time.jsx +10 -15
  54. package/lib/runtime/components/react/dist/mpx-picker-view-column-item.jsx +39 -0
  55. package/lib/runtime/components/react/dist/mpx-picker-view-column.jsx +160 -88
  56. package/lib/runtime/components/react/dist/mpx-picker-view.jsx +80 -121
  57. package/lib/runtime/components/react/dist/mpx-radio-group.jsx +39 -34
  58. package/lib/runtime/components/react/dist/mpx-radio.jsx +28 -43
  59. package/lib/runtime/components/react/dist/mpx-rich-text/html.js +39 -0
  60. package/lib/runtime/components/react/dist/mpx-rich-text/index.jsx +63 -0
  61. package/lib/runtime/components/react/dist/mpx-root-portal.jsx +7 -5
  62. package/lib/runtime/components/react/dist/mpx-scroll-view.jsx +77 -51
  63. package/lib/runtime/components/react/dist/mpx-simple-text.jsx +11 -0
  64. package/lib/runtime/components/react/dist/mpx-swiper-item.jsx +5 -3
  65. package/lib/runtime/components/react/dist/mpx-swiper.jsx +606 -0
  66. package/lib/runtime/components/react/dist/mpx-switch.jsx +28 -11
  67. package/lib/runtime/components/react/dist/mpx-text.jsx +12 -11
  68. package/lib/runtime/components/react/dist/mpx-textarea.jsx +9 -4
  69. package/lib/runtime/components/react/dist/mpx-view.jsx +66 -62
  70. package/lib/runtime/components/react/dist/mpx-web-view.jsx +113 -36
  71. package/lib/runtime/components/react/dist/pickerFaces.js +81 -0
  72. package/lib/runtime/components/react/dist/pickerVIewContext.js +9 -0
  73. package/lib/runtime/components/react/dist/pickerViewMask.jsx +18 -0
  74. package/lib/runtime/components/react/dist/pickerViewOverlay.jsx +23 -0
  75. package/lib/runtime/components/react/dist/useAnimationHooks.js +126 -12
  76. package/lib/runtime/components/react/dist/utils.jsx +80 -24
  77. package/lib/runtime/components/react/event.config.ts +25 -26
  78. package/lib/runtime/components/react/getInnerListeners.ts +237 -198
  79. package/lib/runtime/components/react/mpx-button.tsx +105 -58
  80. package/lib/runtime/components/react/mpx-canvas/Bus.ts +70 -0
  81. package/lib/runtime/components/react/mpx-canvas/CanvasGradient.ts +18 -0
  82. package/lib/runtime/components/react/mpx-canvas/CanvasRenderingContext2D.ts +87 -0
  83. package/lib/runtime/components/react/mpx-canvas/Image.ts +102 -0
  84. package/lib/runtime/components/react/mpx-canvas/ImageData.ts +23 -0
  85. package/lib/runtime/components/react/mpx-canvas/constructorsRegistry.ts +38 -0
  86. package/lib/runtime/components/react/mpx-canvas/html.ts +343 -0
  87. package/lib/runtime/components/react/mpx-canvas/index.tsx +296 -0
  88. package/lib/runtime/components/react/mpx-canvas/utils.tsx +150 -0
  89. package/lib/runtime/components/react/mpx-checkbox-group.tsx +77 -51
  90. package/lib/runtime/components/react/mpx-checkbox.tsx +49 -50
  91. package/lib/runtime/components/react/mpx-form.tsx +62 -57
  92. package/lib/runtime/components/react/mpx-icon.tsx +13 -18
  93. package/lib/runtime/components/react/mpx-image.tsx +436 -0
  94. package/lib/runtime/components/react/mpx-input.tsx +139 -117
  95. package/lib/runtime/components/react/mpx-label.tsx +36 -34
  96. package/lib/runtime/components/react/mpx-movable-area.tsx +26 -39
  97. package/lib/runtime/components/react/mpx-movable-view.tsx +455 -337
  98. package/lib/runtime/components/react/mpx-navigator.tsx +3 -9
  99. package/lib/runtime/components/react/mpx-picker/date.tsx +5 -2
  100. package/lib/runtime/components/react/mpx-picker/index.tsx +3 -2
  101. package/lib/runtime/components/react/mpx-picker/multiSelector.tsx +5 -2
  102. package/lib/runtime/components/react/mpx-picker/region.tsx +5 -2
  103. package/lib/runtime/components/react/mpx-picker/selector.tsx +5 -2
  104. package/lib/runtime/components/react/mpx-picker/time.tsx +10 -15
  105. package/lib/runtime/components/react/mpx-picker/type.ts +48 -43
  106. package/lib/runtime/components/react/mpx-picker-view-column.tsx +236 -104
  107. package/lib/runtime/components/react/mpx-picker-view.tsx +132 -122
  108. package/lib/runtime/components/react/mpx-radio-group.tsx +77 -54
  109. package/lib/runtime/components/react/mpx-radio.tsx +46 -55
  110. package/lib/runtime/components/react/mpx-rich-text/html.ts +40 -0
  111. package/lib/runtime/components/react/mpx-rich-text/index.tsx +121 -0
  112. package/lib/runtime/components/react/mpx-root-portal.tsx +4 -6
  113. package/lib/runtime/components/react/mpx-scroll-view.tsx +122 -76
  114. package/lib/runtime/components/react/mpx-simple-text.tsx +18 -0
  115. package/lib/runtime/components/react/mpx-swiper/carouse.tsx +6 -4
  116. package/lib/runtime/components/react/mpx-swiper/index.tsx +2 -1
  117. package/lib/runtime/components/react/mpx-swiper-item.tsx +4 -3
  118. package/lib/runtime/components/react/mpx-switch.tsx +39 -25
  119. package/lib/runtime/components/react/mpx-text.tsx +15 -19
  120. package/lib/runtime/components/react/mpx-textarea.tsx +12 -11
  121. package/lib/runtime/components/react/mpx-view.tsx +93 -77
  122. package/lib/runtime/components/react/mpx-web-view.tsx +117 -55
  123. package/lib/runtime/components/react/pickerFaces.ts +104 -0
  124. package/lib/runtime/components/react/pickerOverlay.tsx +32 -0
  125. package/lib/runtime/components/react/types/common.ts +2 -0
  126. package/lib/runtime/components/react/types/global.d.ts +5 -17
  127. package/lib/runtime/components/react/useAnimationHooks.ts +127 -18
  128. package/lib/runtime/components/react/useNodesRef.ts +1 -0
  129. package/lib/runtime/components/react/utils.tsx +113 -27
  130. package/lib/runtime/components/web/getInnerListeners.js +6 -6
  131. package/lib/runtime/components/web/mpx-movable-view.vue +334 -344
  132. package/lib/runtime/components/web/mpx-picker-view-column.vue +75 -75
  133. package/lib/runtime/components/web/mpx-picker.vue +382 -385
  134. package/lib/runtime/components/web/mpx-web-view.vue +175 -161
  135. package/lib/runtime/optionProcessor.js +7 -38
  136. package/lib/runtime/optionProcessorReact.js +0 -15
  137. package/lib/runtime/swanHelper.wxs +1 -1
  138. package/lib/runtime/utils.js +2 -0
  139. package/lib/style-compiler/index.js +1 -1
  140. package/lib/style-compiler/plugins/scope-id.js +31 -2
  141. package/lib/template-compiler/bind-this.js +7 -2
  142. package/lib/template-compiler/compiler.js +118 -56
  143. package/lib/template-compiler/gen-node-react.js +3 -3
  144. package/lib/template-compiler/index.js +4 -4
  145. package/lib/utils/pre-process-json.js +117 -0
  146. package/lib/web/index.js +5 -4
  147. package/lib/web/processJSON.js +5 -13
  148. package/lib/web/processTemplate.js +2 -2
  149. package/package.json +6 -4
  150. package/LICENSE +0 -433
  151. package/lib/runtime/components/react/dist/mpx-image/index.jsx +0 -226
  152. package/lib/runtime/components/react/dist/mpx-image/svg.jsx +0 -7
  153. package/lib/runtime/components/react/dist/mpx-swiper/carouse.jsx +0 -478
  154. package/lib/runtime/components/react/dist/mpx-swiper/index.jsx +0 -68
  155. package/lib/runtime/components/react/dist/mpx-swiper/type.js +0 -1
  156. package/lib/runtime/components/react/mpx-image/index.tsx +0 -346
  157. package/lib/runtime/components/react/mpx-image/svg.tsx +0 -22
  158. package/lib/runtime/components/web/event.js +0 -105
@@ -4,15 +4,15 @@
4
4
  * ✔ disabled
5
5
  * ✔ color
6
6
  */
7
- import { Switch, SwitchProps, ViewStyle, NativeSyntheticEvent, LayoutChangeEvent } from 'react-native'
8
- import { useRef, useEffect, forwardRef, JSX, useState, useContext } from 'react'
7
+ import { Switch, SwitchProps, ViewStyle, NativeSyntheticEvent } from 'react-native'
8
+ import { useRef, useEffect, forwardRef, JSX, useState, useContext, createElement } from 'react'
9
9
  import { warn } from '@mpxjs/utils'
10
10
  import useNodesRef, { HandlerRef } from './useNodesRef' // 引入辅助函数
11
11
  import useInnerProps, { getCustomEvent } from './getInnerListeners'
12
12
 
13
13
  import CheckBox from './mpx-checkbox'
14
14
  import { FormContext, FormFieldValue } from './context'
15
- import { useTransformStyle, useLayout } from './utils'
15
+ import { useTransformStyle, useLayout, extendObject } from './utils'
16
16
 
17
17
  interface _SwitchProps extends SwitchProps {
18
18
  style?: ViewStyle
@@ -42,7 +42,6 @@ const _Switch = forwardRef<HandlerRef<Switch, _SwitchProps>, _SwitchProps>((prop
42
42
  'parent-font-size': parentFontSize,
43
43
  'parent-width': parentWidth,
44
44
  'parent-height': parentHeight,
45
-
46
45
  bindchange,
47
46
  catchchange
48
47
  } = props
@@ -77,7 +76,9 @@ const _Switch = forwardRef<HandlerRef<Switch, _SwitchProps>, _SwitchProps>((prop
77
76
  }, [checked])
78
77
 
79
78
  const nodeRef = useRef(null)
80
- useNodesRef<Switch, _SwitchProps>(props, ref, nodeRef)
79
+ useNodesRef<Switch, _SwitchProps>(props, ref, nodeRef, {
80
+ style: normalStyle
81
+ })
81
82
 
82
83
  const {
83
84
  layoutRef,
@@ -111,12 +112,21 @@ const _Switch = forwardRef<HandlerRef<Switch, _SwitchProps>, _SwitchProps>((prop
111
112
  }
112
113
  }
113
114
 
114
- const innerProps = useInnerProps(props, {
115
+ useEffect(() => {
116
+ return () => {
117
+ if (formValuesMap && props.name) {
118
+ formValuesMap.delete(props.name)
119
+ }
120
+ }
121
+ }, [])
122
+
123
+ const innerProps = useInnerProps(props, extendObject({
115
124
  ref: nodeRef,
116
- style: { ...normalStyle, ...layoutStyle },
117
- ...layoutProps,
118
- ...!disabled ? { [type === 'switch' ? 'onValueChange' : '_onChange']: onChange } : {}
119
- }, [
125
+ style: extendObject({}, normalStyle, layoutStyle)
126
+ },
127
+ layoutProps,
128
+ !disabled ? { [type === 'switch' ? 'onValueChange' : '_onChange']: onChange } : {})
129
+ , [
120
130
  'checked',
121
131
  'disabled',
122
132
  'type',
@@ -126,24 +136,28 @@ const _Switch = forwardRef<HandlerRef<Switch, _SwitchProps>, _SwitchProps>((prop
126
136
  })
127
137
 
128
138
  if (type === 'checkbox') {
129
- return <CheckBox
130
- {...innerProps}
131
- color={color}
132
- style={normalStyle}
133
- checked={isChecked}
134
- />
139
+ return createElement(
140
+ CheckBox,
141
+ extendObject({}, innerProps, {
142
+ color: color,
143
+ style: normalStyle,
144
+ checked: isChecked
145
+ })
146
+ )
135
147
  }
136
148
 
137
- return <Switch
138
- {...innerProps}
139
- style={normalStyle}
140
- value={isChecked}
141
- trackColor={{ false: '#FFF', true: color }}
142
- thumbColor={isChecked ? '#FFF' : '#f4f3f4'}
143
- ios_backgroundColor="#FFF"
144
- />
149
+ return createElement(
150
+ Switch,
151
+ extendObject({}, innerProps, {
152
+ style: normalStyle,
153
+ value: isChecked,
154
+ trackColor: { false: '#FFF', true: color },
155
+ thumbColor: isChecked ? '#FFF' : '#f4f3f4',
156
+ ios_backgroundColor: '#FFF'
157
+ })
158
+ )
145
159
  })
146
160
 
147
- _Switch.displayName = 'mpx-switch'
161
+ _Switch.displayName = 'MpxSwitch'
148
162
 
149
163
  export default _Switch
@@ -5,7 +5,7 @@
5
5
  * ✘ decode
6
6
  */
7
7
  import { Text, TextStyle, TextProps } from 'react-native'
8
- import { useRef, forwardRef, ReactNode, JSX } from 'react'
8
+ import { useRef, forwardRef, ReactNode, JSX, createElement } from 'react'
9
9
  import useInnerProps from './getInnerListeners'
10
10
  import useNodesRef, { HandlerRef } from './useNodesRef' // 引入辅助函数
11
11
  import { useTransformStyle, wrapChildren } from './utils'
@@ -25,6 +25,7 @@ interface _TextProps extends TextProps {
25
25
  const _Text = forwardRef<HandlerRef<Text, _TextProps>, _TextProps>((props, ref): JSX.Element => {
26
26
  const {
27
27
  style = {},
28
+ allowFontScaling = false,
28
29
  selectable,
29
30
  'enable-var': enableVar,
30
31
  'external-var-context': externalVarContext,
@@ -49,35 +50,30 @@ const _Text = forwardRef<HandlerRef<Text, _TextProps>, _TextProps>((props, ref):
49
50
  })
50
51
 
51
52
  const nodeRef = useRef(null)
52
- useNodesRef<Text, _TextProps>(props, ref, nodeRef)
53
+ useNodesRef<Text, _TextProps>(props, ref, nodeRef, {
54
+ style: normalStyle
55
+ })
53
56
 
54
57
  const innerProps = useInnerProps(props, {
55
58
  ref: nodeRef,
56
59
  style: normalStyle,
57
- selectable: !!selectable || !!userSelect
60
+ selectable: !!selectable || !!userSelect,
61
+ allowFontScaling
58
62
  }, [
59
63
  'user-select'
60
64
  ], {
61
65
  layoutRef
62
66
  })
63
67
 
64
- return (
65
- <Text
66
- {...innerProps}
67
- >
68
- {
69
- wrapChildren(
70
- props,
71
- {
72
- hasVarDec,
73
- varContext: varContextRef.current
74
- }
75
- )
76
- }
77
- </Text>
78
- )
68
+ return createElement(Text, innerProps, wrapChildren(
69
+ props,
70
+ {
71
+ hasVarDec,
72
+ varContext: varContextRef.current
73
+ }
74
+ ))
79
75
  })
80
76
 
81
- _Text.displayName = 'mpx-text'
77
+ _Text.displayName = 'MpxText'
82
78
 
83
79
  export default _Text
@@ -9,10 +9,10 @@
9
9
  * ✘ show-confirm-bar
10
10
  * ✔ bindlinechange: No `heightRpx` info.
11
11
  */
12
- import { JSX, forwardRef } from 'react'
12
+ import { JSX, forwardRef, createElement } from 'react'
13
13
  import { Keyboard, TextInput } from 'react-native'
14
14
  import Input, { InputProps, PrivateInputProps } from './mpx-input'
15
- import { omit } from './utils'
15
+ import { omit, extendObject } from './utils'
16
16
  import { HandlerRef } from './useNodesRef'
17
17
 
18
18
  export type TextareProps = Omit<
@@ -29,18 +29,19 @@ const Textarea = forwardRef<HandlerRef<TextInput, TextareProps>, TextareProps>(
29
29
  'multiline',
30
30
  'confirm-hold'
31
31
  ])
32
- return (
33
- <Input
34
- ref={ref}
35
- multiline
36
- confirm-type='next'
37
- bindblur={() => Keyboard.dismiss()}
38
- {...restProps}
39
- />
32
+
33
+ return createElement(
34
+ Input,
35
+ extendObject({
36
+ ref: ref,
37
+ multiline: true,
38
+ confirmType: 'next',
39
+ bindblur: () => Keyboard.dismiss()
40
+ }, restProps)
40
41
  )
41
42
  }
42
43
  )
43
44
 
44
- Textarea.displayName = 'mpx-textarea'
45
+ Textarea.displayName = 'MpxTextarea'
45
46
 
46
47
  export default Textarea
@@ -4,15 +4,16 @@
4
4
  * ✔ hover-start-time
5
5
  * ✔ hover-stay-time
6
6
  */
7
- import { View, TextStyle, NativeSyntheticEvent, ViewProps, ImageStyle, ImageResizeMode, StyleSheet, Image, LayoutChangeEvent, Text } from 'react-native'
8
- import { useRef, useState, useEffect, forwardRef, ReactNode, JSX, Children, cloneElement } from 'react'
7
+ import { View, TextStyle, NativeSyntheticEvent, ViewProps, ImageStyle, StyleSheet, Image, LayoutChangeEvent } from 'react-native'
8
+ import { useRef, useState, useEffect, forwardRef, ReactNode, JSX, createElement } from 'react'
9
9
  import useInnerProps from './getInnerListeners'
10
10
  import Animated from 'react-native-reanimated'
11
11
  import useAnimationHooks from './useAnimationHooks'
12
12
  import type { AnimationProp } from './useAnimationHooks'
13
13
  import { ExtendedViewStyle } from './types/common'
14
14
  import useNodesRef, { HandlerRef } from './useNodesRef'
15
- import { parseUrl, PERCENT_REGEX, splitStyle, splitProps, useTransformStyle, wrapChildren, useLayout } from './utils'
15
+ import { parseUrl, PERCENT_REGEX, splitStyle, splitProps, useTransformStyle, wrapChildren, useLayout, renderImage, pickStyle, extendObject } from './utils'
16
+ import { error } from '@mpxjs/utils'
16
17
  import LinearGradient from 'react-native-linear-gradient'
17
18
 
18
19
  export interface _ViewProps extends ViewProps {
@@ -24,6 +25,7 @@ export interface _ViewProps extends ViewProps {
24
25
  'hover-stay-time'?: number
25
26
  'enable-background'?: boolean
26
27
  'enable-var'?: boolean
28
+ 'enable-fast-image'?: boolean
27
29
  'external-var-context'?: Record<string, any>
28
30
  'parent-font-size'?: number
29
31
  'parent-width'?: number
@@ -76,9 +78,11 @@ type PreImageInfo = {
76
78
  type ImageProps = {
77
79
  style: ImageStyle,
78
80
  src?: string,
81
+ source?: {uri: string },
79
82
  colors: Array<string>,
80
83
  locations?: Array<number>
81
84
  angle?: number
85
+ resizeMode?: 'cover' | 'stretch'
82
86
  }
83
87
 
84
88
  const linearMap = new Map([
@@ -233,10 +237,7 @@ function backgroundPosition (imageProps: ImageProps, preImageInfo: PreImageInfo,
233
237
  }
234
238
  }
235
239
 
236
- imageProps.style = {
237
- ...imageProps.style as ImageStyle,
238
- ...style
239
- }
240
+ extendObject(imageProps.style, style)
240
241
  }
241
242
 
242
243
  // background-size 转换
@@ -280,24 +281,23 @@ function backgroundSize (imageProps: ImageProps, preImageInfo: PreImageInfo, ima
280
281
  if (!dimensions) return
281
282
  } else { // 数值类型 ImageStyle
282
283
  // 数值类型设置为 stretch
283
- (imageProps.style as ImageStyle).resizeMode = 'stretch'
284
+ imageProps.resizeMode = 'stretch'
284
285
  dimensions = {
285
286
  width: isPercent(width) ? width : +width,
286
287
  height: isPercent(height) ? height : +height
287
288
  } as { width: NumberVal, height: NumberVal }
288
289
  }
289
290
  }
291
+
290
292
  // 样式合并
291
- imageProps.style = {
292
- ...imageProps.style as ImageStyle,
293
- ...dimensions
294
- }
293
+ extendObject(imageProps.style, dimensions)
295
294
  }
296
295
 
297
296
  // background-image转换为source
298
297
  function backgroundImage (imageProps: ImageProps, preImageInfo: PreImageInfo) {
299
- if (preImageInfo.src) {
300
- imageProps.src = preImageInfo.src
298
+ const src = preImageInfo.src
299
+ if (src) {
300
+ imageProps.source = { uri: src }
301
301
  }
302
302
  }
303
303
 
@@ -326,8 +326,8 @@ function linearGradient (imageProps: ImageProps, preImageInfo: PreImageInfo, ima
326
326
  const imageStyleToProps = (preImageInfo: PreImageInfo, imageSize: Size, layoutInfo: Size) => {
327
327
  // 初始化
328
328
  const imageProps: ImageProps = {
329
+ resizeMode: 'cover',
329
330
  style: {
330
- resizeMode: 'cover' as ImageResizeMode,
331
331
  position: 'absolute'
332
332
  // ...StyleSheet.absoluteFillObject
333
333
  },
@@ -476,10 +476,9 @@ function parseLinearGradient (text: string): LinearInfo | undefined {
476
476
  return prev
477
477
  }, { colors: [], locations: [] })
478
478
 
479
- return {
480
- ...linearInfo,
479
+ return extendObject({}, linearInfo, {
481
480
  direction: direction.trim()
482
- }
481
+ })
483
482
  }
484
483
 
485
484
  function parseBgImage (text: string): {
@@ -533,7 +532,26 @@ function isDiagonalAngle (linearInfo?: LinearInfo): boolean {
533
532
  return !!(linearInfo?.direction && diagonalAngleMap[linearInfo.direction])
534
533
  }
535
534
 
536
- function wrapImage (imageStyle?: ExtendedViewStyle) {
535
+ function inheritStyle (innerStyle: ExtendedViewStyle = {}) {
536
+ const { borderWidth, borderRadius } = innerStyle
537
+ const borderStyles = ['borderRadius', 'borderTopLeftRadius', 'borderTopRightRadius', 'borderBottomRightRadius', 'borderBottomLeftRadius']
538
+ return pickStyle(innerStyle,
539
+ borderStyles,
540
+ borderWidth && borderRadius
541
+ ? (key, val) => {
542
+ // 盒子内圆角borderWith与borderRadius的关系
543
+ // 当borderRadius 小于 当borderWith 内边框为直角
544
+ // 当borderRadius 大于等于 当borderWith 内边框为圆角
545
+ if (borderStyles.includes(key)) {
546
+ const borderVal = +val - borderWidth
547
+ return borderVal > 0 ? borderVal : 0
548
+ }
549
+ return val
550
+ }
551
+ : undefined)
552
+ }
553
+
554
+ function wrapImage (imageStyle?: ExtendedViewStyle, innerStyle?: Record<string, any>, enableFastImage?: boolean) {
537
555
  // 预处理数据
538
556
  const preImageInfo: PreImageInfo = preParseImage(imageStyle)
539
557
  // 预解析
@@ -616,9 +634,9 @@ function wrapImage (imageStyle?: ExtendedViewStyle) {
616
634
  }
617
635
  }
618
636
 
619
- return <View key='backgroundImage' {...needLayout ? { onLayout } : null} style={{ ...StyleSheet.absoluteFillObject, overflow: 'hidden' }}>
637
+ return <View key='backgroundImage' {...needLayout ? { onLayout } : null} style={{ ...inheritStyle(innerStyle), ...StyleSheet.absoluteFillObject, overflow: 'hidden' }}>
620
638
  {show && type === 'linear' && <LinearGradient useAngle={true} {...imageStyleToProps(preImageInfo, sizeInfo.current as Size, layoutInfo.current as Size)} /> }
621
- {show && type === 'image' && <Image {...imageStyleToProps(preImageInfo, sizeInfo.current as Size, layoutInfo.current as Size)} />}
639
+ {show && type === 'image' && (renderImage(imageStyleToProps(preImageInfo, sizeInfo.current as Size, layoutInfo.current as Size), enableFastImage))}
622
640
  </View>
623
641
  }
624
642
 
@@ -629,9 +647,11 @@ interface WrapChildrenConfig {
629
647
  backgroundStyle?: ExtendedViewStyle
630
648
  varContext?: Record<string, any>
631
649
  textProps?: Record<string, any>
650
+ innerStyle?: Record<string, any>
651
+ enableFastImage?: boolean
632
652
  }
633
653
 
634
- function wrapWithChildren (props: _ViewProps, { hasVarDec, enableBackground, textStyle, backgroundStyle, varContext, textProps }: WrapChildrenConfig) {
654
+ function wrapWithChildren (props: _ViewProps, { hasVarDec, enableBackground, textStyle, backgroundStyle, varContext, textProps, innerStyle, enableFastImage }: WrapChildrenConfig) {
635
655
  const children = wrapChildren(props, {
636
656
  hasVarDec,
637
657
  varContext,
@@ -640,7 +660,7 @@ function wrapWithChildren (props: _ViewProps, { hasVarDec, enableBackground, tex
640
660
  })
641
661
 
642
662
  return [
643
- enableBackground ? wrapImage(backgroundStyle) : null,
663
+ enableBackground ? wrapImage(backgroundStyle, innerStyle, enableFastImage) : null,
644
664
  children
645
665
  ]
646
666
  }
@@ -655,6 +675,7 @@ const _View = forwardRef<HandlerRef<View, _ViewProps>, _ViewProps>((viewProps, r
655
675
  'enable-var': enableVar,
656
676
  'external-var-context': externalVarContext,
657
677
  'enable-background': enableBackground,
678
+ 'enable-fast-image': enableFastImage,
658
679
  'enable-animation': enableAnimation,
659
680
  'parent-font-size': parentFontSize,
660
681
  'parent-width': parentWidth,
@@ -665,21 +686,16 @@ const _View = forwardRef<HandlerRef<View, _ViewProps>, _ViewProps>((viewProps, r
665
686
  const [isHover, setIsHover] = useState(false)
666
687
 
667
688
  // 默认样式
668
- const defaultStyle: ExtendedViewStyle = {
669
- // flex 布局相关的默认样式
670
- ...style.display === 'flex' && {
671
- flexDirection: 'row',
672
- flexBasis: 'auto',
673
- flexShrink: 1,
674
- flexWrap: 'nowrap'
675
- }
676
- }
689
+ const defaultStyle: ExtendedViewStyle = style.display === 'flex'
690
+ ? {
691
+ flexDirection: 'row',
692
+ flexBasis: 'auto',
693
+ flexShrink: 1,
694
+ flexWrap: 'nowrap'
695
+ }
696
+ : {}
677
697
 
678
- const styleObj: ExtendedViewStyle = {
679
- ...defaultStyle,
680
- ...style,
681
- ...(isHover ? hoverStyle : null)
682
- }
698
+ const styleObj: ExtendedViewStyle = extendObject({}, defaultStyle, style, isHover ? hoverStyle as ExtendedViewStyle : {})
683
699
 
684
700
  const {
685
701
  normalStyle,
@@ -696,17 +712,17 @@ const _View = forwardRef<HandlerRef<View, _ViewProps>, _ViewProps>((viewProps, r
696
712
  parentHeight
697
713
  })
698
714
 
699
- const { textStyle, backgroundStyle, innerStyle } = splitStyle(normalStyle)
715
+ const { textStyle, backgroundStyle, innerStyle = {} } = splitStyle(normalStyle)
700
716
 
701
717
  enableBackground = enableBackground || !!backgroundStyle
702
718
  const enableBackgroundRef = useRef(enableBackground)
703
719
  if (enableBackgroundRef.current !== enableBackground) {
704
- throw new Error('[Mpx runtime error]: background use should be stable in the component lifecycle, or you can set [enable-background] with true.')
720
+ error('[Mpx runtime error]: background use should be stable in the component lifecycle, or you can set [enable-background] with true.')
705
721
  }
706
722
 
707
723
  const nodeRef = useRef(null)
708
724
  useNodesRef<View, _ViewProps>(props, ref, nodeRef, {
709
- defaultStyle
725
+ style: normalStyle
710
726
  })
711
727
 
712
728
  const dataRef = useRef<{
@@ -754,57 +770,57 @@ const _View = forwardRef<HandlerRef<View, _ViewProps>, _ViewProps>((viewProps, r
754
770
  layoutProps
755
771
  } = useLayout({ props, hasSelfPercent, setWidth, setHeight, nodeRef })
756
772
 
757
- const viewStyle = Object.assign({}, innerStyle, layoutStyle)
758
- const innerProps = useInnerProps(props, {
759
- ref: nodeRef,
760
- style: viewStyle,
761
- ...layoutProps,
762
- ...(hoverStyle && {
763
- bindtouchstart: onTouchStart,
764
- bindtouchend: onTouchEnd
765
- })
766
- }, [
767
- 'hover-start-time',
768
- 'hover-stay-time',
769
- 'hover-style',
770
- 'hover-class'
771
- ], {
772
- layoutRef
773
- })
773
+ const viewStyle = extendObject({}, innerStyle, layoutStyle)
774
774
 
775
775
  enableAnimation = enableAnimation || !!animation
776
776
  const enableAnimationRef = useRef(enableAnimation)
777
777
  if (enableAnimationRef.current !== enableAnimation) {
778
- throw new Error('[Mpx runtime error]: animation use should be stable in the component lifecycle, or you can set [enable-animation] with true.')
778
+ error('[Mpx runtime error]: animation use should be stable in the component lifecycle, or you can set [enable-animation] with true.')
779
779
  }
780
- const finalStyle = enableAnimation
781
- ? useAnimationHooks({
782
- animation,
783
- style: viewStyle
784
- })
780
+ const finalStyle = enableAnimationRef.current
781
+ ? [viewStyle, useAnimationHooks({
782
+ animation,
783
+ style: viewStyle
784
+ })]
785
785
  : viewStyle
786
+ const innerProps = useInnerProps(
787
+ props,
788
+ extendObject({
789
+ ref: nodeRef,
790
+ style: finalStyle
791
+ },
792
+ layoutProps,
793
+ hoverStyle
794
+ ? {
795
+ bindtouchstart: onTouchStart,
796
+ bindtouchend: onTouchEnd
797
+ }
798
+ : {}
799
+ ), [
800
+ 'hover-start-time',
801
+ 'hover-stay-time',
802
+ 'hover-style',
803
+ 'hover-class'
804
+ ], {
805
+ layoutRef
806
+ })
807
+
786
808
  const childNode = wrapWithChildren(props, {
787
809
  hasVarDec,
788
810
  enableBackground: enableBackgroundRef.current,
789
811
  textStyle,
790
812
  backgroundStyle,
791
813
  varContext: varContextRef.current,
792
- textProps
814
+ textProps,
815
+ innerStyle,
816
+ enableFastImage
793
817
  })
794
- return animation?.actions?.length
795
- ? (<Animated.View
796
- {...innerProps}
797
- style={finalStyle}
798
- >
799
- {childNode}
800
- </Animated.View>)
801
- : (<View
802
- {...innerProps}
803
- >
804
- {childNode}
805
- </View>)
818
+
819
+ return enableAnimation
820
+ ? createElement(Animated.View, innerProps, childNode)
821
+ : createElement(View, innerProps, childNode)
806
822
  })
807
823
 
808
- _View.displayName = 'mpx-view'
824
+ _View.displayName = 'MpxView'
809
825
 
810
826
  export default _View