@mpxjs/webpack-plugin 2.9.67 → 2.9.69-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 (150) hide show
  1. package/lib/index.js +30 -9
  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/canvas.js +8 -0
  5. package/lib/platform/template/wx/component-config/fix-component-name.js +15 -12
  6. package/lib/platform/template/wx/component-config/index.js +1 -1
  7. package/lib/platform/template/wx/component-config/input.js +1 -1
  8. package/lib/platform/template/wx/component-config/movable-view.js +8 -1
  9. package/lib/platform/template/wx/component-config/rich-text.js +8 -0
  10. package/lib/platform/template/wx/component-config/scroll-view.js +1 -1
  11. package/lib/platform/template/wx/component-config/swiper.js +1 -1
  12. package/lib/platform/template/wx/component-config/textarea.js +1 -1
  13. package/lib/platform/template/wx/component-config/unsupported.js +1 -1
  14. package/lib/react/processStyles.js +14 -4
  15. package/lib/react/processTemplate.js +3 -0
  16. package/lib/resolver/AddEnvPlugin.js +1 -0
  17. package/lib/resolver/AddModePlugin.js +9 -8
  18. package/lib/runtime/components/react/context.ts +14 -0
  19. package/lib/runtime/components/react/dist/context.js +4 -0
  20. package/lib/runtime/components/react/dist/event.config.js +24 -24
  21. package/lib/runtime/components/react/dist/getInnerListeners.js +183 -175
  22. package/lib/runtime/components/react/dist/mpx-button.jsx +77 -49
  23. package/lib/runtime/components/react/dist/mpx-canvas/Bus.js +60 -0
  24. package/lib/runtime/components/react/dist/mpx-canvas/CanvasGradient.js +15 -0
  25. package/lib/runtime/components/react/dist/mpx-canvas/CanvasRenderingContext2D.js +84 -0
  26. package/lib/runtime/components/react/dist/mpx-canvas/Image.js +87 -0
  27. package/lib/runtime/components/react/dist/mpx-canvas/ImageData.js +15 -0
  28. package/lib/runtime/components/react/dist/mpx-canvas/constructorsRegistry.js +28 -0
  29. package/lib/runtime/components/react/dist/mpx-canvas/html.js +343 -0
  30. package/lib/runtime/components/react/dist/mpx-canvas/index.jsx +232 -0
  31. package/lib/runtime/components/react/dist/mpx-canvas/utils.jsx +89 -0
  32. package/lib/runtime/components/react/dist/mpx-checkbox-group.jsx +13 -19
  33. package/lib/runtime/components/react/dist/mpx-checkbox.jsx +29 -38
  34. package/lib/runtime/components/react/dist/mpx-form.jsx +16 -19
  35. package/lib/runtime/components/react/dist/mpx-icon.jsx +8 -16
  36. package/lib/runtime/components/react/dist/mpx-image.jsx +291 -0
  37. package/lib/runtime/components/react/dist/mpx-input.jsx +54 -27
  38. package/lib/runtime/components/react/dist/mpx-label.jsx +15 -22
  39. package/lib/runtime/components/react/dist/mpx-movable-area.jsx +13 -16
  40. package/lib/runtime/components/react/dist/mpx-movable-view.jsx +14 -14
  41. package/lib/runtime/components/react/dist/mpx-navigator.jsx +2 -4
  42. package/lib/runtime/components/react/dist/mpx-picker/date.jsx +6 -2
  43. package/lib/runtime/components/react/dist/mpx-picker/index.jsx +5 -3
  44. package/lib/runtime/components/react/dist/mpx-picker/multiSelector.jsx +6 -2
  45. package/lib/runtime/components/react/dist/mpx-picker/region.jsx +6 -2
  46. package/lib/runtime/components/react/dist/mpx-picker/selector.jsx +6 -2
  47. package/lib/runtime/components/react/dist/mpx-picker/time.jsx +10 -15
  48. package/lib/runtime/components/react/dist/mpx-picker-view-column-item.jsx +39 -0
  49. package/lib/runtime/components/react/dist/mpx-picker-view-column.jsx +171 -88
  50. package/lib/runtime/components/react/dist/mpx-picker-view.jsx +80 -121
  51. package/lib/runtime/components/react/dist/mpx-radio-group.jsx +11 -19
  52. package/lib/runtime/components/react/dist/mpx-radio.jsx +27 -42
  53. package/lib/runtime/components/react/dist/mpx-rich-text/html.js +39 -0
  54. package/lib/runtime/components/react/dist/mpx-rich-text/index.jsx +62 -0
  55. package/lib/runtime/components/react/dist/mpx-root-portal.jsx +6 -4
  56. package/lib/runtime/components/react/dist/mpx-scroll-view.jsx +53 -42
  57. package/lib/runtime/components/react/dist/mpx-simple-text.jsx +11 -0
  58. package/lib/runtime/components/react/dist/mpx-swiper-item.jsx +28 -9
  59. package/lib/runtime/components/react/dist/mpx-swiper.jsx +608 -0
  60. package/lib/runtime/components/react/dist/mpx-switch.jsx +20 -10
  61. package/lib/runtime/components/react/dist/mpx-text.jsx +11 -10
  62. package/lib/runtime/components/react/dist/mpx-textarea.jsx +8 -3
  63. package/lib/runtime/components/react/dist/mpx-view.jsx +67 -94
  64. package/lib/runtime/components/react/dist/mpx-web-view.jsx +152 -37
  65. package/lib/runtime/components/react/dist/pickerFaces.js +81 -0
  66. package/lib/runtime/components/react/dist/pickerVIewContext.js +9 -0
  67. package/lib/runtime/components/react/dist/pickerViewMask.jsx +18 -0
  68. package/lib/runtime/components/react/dist/pickerViewOverlay.jsx +23 -0
  69. package/lib/runtime/components/react/dist/useAnimationHooks.js +36 -10
  70. package/lib/runtime/components/react/dist/utils.jsx +129 -24
  71. package/lib/runtime/components/react/event.config.ts +25 -26
  72. package/lib/runtime/components/react/getInnerListeners.ts +238 -202
  73. package/lib/runtime/components/react/mpx-button.tsx +104 -57
  74. package/lib/runtime/components/react/mpx-canvas/Bus.ts +70 -0
  75. package/lib/runtime/components/react/mpx-canvas/CanvasGradient.ts +18 -0
  76. package/lib/runtime/components/react/mpx-canvas/CanvasRenderingContext2D.ts +87 -0
  77. package/lib/runtime/components/react/mpx-canvas/Image.ts +102 -0
  78. package/lib/runtime/components/react/mpx-canvas/ImageData.ts +23 -0
  79. package/lib/runtime/components/react/mpx-canvas/constructorsRegistry.ts +38 -0
  80. package/lib/runtime/components/react/mpx-canvas/html.ts +343 -0
  81. package/lib/runtime/components/react/mpx-canvas/index.tsx +296 -0
  82. package/lib/runtime/components/react/mpx-canvas/utils.tsx +150 -0
  83. package/lib/runtime/components/react/mpx-checkbox-group.tsx +28 -25
  84. package/lib/runtime/components/react/mpx-checkbox.tsx +48 -49
  85. package/lib/runtime/components/react/mpx-form.tsx +25 -28
  86. package/lib/runtime/components/react/mpx-icon.tsx +12 -17
  87. package/lib/runtime/components/react/mpx-image.tsx +436 -0
  88. package/lib/runtime/components/react/mpx-input.tsx +77 -57
  89. package/lib/runtime/components/react/mpx-label.tsx +26 -27
  90. package/lib/runtime/components/react/mpx-movable-area.tsx +18 -23
  91. package/lib/runtime/components/react/mpx-movable-view.tsx +22 -26
  92. package/lib/runtime/components/react/mpx-navigator.tsx +2 -8
  93. package/lib/runtime/components/react/mpx-picker/date.tsx +5 -2
  94. package/lib/runtime/components/react/mpx-picker/index.tsx +3 -2
  95. package/lib/runtime/components/react/mpx-picker/multiSelector.tsx +5 -2
  96. package/lib/runtime/components/react/mpx-picker/region.tsx +5 -2
  97. package/lib/runtime/components/react/mpx-picker/selector.tsx +5 -2
  98. package/lib/runtime/components/react/mpx-picker/time.tsx +10 -15
  99. package/lib/runtime/components/react/mpx-picker/type.ts +48 -43
  100. package/lib/runtime/components/react/mpx-picker-view-column-item.tsx +88 -0
  101. package/lib/runtime/components/react/mpx-picker-view-column.tsx +276 -112
  102. package/lib/runtime/components/react/mpx-picker-view.tsx +137 -129
  103. package/lib/runtime/components/react/mpx-radio-group.tsx +24 -27
  104. package/lib/runtime/components/react/mpx-radio.tsx +45 -54
  105. package/lib/runtime/components/react/mpx-rich-text/html.ts +40 -0
  106. package/lib/runtime/components/react/mpx-rich-text/index.tsx +115 -0
  107. package/lib/runtime/components/react/mpx-root-portal.tsx +3 -5
  108. package/lib/runtime/components/react/mpx-scroll-view.tsx +83 -73
  109. package/lib/runtime/components/react/mpx-simple-text.tsx +18 -0
  110. package/lib/runtime/components/react/mpx-swiper-item.tsx +41 -12
  111. package/lib/runtime/components/react/mpx-swiper.tsx +690 -0
  112. package/lib/runtime/components/react/mpx-switch.tsx +29 -23
  113. package/lib/runtime/components/react/mpx-text.tsx +14 -18
  114. package/lib/runtime/components/react/mpx-textarea.tsx +11 -10
  115. package/lib/runtime/components/react/mpx-view.tsx +93 -117
  116. package/lib/runtime/components/react/mpx-web-view.tsx +162 -56
  117. package/lib/runtime/components/react/pickerFaces.ts +112 -0
  118. package/lib/runtime/components/react/pickerVIewContext.ts +18 -0
  119. package/lib/runtime/components/react/pickerViewMask.tsx +30 -0
  120. package/lib/runtime/components/react/pickerViewOverlay.tsx +34 -0
  121. package/lib/runtime/components/react/types/common.ts +2 -0
  122. package/lib/runtime/components/react/types/global.d.ts +7 -17
  123. package/lib/runtime/components/react/useAnimationHooks.ts +37 -12
  124. package/lib/runtime/components/react/utils.tsx +169 -29
  125. package/lib/runtime/components/web/getInnerListeners.js +6 -6
  126. package/lib/runtime/components/web/mpx-movable-view.vue +334 -344
  127. package/lib/runtime/components/web/mpx-picker-view-column.vue +75 -75
  128. package/lib/runtime/components/web/mpx-picker.vue +382 -385
  129. package/lib/runtime/components/web/mpx-web-view.vue +175 -161
  130. package/lib/runtime/optionProcessor.js +7 -38
  131. package/lib/runtime/utils.js +2 -0
  132. package/lib/style-compiler/index.js +3 -4
  133. package/lib/style-compiler/plugins/scope-id.js +30 -2
  134. package/lib/style-compiler/strip-conditional-loader.js +118 -0
  135. package/lib/template-compiler/bind-this.js +7 -2
  136. package/lib/template-compiler/compiler.js +66 -39
  137. package/lib/template-compiler/gen-node-react.js +3 -3
  138. package/package.json +6 -4
  139. package/LICENSE +0 -433
  140. package/lib/runtime/components/react/dist/mpx-image/index.jsx +0 -226
  141. package/lib/runtime/components/react/dist/mpx-image/svg.jsx +0 -7
  142. package/lib/runtime/components/react/dist/mpx-swiper/carouse.jsx +0 -478
  143. package/lib/runtime/components/react/dist/mpx-swiper/index.jsx +0 -68
  144. package/lib/runtime/components/react/dist/mpx-swiper/type.js +0 -1
  145. package/lib/runtime/components/react/mpx-image/index.tsx +0 -345
  146. package/lib/runtime/components/react/mpx-image/svg.tsx +0 -22
  147. package/lib/runtime/components/react/mpx-swiper/carouse.tsx +0 -525
  148. package/lib/runtime/components/react/mpx-swiper/index.tsx +0 -80
  149. package/lib/runtime/components/react/mpx-swiper/type.ts +0 -87
  150. package/lib/runtime/components/web/event.js +0 -105
@@ -5,14 +5,14 @@
5
5
  * ✔ color
6
6
  */
7
7
  import { Switch, SwitchProps, ViewStyle, NativeSyntheticEvent } from 'react-native'
8
- import { useRef, useEffect, forwardRef, JSX, useState, useContext } from 'react'
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,
@@ -119,12 +120,13 @@ const _Switch = forwardRef<HandlerRef<Switch, _SwitchProps>, _SwitchProps>((prop
119
120
  }
120
121
  }, [])
121
122
 
122
- const innerProps = useInnerProps(props, {
123
+ const innerProps = useInnerProps(props, extendObject({
123
124
  ref: nodeRef,
124
- style: { ...normalStyle, ...layoutStyle },
125
- ...layoutProps,
126
- ...!disabled ? { [type === 'switch' ? 'onValueChange' : '_onChange']: onChange } : {}
127
- }, [
125
+ style: extendObject({}, normalStyle, layoutStyle)
126
+ },
127
+ layoutProps,
128
+ !disabled ? { [type === 'switch' ? 'onValueChange' : '_onChange']: onChange } : {})
129
+ , [
128
130
  'checked',
129
131
  'disabled',
130
132
  'type',
@@ -134,22 +136,26 @@ const _Switch = forwardRef<HandlerRef<Switch, _SwitchProps>, _SwitchProps>((prop
134
136
  })
135
137
 
136
138
  if (type === 'checkbox') {
137
- return <CheckBox
138
- {...innerProps}
139
- color={color}
140
- style={normalStyle}
141
- checked={isChecked}
142
- />
139
+ return createElement(
140
+ CheckBox,
141
+ extendObject({}, innerProps, {
142
+ color: color,
143
+ style: normalStyle,
144
+ checked: isChecked
145
+ })
146
+ )
143
147
  }
144
148
 
145
- return <Switch
146
- {...innerProps}
147
- style={normalStyle}
148
- value={isChecked}
149
- trackColor={{ false: '#FFF', true: color }}
150
- thumbColor={isChecked ? '#FFF' : '#f4f3f4'}
151
- ios_backgroundColor="#FFF"
152
- />
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
+ )
153
159
  })
154
160
 
155
161
  _Switch.displayName = 'MpxSwitch'
@@ -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,33 +50,28 @@ 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
77
  _Text.displayName = 'MpxText'
@@ -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,14 +29,15 @@ 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
  )
@@ -4,16 +4,18 @@
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, useHoverStyle } from './utils'
16
+ import { error } from '@mpxjs/utils'
16
17
  import LinearGradient from 'react-native-linear-gradient'
18
+ import { GestureDetector } from 'react-native-gesture-handler'
17
19
 
18
20
  export interface _ViewProps extends ViewProps {
19
21
  style?: ExtendedViewStyle
@@ -24,6 +26,7 @@ export interface _ViewProps extends ViewProps {
24
26
  'hover-stay-time'?: number
25
27
  'enable-background'?: boolean
26
28
  'enable-var'?: boolean
29
+ 'enable-fast-image'?: boolean
27
30
  'external-var-context'?: Record<string, any>
28
31
  'parent-font-size'?: number
29
32
  'parent-width'?: number
@@ -76,9 +79,11 @@ type PreImageInfo = {
76
79
  type ImageProps = {
77
80
  style: ImageStyle,
78
81
  src?: string,
82
+ source?: {uri: string },
79
83
  colors: Array<string>,
80
84
  locations?: Array<number>
81
85
  angle?: number
86
+ resizeMode?: 'cover' | 'stretch'
82
87
  }
83
88
 
84
89
  const linearMap = new Map([
@@ -233,10 +238,7 @@ function backgroundPosition (imageProps: ImageProps, preImageInfo: PreImageInfo,
233
238
  }
234
239
  }
235
240
 
236
- imageProps.style = {
237
- ...imageProps.style as ImageStyle,
238
- ...style
239
- }
241
+ extendObject(imageProps.style, style)
240
242
  }
241
243
 
242
244
  // background-size 转换
@@ -280,24 +282,23 @@ function backgroundSize (imageProps: ImageProps, preImageInfo: PreImageInfo, ima
280
282
  if (!dimensions) return
281
283
  } else { // 数值类型 ImageStyle
282
284
  // 数值类型设置为 stretch
283
- (imageProps.style as ImageStyle).resizeMode = 'stretch'
285
+ imageProps.resizeMode = 'stretch'
284
286
  dimensions = {
285
287
  width: isPercent(width) ? width : +width,
286
288
  height: isPercent(height) ? height : +height
287
289
  } as { width: NumberVal, height: NumberVal }
288
290
  }
289
291
  }
292
+
290
293
  // 样式合并
291
- imageProps.style = {
292
- ...imageProps.style as ImageStyle,
293
- ...dimensions
294
- }
294
+ extendObject(imageProps.style, dimensions)
295
295
  }
296
296
 
297
297
  // background-image转换为source
298
298
  function backgroundImage (imageProps: ImageProps, preImageInfo: PreImageInfo) {
299
- if (preImageInfo.src) {
300
- imageProps.src = preImageInfo.src
299
+ const src = preImageInfo.src
300
+ if (src) {
301
+ imageProps.source = { uri: src }
301
302
  }
302
303
  }
303
304
 
@@ -326,8 +327,8 @@ function linearGradient (imageProps: ImageProps, preImageInfo: PreImageInfo, ima
326
327
  const imageStyleToProps = (preImageInfo: PreImageInfo, imageSize: Size, layoutInfo: Size) => {
327
328
  // 初始化
328
329
  const imageProps: ImageProps = {
330
+ resizeMode: 'cover',
329
331
  style: {
330
- resizeMode: 'cover' as ImageResizeMode,
331
332
  position: 'absolute'
332
333
  // ...StyleSheet.absoluteFillObject
333
334
  },
@@ -476,10 +477,9 @@ function parseLinearGradient (text: string): LinearInfo | undefined {
476
477
  return prev
477
478
  }, { colors: [], locations: [] })
478
479
 
479
- return {
480
- ...linearInfo,
480
+ return extendObject({}, linearInfo, {
481
481
  direction: direction.trim()
482
- }
482
+ })
483
483
  }
484
484
 
485
485
  function parseBgImage (text: string): {
@@ -533,7 +533,26 @@ function isDiagonalAngle (linearInfo?: LinearInfo): boolean {
533
533
  return !!(linearInfo?.direction && diagonalAngleMap[linearInfo.direction])
534
534
  }
535
535
 
536
- function wrapImage (imageStyle?: ExtendedViewStyle) {
536
+ function inheritStyle (innerStyle: ExtendedViewStyle = {}) {
537
+ const { borderWidth, borderRadius } = innerStyle
538
+ const borderStyles = ['borderRadius', 'borderTopLeftRadius', 'borderTopRightRadius', 'borderBottomRightRadius', 'borderBottomLeftRadius']
539
+ return pickStyle(innerStyle,
540
+ borderStyles,
541
+ borderWidth && borderRadius
542
+ ? (key, val) => {
543
+ // 盒子内圆角borderWith与borderRadius的关系
544
+ // 当borderRadius 小于 当borderWith 内边框为直角
545
+ // 当borderRadius 大于等于 当borderWith 内边框为圆角
546
+ if (borderStyles.includes(key)) {
547
+ const borderVal = +val - borderWidth
548
+ return borderVal > 0 ? borderVal : 0
549
+ }
550
+ return val
551
+ }
552
+ : undefined)
553
+ }
554
+
555
+ function wrapImage (imageStyle?: ExtendedViewStyle, innerStyle?: Record<string, any>, enableFastImage?: boolean) {
537
556
  // 预处理数据
538
557
  const preImageInfo: PreImageInfo = preParseImage(imageStyle)
539
558
  // 预解析
@@ -616,9 +635,9 @@ function wrapImage (imageStyle?: ExtendedViewStyle) {
616
635
  }
617
636
  }
618
637
 
619
- return <View key='backgroundImage' {...needLayout ? { onLayout } : null} style={{ ...StyleSheet.absoluteFillObject, overflow: 'hidden' }}>
638
+ return <View key='backgroundImage' {...needLayout ? { onLayout } : null} style={{ ...inheritStyle(innerStyle), ...StyleSheet.absoluteFillObject, overflow: 'hidden' }}>
620
639
  {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)} />}
640
+ {show && type === 'image' && (renderImage(imageStyleToProps(preImageInfo, sizeInfo.current as Size, layoutInfo.current as Size), enableFastImage))}
622
641
  </View>
623
642
  }
624
643
 
@@ -629,9 +648,11 @@ interface WrapChildrenConfig {
629
648
  backgroundStyle?: ExtendedViewStyle
630
649
  varContext?: Record<string, any>
631
650
  textProps?: Record<string, any>
651
+ innerStyle?: Record<string, any>
652
+ enableFastImage?: boolean
632
653
  }
633
654
 
634
- function wrapWithChildren (props: _ViewProps, { hasVarDec, enableBackground, textStyle, backgroundStyle, varContext, textProps }: WrapChildrenConfig) {
655
+ function wrapWithChildren (props: _ViewProps, { hasVarDec, enableBackground, textStyle, backgroundStyle, varContext, textProps, innerStyle, enableFastImage }: WrapChildrenConfig) {
635
656
  const children = wrapChildren(props, {
636
657
  hasVarDec,
637
658
  varContext,
@@ -640,7 +661,7 @@ function wrapWithChildren (props: _ViewProps, { hasVarDec, enableBackground, tex
640
661
  })
641
662
 
642
663
  return [
643
- enableBackground ? wrapImage(backgroundStyle) : null,
664
+ enableBackground ? wrapImage(backgroundStyle, innerStyle, enableFastImage) : null,
644
665
  children
645
666
  ]
646
667
  }
@@ -655,6 +676,7 @@ const _View = forwardRef<HandlerRef<View, _ViewProps>, _ViewProps>((viewProps, r
655
676
  'enable-var': enableVar,
656
677
  'external-var-context': externalVarContext,
657
678
  'enable-background': enableBackground,
679
+ 'enable-fast-image': enableFastImage,
658
680
  'enable-animation': enableAnimation,
659
681
  'parent-font-size': parentFontSize,
660
682
  'parent-width': parentWidth,
@@ -662,24 +684,19 @@ const _View = forwardRef<HandlerRef<View, _ViewProps>, _ViewProps>((viewProps, r
662
684
  animation
663
685
  } = props
664
686
 
665
- const [isHover, setIsHover] = useState(false)
666
-
667
687
  // 默认样式
668
- const defaultStyle: ExtendedViewStyle = {
669
- // flex 布局相关的默认样式
670
- ...style.display === 'flex' && {
671
- flexDirection: 'row',
672
- flexBasis: 'auto',
673
- flexShrink: 1,
674
- flexWrap: 'nowrap'
675
- }
676
- }
688
+ const defaultStyle: ExtendedViewStyle = style.display === 'flex'
689
+ ? {
690
+ flexDirection: 'row',
691
+ flexBasis: 'auto',
692
+ flexShrink: 1,
693
+ flexWrap: 'nowrap'
694
+ }
695
+ : {}
677
696
 
678
- const styleObj: ExtendedViewStyle = {
679
- ...defaultStyle,
680
- ...style,
681
- ...(isHover ? hoverStyle : null)
682
- }
697
+ const { isHover, enableHoverStyle, gesture } = useHoverStyle({ hoverStyle, hoverStartTime, hoverStayTime })
698
+
699
+ const styleObj: ExtendedViewStyle = extendObject({}, defaultStyle, style, isHover ? hoverStyle as ExtendedViewStyle : {})
683
700
 
684
701
  const {
685
702
  normalStyle,
@@ -696,113 +713,72 @@ const _View = forwardRef<HandlerRef<View, _ViewProps>, _ViewProps>((viewProps, r
696
713
  parentHeight
697
714
  })
698
715
 
699
- const { textStyle, backgroundStyle, innerStyle } = splitStyle(normalStyle)
716
+ const { textStyle, backgroundStyle, innerStyle = {} } = splitStyle(normalStyle)
700
717
 
701
718
  enableBackground = enableBackground || !!backgroundStyle
702
719
  const enableBackgroundRef = useRef(enableBackground)
703
720
  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.')
721
+ error('[Mpx runtime error]: background use should be stable in the component lifecycle, or you can set [enable-background] with true.')
705
722
  }
706
723
 
707
724
  const nodeRef = useRef(null)
708
725
  useNodesRef<View, _ViewProps>(props, ref, nodeRef, {
709
- defaultStyle
726
+ style: normalStyle
710
727
  })
711
728
 
712
- const dataRef = useRef<{
713
- startTimer?: ReturnType<typeof setTimeout>
714
- stayTimer?: ReturnType<typeof setTimeout>
715
- }>({})
716
-
717
- useEffect(() => {
718
- return () => {
719
- dataRef.current.startTimer && clearTimeout(dataRef.current.startTimer)
720
- dataRef.current.stayTimer && clearTimeout(dataRef.current.stayTimer)
721
- }
722
- }, [])
723
-
724
- const setStartTimer = () => {
725
- dataRef.current.startTimer && clearTimeout(dataRef.current.startTimer)
726
- dataRef.current.startTimer = setTimeout(() => {
727
- setIsHover(true)
728
- }, +hoverStartTime)
729
- }
730
-
731
- const setStayTimer = () => {
732
- dataRef.current.stayTimer && clearTimeout(dataRef.current.stayTimer)
733
- dataRef.current.startTimer && clearTimeout(dataRef.current.startTimer)
734
- dataRef.current.stayTimer = setTimeout(() => {
735
- setIsHover(false)
736
- }, +hoverStayTime)
737
- }
738
-
739
- function onTouchStart (e: NativeSyntheticEvent<TouchEvent>) {
740
- const { bindtouchstart } = props
741
- bindtouchstart && bindtouchstart(e)
742
- setStartTimer()
743
- }
744
-
745
- function onTouchEnd (e: NativeSyntheticEvent<TouchEvent>) {
746
- const { bindtouchend } = props
747
- bindtouchend && bindtouchend(e)
748
- setStayTimer()
749
- }
750
-
751
729
  const {
752
730
  layoutRef,
753
731
  layoutStyle,
754
732
  layoutProps
755
733
  } = useLayout({ props, hasSelfPercent, setWidth, setHeight, nodeRef })
756
734
 
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
- })
735
+ const viewStyle = extendObject({}, innerStyle, layoutStyle)
774
736
 
775
737
  enableAnimation = enableAnimation || !!animation
776
738
  const enableAnimationRef = useRef(enableAnimation)
777
739
  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.')
740
+ error('[Mpx runtime error]: animation use should be stable in the component lifecycle, or you can set [enable-animation] with true.')
779
741
  }
780
- const finalStyle = enableAnimation
781
- ? useAnimationHooks({
782
- animation,
783
- style: viewStyle
784
- })
742
+ const finalStyle = enableAnimationRef.current
743
+ ? [viewStyle, useAnimationHooks({
744
+ animation,
745
+ style: viewStyle
746
+ })]
785
747
  : viewStyle
748
+ const innerProps = useInnerProps(
749
+ props,
750
+ extendObject({
751
+ ref: nodeRef,
752
+ style: finalStyle
753
+ },
754
+ layoutProps
755
+ ), [
756
+ 'hover-start-time',
757
+ 'hover-stay-time',
758
+ 'hover-style',
759
+ 'hover-class'
760
+ ], {
761
+ layoutRef
762
+ })
763
+
786
764
  const childNode = wrapWithChildren(props, {
787
765
  hasVarDec,
788
766
  enableBackground: enableBackgroundRef.current,
789
767
  textStyle,
790
768
  backgroundStyle,
791
769
  varContext: varContextRef.current,
792
- textProps
770
+ textProps,
771
+ innerStyle,
772
+ enableFastImage
793
773
  })
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>)
774
+
775
+ const BaseComponent = enableAnimation
776
+ ? createElement(Animated.View, extendObject({}, innerProps, { style: finalStyle }), childNode)
777
+ : createElement(View, innerProps, childNode)
778
+
779
+ return enableHoverStyle
780
+ ? createElement(GestureDetector, { gesture }, BaseComponent)
781
+ : BaseComponent
806
782
  })
807
783
 
808
784
  _View.displayName = 'MpxView'