@mpxjs/webpack-plugin 2.10.24 → 2.11.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 (151) hide show
  1. package/lib/index.js +4 -1
  2. package/lib/platform/style/wx/index.js +417 -120
  3. package/lib/platform/template/wx/component-config/picker.js +0 -6
  4. package/lib/react/style-helper.js +6 -6
  5. package/lib/resolver/AddEnvPlugin.js +1 -1
  6. package/lib/resolver/AddModePlugin.js +1 -1
  7. package/lib/resolver/ExtendComponentsPlugin.js +68 -0
  8. package/lib/runtime/components/extends/section-list.mpx +14 -0
  9. package/lib/runtime/components/react/animationHooks/index.ts +7 -3
  10. package/lib/runtime/components/react/dist/animationHooks/index.d.ts +0 -2
  11. package/lib/runtime/components/react/dist/animationHooks/index.js +6 -1
  12. package/lib/runtime/components/react/dist/event.config.d.ts +2 -6
  13. package/lib/runtime/components/react/dist/event.config.js +28 -24
  14. package/lib/runtime/components/react/dist/getInnerListeners.d.ts +1 -1
  15. package/lib/runtime/components/react/dist/getInnerListeners.js +74 -56
  16. package/lib/runtime/components/react/dist/mpx-button.d.ts +1 -2
  17. package/lib/runtime/components/react/dist/mpx-button.jsx +16 -9
  18. package/lib/runtime/components/react/dist/mpx-camera.d.ts +0 -2
  19. package/lib/runtime/components/react/dist/mpx-camera.jsx +36 -5
  20. package/lib/runtime/components/react/dist/mpx-canvas/index.d.ts +0 -2
  21. package/lib/runtime/components/react/dist/mpx-canvas/index.jsx +1 -3
  22. package/lib/runtime/components/react/dist/mpx-canvas/utils.d.ts +1 -1
  23. package/lib/runtime/components/react/dist/mpx-checkbox-group.d.ts +0 -2
  24. package/lib/runtime/components/react/dist/mpx-checkbox-group.jsx +3 -4
  25. package/lib/runtime/components/react/dist/mpx-checkbox.d.ts +1 -2
  26. package/lib/runtime/components/react/dist/mpx-checkbox.jsx +8 -9
  27. package/lib/runtime/components/react/dist/mpx-form.d.ts +1 -2
  28. package/lib/runtime/components/react/dist/mpx-form.jsx +5 -5
  29. package/lib/runtime/components/react/dist/mpx-icon/index.d.ts +0 -2
  30. package/lib/runtime/components/react/dist/mpx-icon/index.jsx +2 -2
  31. package/lib/runtime/components/react/dist/mpx-image.d.ts +0 -2
  32. package/lib/runtime/components/react/dist/mpx-image.jsx +59 -43
  33. package/lib/runtime/components/react/dist/mpx-inline-text.jsx +13 -4
  34. package/lib/runtime/components/react/dist/mpx-input.d.ts +0 -2
  35. package/lib/runtime/components/react/dist/mpx-input.jsx +16 -8
  36. package/lib/runtime/components/react/dist/mpx-label.d.ts +1 -2
  37. package/lib/runtime/components/react/dist/mpx-label.jsx +5 -6
  38. package/lib/runtime/components/react/dist/mpx-movable-area.d.ts +0 -2
  39. package/lib/runtime/components/react/dist/mpx-movable-area.jsx +3 -3
  40. package/lib/runtime/components/react/dist/mpx-movable-view.d.ts +1 -2
  41. package/lib/runtime/components/react/dist/mpx-movable-view.jsx +6 -6
  42. package/lib/runtime/components/react/dist/mpx-nav.jsx +1 -1
  43. package/lib/runtime/components/react/dist/mpx-picker/index.jsx +72 -23
  44. package/lib/runtime/components/react/dist/mpx-picker/multiSelector.jsx +2 -2
  45. package/lib/runtime/components/react/dist/mpx-picker/type.d.ts +4 -0
  46. package/lib/runtime/components/react/dist/mpx-picker-view/index.d.ts +1 -1
  47. package/lib/runtime/components/react/dist/mpx-picker-view/index.jsx +10 -14
  48. package/lib/runtime/components/react/dist/mpx-picker-view/pickerVIewContext.d.ts +0 -2
  49. package/lib/runtime/components/react/dist/mpx-picker-view/pickerVIewContext.js +0 -5
  50. package/lib/runtime/components/react/dist/mpx-picker-view-column/index.d.ts +1 -1
  51. package/lib/runtime/components/react/dist/mpx-picker-view-column/index.jsx +34 -14
  52. package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewColumnItem.d.ts +0 -2
  53. package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewColumnItem.jsx +4 -5
  54. package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewColumnItemLite.d.ts +0 -2
  55. package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewColumnItemLite.jsx +3 -5
  56. package/lib/runtime/components/react/dist/mpx-popup/index.d.ts +5 -4
  57. package/lib/runtime/components/react/dist/mpx-popup/index.jsx +2 -2
  58. package/lib/runtime/components/react/dist/mpx-popup/popupBase.jsx +3 -2
  59. package/lib/runtime/components/react/dist/mpx-progress.d.ts +0 -2
  60. package/lib/runtime/components/react/dist/mpx-progress.jsx +1 -3
  61. package/lib/runtime/components/react/dist/mpx-radio-group.d.ts +0 -2
  62. package/lib/runtime/components/react/dist/mpx-radio-group.jsx +3 -4
  63. package/lib/runtime/components/react/dist/mpx-radio.d.ts +1 -2
  64. package/lib/runtime/components/react/dist/mpx-radio.jsx +8 -9
  65. package/lib/runtime/components/react/dist/mpx-rich-text/index.d.ts +0 -2
  66. package/lib/runtime/components/react/dist/mpx-rich-text/index.jsx +1 -3
  67. package/lib/runtime/components/react/dist/mpx-scroll-view.d.ts +1 -2
  68. package/lib/runtime/components/react/dist/mpx-scroll-view.jsx +6 -6
  69. package/lib/runtime/components/react/dist/mpx-section-list.d.ts +51 -0
  70. package/lib/runtime/components/react/dist/mpx-section-list.jsx +376 -0
  71. package/lib/runtime/components/react/dist/mpx-simple-text.jsx +37 -19
  72. package/lib/runtime/components/react/dist/mpx-simple-view.d.ts +4 -1
  73. package/lib/runtime/components/react/dist/mpx-simple-view.jsx +11 -4
  74. package/lib/runtime/components/react/dist/mpx-slider.d.ts +0 -2
  75. package/lib/runtime/components/react/dist/mpx-slider.jsx +6 -7
  76. package/lib/runtime/components/react/dist/mpx-sticky-header.d.ts +1 -2
  77. package/lib/runtime/components/react/dist/mpx-sticky-header.jsx +5 -5
  78. package/lib/runtime/components/react/dist/mpx-sticky-section.d.ts +1 -2
  79. package/lib/runtime/components/react/dist/mpx-sticky-section.jsx +6 -6
  80. package/lib/runtime/components/react/dist/mpx-swiper-item.d.ts +1 -2
  81. package/lib/runtime/components/react/dist/mpx-swiper-item.jsx +5 -5
  82. package/lib/runtime/components/react/dist/mpx-swiper.d.ts +1 -2
  83. package/lib/runtime/components/react/dist/mpx-swiper.jsx +4 -8
  84. package/lib/runtime/components/react/dist/mpx-switch.d.ts +0 -2
  85. package/lib/runtime/components/react/dist/mpx-switch.jsx +1 -3
  86. package/lib/runtime/components/react/dist/mpx-text.d.ts +0 -2
  87. package/lib/runtime/components/react/dist/mpx-text.jsx +43 -25
  88. package/lib/runtime/components/react/dist/mpx-video.d.ts +0 -2
  89. package/lib/runtime/components/react/dist/mpx-video.jsx +4 -5
  90. package/lib/runtime/components/react/dist/mpx-view.d.ts +2 -2
  91. package/lib/runtime/components/react/dist/mpx-view.jsx +214 -114
  92. package/lib/runtime/components/react/dist/mpx-web-view.d.ts +2 -1
  93. package/lib/runtime/components/react/dist/mpx-web-view.jsx +5 -1
  94. package/lib/runtime/components/react/dist/namedColorSet.d.ts +2 -0
  95. package/lib/runtime/components/react/dist/namedColorSet.js +149 -0
  96. package/lib/runtime/components/react/dist/utils.d.ts +71 -70
  97. package/lib/runtime/components/react/dist/utils.jsx +1295 -456
  98. package/lib/runtime/components/react/event.config.ts +32 -25
  99. package/lib/runtime/components/react/getInnerListeners.ts +84 -60
  100. package/lib/runtime/components/react/mpx-button.tsx +18 -18
  101. package/lib/runtime/components/react/mpx-camera.tsx +40 -8
  102. package/lib/runtime/components/react/mpx-canvas/index.tsx +5 -7
  103. package/lib/runtime/components/react/mpx-canvas/utils.tsx +3 -1
  104. package/lib/runtime/components/react/mpx-checkbox-group.tsx +2 -8
  105. package/lib/runtime/components/react/mpx-checkbox.tsx +9 -13
  106. package/lib/runtime/components/react/mpx-form.tsx +6 -8
  107. package/lib/runtime/components/react/mpx-icon/index.tsx +1 -5
  108. package/lib/runtime/components/react/mpx-image.tsx +66 -58
  109. package/lib/runtime/components/react/mpx-inline-text.tsx +13 -4
  110. package/lib/runtime/components/react/mpx-input.tsx +19 -12
  111. package/lib/runtime/components/react/mpx-label.tsx +6 -10
  112. package/lib/runtime/components/react/mpx-movable-area.tsx +3 -5
  113. package/lib/runtime/components/react/mpx-movable-view.tsx +7 -9
  114. package/lib/runtime/components/react/mpx-nav.tsx +1 -1
  115. package/lib/runtime/components/react/mpx-picker/index.tsx +100 -29
  116. package/lib/runtime/components/react/mpx-picker/multiSelector.tsx +3 -3
  117. package/lib/runtime/components/react/mpx-picker/selector.tsx +1 -1
  118. package/lib/runtime/components/react/mpx-picker/type.ts +4 -0
  119. package/lib/runtime/components/react/mpx-picker-view/index.tsx +17 -24
  120. package/lib/runtime/components/react/mpx-picker-view/pickerVIewContext.ts +0 -9
  121. package/lib/runtime/components/react/mpx-picker-view-column/index.tsx +44 -23
  122. package/lib/runtime/components/react/mpx-picker-view-column/pickerViewColumnItem.tsx +1 -9
  123. package/lib/runtime/components/react/mpx-picker-view-column/pickerViewColumnItemLite.tsx +0 -9
  124. package/lib/runtime/components/react/mpx-popup/index.tsx +7 -3
  125. package/lib/runtime/components/react/mpx-popup/popupBase.tsx +3 -2
  126. package/lib/runtime/components/react/mpx-progress.tsx +0 -6
  127. package/lib/runtime/components/react/mpx-radio-group.tsx +2 -8
  128. package/lib/runtime/components/react/mpx-radio.tsx +9 -13
  129. package/lib/runtime/components/react/mpx-rich-text/index.tsx +0 -6
  130. package/lib/runtime/components/react/mpx-scroll-view.tsx +7 -9
  131. package/lib/runtime/components/react/mpx-section-list.tsx +557 -0
  132. package/lib/runtime/components/react/mpx-simple-text.tsx +36 -25
  133. package/lib/runtime/components/react/mpx-simple-view.tsx +17 -5
  134. package/lib/runtime/components/react/mpx-slider.tsx +15 -13
  135. package/lib/runtime/components/react/mpx-sticky-header.tsx +6 -8
  136. package/lib/runtime/components/react/mpx-sticky-section.tsx +7 -9
  137. package/lib/runtime/components/react/mpx-swiper-item.tsx +6 -7
  138. package/lib/runtime/components/react/mpx-swiper.tsx +5 -11
  139. package/lib/runtime/components/react/mpx-switch.tsx +0 -6
  140. package/lib/runtime/components/react/mpx-text.tsx +45 -36
  141. package/lib/runtime/components/react/mpx-video.tsx +3 -8
  142. package/lib/runtime/components/react/mpx-view.tsx +235 -129
  143. package/lib/runtime/components/react/mpx-web-view.tsx +12 -6
  144. package/lib/runtime/components/react/namedColorSet.ts +150 -0
  145. package/lib/runtime/components/react/types/getInnerListeners.d.ts +21 -1
  146. package/lib/runtime/components/react/types/global.d.ts +1 -0
  147. package/lib/runtime/components/react/utils.tsx +1352 -550
  148. package/lib/runtime/i18n.wxs +15 -9
  149. package/lib/style-compiler/strip-conditional.js +19 -4
  150. package/lib/template-compiler/compiler.js +6 -0
  151. package/package.json +6 -6
@@ -26,7 +26,7 @@ import { warn } from '@mpxjs/utils'
26
26
  import useInnerProps, { getCustomEvent } from './getInnerListeners'
27
27
  import useNodesRef, { HandlerRef } from './useNodesRef'
28
28
  import Icon from './mpx-icon'
29
- import { splitProps, splitStyle, useLayout, useTransformStyle, wrapChildren, extendObject, useTextPassThroughValue } from './utils'
29
+ import { splitProps, splitStyle, useLayout, useTransformStyle, wrapChildren, extendObject, useTextPassThrough } from './utils'
30
30
  import { CheckboxGroupContext, LabelContext } from './context'
31
31
  import Portal from './mpx-portal'
32
32
 
@@ -42,8 +42,7 @@ export interface CheckboxProps extends Selection {
42
42
  groupValue?: Array<string>
43
43
  'enable-offset'?: boolean
44
44
  'enable-var'?: boolean
45
- 'external-var-context'?: Record<string, any>
46
- 'parent-font-size'?: number
45
+ 'enable-text-pass-through'?: boolean
47
46
  'parent-width'?: number
48
47
  'parent-height'?: number
49
48
  children?: ReactNode
@@ -89,8 +88,7 @@ const Checkbox = forwardRef<HandlerRef<View, CheckboxProps>, CheckboxProps>(
89
88
  color = '#09BB07',
90
89
  style = {},
91
90
  'enable-var': enableVar,
92
- 'external-var-context': externalVarContext,
93
- 'parent-font-size': parentFontSize,
91
+ 'enable-text-pass-through': enableTextPassThrough,
94
92
  'parent-width': parentWidth,
95
93
  'parent-height': parentHeight,
96
94
  bindtap,
@@ -103,14 +101,12 @@ const Checkbox = forwardRef<HandlerRef<View, CheckboxProps>, CheckboxProps>(
103
101
  let groupValue: { [key: string]: { checked: boolean; setValue: Dispatch<SetStateAction<boolean>> } } | undefined
104
102
  let notifyChange: (evt: NativeSyntheticEvent<TouchEvent>) => void | undefined
105
103
 
106
- const defaultStyle = extendObject(
104
+ const wrapperStyle = extendObject(
107
105
  {},
108
106
  styles.wrapper,
109
107
  disabled ? styles.wrapperDisabled : null
110
108
  )
111
109
 
112
- const styleObj = extendObject({}, styles.container, style)
113
-
114
110
  const onChange = (evt: NativeSyntheticEvent<TouchEvent>) => {
115
111
  if (disabled) return
116
112
  const checked = !isChecked
@@ -136,19 +132,19 @@ const Checkbox = forwardRef<HandlerRef<View, CheckboxProps>, CheckboxProps>(
136
132
  varContextRef,
137
133
  setWidth,
138
134
  setHeight
139
- } = useTransformStyle(styleObj, { enableVar, externalVarContext, parentFontSize, parentWidth, parentHeight })
135
+ } = useTransformStyle(style, { enableVar, parentWidth, parentHeight, defaultStyle: styles.container })
140
136
 
141
137
  const nodeRef = useRef(null)
142
138
 
143
139
  useNodesRef(props, ref, nodeRef, {
144
- style: extendObject({}, defaultStyle, normalStyle),
140
+ style: normalStyle,
145
141
  change: onChange
146
142
  })
147
143
 
148
144
  const { layoutRef, layoutStyle, layoutProps } = useLayout({ props, hasSelfPercent, setWidth, setHeight, nodeRef })
149
145
 
150
146
  const { textStyle, backgroundStyle, innerStyle = {} } = splitStyle(normalStyle)
151
- const textPassThrough = useTextPassThroughValue(textStyle, textProps)
147
+ const textPassThrough = useTextPassThrough(textStyle, textProps, { enableTextPassThrough })
152
148
 
153
149
  if (backgroundStyle) {
154
150
  warn('Checkbox does not support background image-related styles!')
@@ -214,7 +210,7 @@ const Checkbox = forwardRef<HandlerRef<View, CheckboxProps>, CheckboxProps>(
214
210
  const finalComponent = createElement(View, innerProps,
215
211
  createElement(
216
212
  View,
217
- { style: defaultStyle },
213
+ { style: wrapperStyle },
218
214
  createElement(Icon, {
219
215
  type: 'success_no_circle',
220
216
  size: 18,
@@ -223,7 +219,7 @@ const Checkbox = forwardRef<HandlerRef<View, CheckboxProps>, CheckboxProps>(
223
219
  })
224
220
  ),
225
221
  wrapChildren(
226
- props,
222
+ props.children,
227
223
  {
228
224
  hasVarDec,
229
225
  varContext: varContextRef.current,
@@ -9,14 +9,13 @@ import { JSX, useRef, forwardRef, ReactNode, useMemo, createElement } from 'reac
9
9
  import useNodesRef, { HandlerRef } from './useNodesRef'
10
10
  import useInnerProps, { getCustomEvent } from './getInnerListeners'
11
11
  import { FormContext } from './context'
12
- import { useTransformStyle, splitProps, splitStyle, useLayout, wrapChildren, extendObject, useTextPassThroughValue } from './utils'
12
+ import { useTransformStyle, splitProps, splitStyle, useLayout, wrapChildren, extendObject, useTextPassThrough } from './utils'
13
13
  interface FormProps {
14
14
  style?: Record<string, any>
15
15
  children?: ReactNode
16
16
  'enable-offset'?: boolean
17
17
  'enable-var'?: boolean
18
- 'external-var-context'?: Record<string, any>
19
- 'parent-font-size'?: number
18
+ 'enable-text-pass-through'?: boolean
20
19
  'parent-width'?: number
21
20
  'parent-height'?: number
22
21
  bindsubmit?: (evt: {
@@ -32,8 +31,7 @@ const _Form = forwardRef<HandlerRef<View, FormProps>, FormProps>((fromProps: For
32
31
  const {
33
32
  style,
34
33
  'enable-var': enableVar,
35
- 'external-var-context': externalVarContext,
36
- 'parent-font-size': parentFontSize,
34
+ 'enable-text-pass-through': enableTextPassThrough,
37
35
  'parent-width': parentWidth,
38
36
  'parent-height': parentHeight
39
37
  } = props
@@ -45,10 +43,10 @@ const _Form = forwardRef<HandlerRef<View, FormProps>, FormProps>((fromProps: For
45
43
  varContextRef,
46
44
  setWidth,
47
45
  setHeight
48
- } = useTransformStyle(style, { enableVar, externalVarContext, parentFontSize, parentWidth, parentHeight })
46
+ } = useTransformStyle(style, { enableVar, parentWidth, parentHeight })
49
47
 
50
48
  const { textStyle, innerStyle = {} } = splitStyle(normalStyle)
51
- const textPassThrough = useTextPassThroughValue(textStyle, textProps)
49
+ const textPassThrough = useTextPassThrough(textStyle, textProps, { enableTextPassThrough })
52
50
 
53
51
  const formRef = useRef(null)
54
52
  useNodesRef(props, ref, formRef, {
@@ -114,7 +112,7 @@ const _Form = forwardRef<HandlerRef<View, FormProps>, FormProps>((fromProps: For
114
112
  FormContext.Provider,
115
113
  { value: contextValue },
116
114
  wrapChildren(
117
- props,
115
+ props.children,
118
116
  {
119
117
  hasVarDec,
120
118
  varContext: varContextRef.current,
@@ -37,8 +37,6 @@ export interface IconProps {
37
37
  style?: TextStyle & Record<string, any>
38
38
  'enable-offset'?: boolean
39
39
  'enable-var'?: boolean
40
- 'external-var-context'?: Record<string, any>
41
- 'parent-font-size'?: number
42
40
  'parent-width'?: number
43
41
  'parent-height'?: number
44
42
  }
@@ -63,8 +61,6 @@ const Icon = forwardRef<HandlerRef<Text, IconProps>, IconProps>(
63
61
  color,
64
62
  style = {},
65
63
  'enable-var': enableVar,
66
- 'external-var-context': externalVarContext,
67
- 'parent-font-size': parentFontSize,
68
64
  'parent-width': parentWidth,
69
65
  'parent-height': parentHeight
70
66
  } = props
@@ -81,7 +77,7 @@ const Icon = forwardRef<HandlerRef<Text, IconProps>, IconProps>(
81
77
  normalStyle,
82
78
  setWidth,
83
79
  setHeight
84
- } = useTransformStyle(styleObj, { enableVar, externalVarContext, parentFontSize, parentWidth, parentHeight })
80
+ } = useTransformStyle(styleObj, { enableVar, parentWidth, parentHeight })
85
81
 
86
82
  const nodeRef = useRef(null)
87
83
  useNodesRef(props, ref, nodeRef, { style: normalStyle })
@@ -23,11 +23,11 @@ import {
23
23
  ImageLoadEventData,
24
24
  ImageSourcePropType
25
25
  } from 'react-native'
26
- import { noop } from '@mpxjs/utils'
26
+ import { hasOwn, noop } from '@mpxjs/utils'
27
27
  import { LocalSvg, SvgCssUri } from 'react-native-svg/css'
28
28
  import useInnerProps, { getCustomEvent } from './getInnerListeners'
29
29
  import useNodesRef, { HandlerRef } from './useNodesRef'
30
- import { SVG_REGEXP, useLayout, useTransformStyle, renderImage, extendObject, isAndroid } from './utils'
30
+ import { svgRegExp, useLayout, useTransformStyle, renderImage, extendObject, isAndroid } from './utils'
31
31
  import Portal from './mpx-portal'
32
32
 
33
33
  export type Mode =
@@ -52,8 +52,6 @@ export interface ImageProps {
52
52
  style?: ImageStyle & Record<string, any>
53
53
  'enable-offset'?: boolean
54
54
  'enable-var'?: boolean
55
- 'external-var-context'?: Record<string, any>
56
- 'parent-font-size'?: number
57
55
  'parent-width'?: number
58
56
  'parent-height'?: number
59
57
  'enable-fast-image'?: boolean
@@ -72,26 +70,46 @@ interface ImageState {
72
70
 
73
71
  const DEFAULT_IMAGE_WIDTH = 320
74
72
  const DEFAULT_IMAGE_HEIGHT = 240
75
- const cropMode: Mode[] = [
76
- 'top',
77
- 'bottom',
78
- 'center',
79
- 'right',
80
- 'left',
81
- 'top left',
82
- 'top right',
83
- 'bottom left',
84
- 'bottom right'
85
- ]
86
-
87
- const ModeMap = new Map<Mode, ImageResizeMode | undefined>([
88
- ['scaleToFill', 'stretch'],
89
- ['aspectFit', 'contain'],
90
- ['aspectFill', 'cover'],
91
- ['widthFix', 'stretch'],
92
- ['heightFix', 'stretch'],
93
- ...cropMode.map<[Mode, ImageResizeMode]>(mode => [mode, 'stretch'])
94
- ])
73
+ const cropModeMap: Record<string, boolean> = {
74
+ top: true,
75
+ bottom: true,
76
+ center: true,
77
+ right: true,
78
+ left: true,
79
+ 'top left': true,
80
+ 'top right': true,
81
+ 'bottom left': true,
82
+ 'bottom right': true
83
+ }
84
+
85
+ const modeResizeMap: Record<string, ImageResizeMode> = {
86
+ scaleToFill: 'stretch',
87
+ aspectFit: 'contain',
88
+ aspectFill: 'cover',
89
+ widthFix: 'stretch',
90
+ heightFix: 'stretch',
91
+ top: 'stretch',
92
+ bottom: 'stretch',
93
+ center: 'stretch',
94
+ right: 'stretch',
95
+ left: 'stretch',
96
+ 'top left': 'stretch',
97
+ 'top right': 'stretch',
98
+ 'bottom left': 'stretch',
99
+ 'bottom right': 'stretch'
100
+ }
101
+
102
+ const DEFAULT_IMAGE_STYLE: ImageStyle = {
103
+ width: DEFAULT_IMAGE_WIDTH,
104
+ height: DEFAULT_IMAGE_HEIGHT
105
+ }
106
+ const OVERFLOW_HIDDEN_STYLE = { overflow: 'hidden' as const }
107
+ const SVG_TRANSFORM_ORIGIN_STYLE = { transformOrigin: 'left top' as const }
108
+ const BASE_IMAGE_FILL_STYLE: ImageStyle = {
109
+ transformOrigin: 'left top',
110
+ width: '100%',
111
+ height: '100%'
112
+ }
95
113
 
96
114
  const isNumber = (value: DimensionValue): value is number => typeof value === 'number'
97
115
 
@@ -109,7 +127,7 @@ function getImageUri (src: string | ImageSourcePropType) {
109
127
 
110
128
  function isSvgSource (src: string | ImageSourcePropType) {
111
129
  const uri = getImageUri(src)
112
- return SVG_REGEXP.test(uri)
130
+ return svgRegExp.test(uri)
113
131
  }
114
132
 
115
133
  function getImageSize (src: string | ImageSourcePropType, success: (width: number, height: number) => void, fail: () => void = noop) {
@@ -157,10 +175,7 @@ const Image = forwardRef<HandlerRef<RNImage, ImageProps>, ImageProps>((props, re
157
175
  src = '',
158
176
  mode = 'scaleToFill',
159
177
  style = {},
160
- 'enable-var': enableVar,
161
- 'external-var-context': externalVarContext,
162
- 'parent-font-size': parentFontSize,
163
- 'enable-fast-image': enableFastImage,
178
+ 'enable-var': enableVar, 'enable-fast-image': enableFastImage,
164
179
  'parent-width': parentWidth,
165
180
  'parent-height': parentHeight,
166
181
  'is-svg': isSvgProp,
@@ -168,29 +183,17 @@ const Image = forwardRef<HandlerRef<RNImage, ImageProps>, ImageProps>((props, re
168
183
  binderror
169
184
  } = props
170
185
 
171
- const defaultStyle = {
172
- width: DEFAULT_IMAGE_WIDTH,
173
- height: DEFAULT_IMAGE_HEIGHT
174
- }
175
-
176
- const styleObj = extendObject(
177
- {},
178
- defaultStyle,
179
- style,
180
- { overflow: 'hidden' }
181
- )
186
+ const styleObj = extendObject({}, style, OVERFLOW_HIDDEN_STYLE)
182
187
 
183
188
  const nodeRef = useRef(null)
184
- useNodesRef(props, ref, nodeRef, {
185
- defaultStyle
186
- })
187
189
 
188
- const isSvg = isSvgProp || isSvgSource(src)
190
+ const isSvg = useMemo(() => isSvgProp || isSvgSource(src), [isSvgProp, src])
191
+ const imageSource = useMemo(() => normalizeImageSource(src), [src])
189
192
  const isWidthFixMode = mode === 'widthFix'
190
193
  const isHeightFixMode = mode === 'heightFix'
191
- const isCropMode = cropMode.includes(mode)
194
+ const isCropMode = hasOwn(cropModeMap, mode)
192
195
  const isLayoutMode = isWidthFixMode || isHeightFixMode || isCropMode
193
- const resizeMode: ImageResizeMode = ModeMap.get(mode) || 'stretch'
196
+ const resizeMode: ImageResizeMode = hasOwn(modeResizeMap, mode) ? modeResizeMap[mode] : 'stretch'
194
197
 
195
198
  const onLayout = ({ nativeEvent: { layout: { width, height } } }: LayoutChangeEvent) => {
196
199
  state.current.viewWidth = width
@@ -217,7 +220,12 @@ const Image = forwardRef<HandlerRef<RNImage, ImageProps>, ImageProps>((props, re
217
220
  normalStyle,
218
221
  setWidth,
219
222
  setHeight
220
- } = useTransformStyle(styleObj, { enableVar, transformRadiusPercent: isAndroid && !isSvg && !isLayoutMode, externalVarContext, parentFontSize, parentWidth, parentHeight })
223
+ } = useTransformStyle(styleObj, { enableVar, transformRadiusPercent: isAndroid && !isSvg && !isLayoutMode, parentWidth, parentHeight, defaultStyle: DEFAULT_IMAGE_STYLE })
224
+
225
+ // normalStyle 已合入 DEFAULT_IMAGE_STYLE,对外暴露完整 style(含 default 兜底的 width/height)
226
+ useNodesRef(props, ref, nodeRef, {
227
+ style: normalStyle
228
+ })
221
229
 
222
230
  const { layoutRef, layoutStyle, layoutProps } = useLayout({
223
231
  props,
@@ -225,7 +233,7 @@ const Image = forwardRef<HandlerRef<RNImage, ImageProps>, ImageProps>((props, re
225
233
  setWidth,
226
234
  setHeight,
227
235
  nodeRef,
228
- onLayout: isLayoutMode ? onLayout : noop
236
+ onLayout: isLayoutMode ? onLayout : undefined
229
237
  })
230
238
 
231
239
  const { width, height } = normalStyle
@@ -504,7 +512,8 @@ const Image = forwardRef<HandlerRef<RNImage, ImageProps>, ImageProps>((props, re
504
512
  const svgProps = {
505
513
  onLayout: onSvgLoad,
506
514
  style: extendObject(
507
- { transformOrigin: 'left top' },
515
+ {},
516
+ SVG_TRANSFORM_ORIGIN_STYLE,
508
517
  modeStyle
509
518
  )
510
519
  }
@@ -518,21 +527,20 @@ const Image = forwardRef<HandlerRef<RNImage, ImageProps>, ImageProps>((props, re
518
527
  }
519
528
 
520
529
  function renderBaseImage () {
530
+ const baseImageStyle = isCropMode
531
+ ? extendObject(
532
+ { transformOrigin: 'left top', width: imageWidth, height: imageHeight },
533
+ modeStyle
534
+ )
535
+ : BASE_IMAGE_FILL_STYLE
521
536
  return renderImage(
522
537
  extendObject(
523
538
  {
524
- source: normalizeImageSource(src),
539
+ source: imageSource,
525
540
  resizeMode: resizeMode,
526
541
  onLoad: bindload && onImageLoad,
527
542
  onError: binderror && onImageError,
528
- style: extendObject(
529
- {
530
- transformOrigin: 'left top',
531
- width: isCropMode ? imageWidth : '100%',
532
- height: isCropMode ? imageHeight : '100%'
533
- },
534
- isCropMode ? modeStyle : {}
535
- )
543
+ style: baseImageStyle
536
544
  },
537
545
  isLayoutMode ? {} : innerProps
538
546
  ),
@@ -1,20 +1,29 @@
1
1
  import { Text, TextProps } from 'react-native'
2
2
  import { JSX, createElement, useContext } from 'react'
3
3
 
4
- import { extendObject, getDefaultAllowFontScaling } from './utils'
4
+ import { extendObject, getDefaultAllowFontScaling, resolveTextLineHeightPercentStyle } from './utils'
5
5
  import { TextPassThroughContext } from './context'
6
6
 
7
7
  const InlineText = (props: TextProps): JSX.Element => {
8
8
  const inheritedText = useContext(TextPassThroughContext)
9
- const style = extendObject({}, inheritedText?.textStyle, props.style)
10
- const mergedProps = extendObject({}, inheritedText?.pendingTextProps, props, { style })
9
+ const mergedStyle = inheritedText?.textStyle
10
+ ? extendObject({}, inheritedText.textStyle)
11
+ : undefined
12
+ // inline-text 只包裹裸文本,消费继承文本样式中的相对 lineHeight,不处理本地样式。
13
+ if (inheritedText?.textStyle) {
14
+ resolveTextLineHeightPercentStyle(mergedStyle, inheritedText.textStyle)
15
+ }
16
+ const mergedProps = inheritedText?.pendingTextProps
17
+ ? extendObject({}, inheritedText.pendingTextProps, props)
18
+ : props
11
19
  const {
12
20
  allowFontScaling,
13
21
  children
14
22
  } = mergedProps
15
23
 
16
24
  return createElement(Text, extendObject({}, mergedProps, {
17
- allowFontScaling: allowFontScaling ?? getDefaultAllowFontScaling()
25
+ allowFontScaling: allowFontScaling ?? getDefaultAllowFontScaling(),
26
+ style: mergedStyle
18
27
  }), children)
19
28
  }
20
29
 
@@ -97,8 +97,6 @@ export interface InputProps {
97
97
  'placeholder-style'?: { color?: string }
98
98
  'enable-offset'?: boolean
99
99
  'enable-var'?: boolean
100
- 'external-var-context'?: Record<string, any>
101
- 'parent-font-size'?: number
102
100
  'parent-width'?: number
103
101
  'parent-height'?: number
104
102
  // 只有 RN 环境读取
@@ -148,8 +146,6 @@ const Input = forwardRef<HandlerRef<TextInput, FinalInputProps>, FinalInputProps
148
146
  'selection-start': selectionStart = -1,
149
147
  'selection-end': selectionEnd = -1,
150
148
  'enable-var': enableVar,
151
- 'external-var-context': externalVarContext,
152
- 'parent-font-size': parentFontSize,
153
149
  'parent-width': parentWidth,
154
150
  'parent-height': parentHeight,
155
151
  'adjust-position': adjustPosition = true,
@@ -212,7 +208,7 @@ const Input = forwardRef<HandlerRef<TextInput, FinalInputProps>, FinalInputProps
212
208
  normalStyle,
213
209
  setWidth,
214
210
  setHeight
215
- } = useTransformStyle(styleObj, { enableVar, externalVarContext, parentFontSize, parentWidth, parentHeight })
211
+ } = useTransformStyle(styleObj, { enableVar, parentWidth, parentHeight })
216
212
 
217
213
  const nodeRef = useRef(null)
218
214
  useNodesRef(props, ref, nodeRef, {
@@ -295,7 +291,7 @@ const Input = forwardRef<HandlerRef<TextInput, FinalInputProps>, FinalInputProps
295
291
  setKeyboardAvoidContext()
296
292
  }
297
293
 
298
- const onTouchEnd = (evt: NativeSyntheticEvent<NativeTouchEvent & { origin?: string }>) => {
294
+ const markEventOrigin = (evt: NativeSyntheticEvent<NativeTouchEvent & { origin?: string }>) => {
299
295
  evt.nativeEvent.origin = 'input'
300
296
  }
301
297
 
@@ -473,7 +469,18 @@ const Input = forwardRef<HandlerRef<TextInput, FinalInputProps>, FinalInputProps
473
469
  // React Native 的 TextInput 在 textAlign center + placeholder 时光标会跑到右边
474
470
  // 这个问题只在 Android 上出现
475
471
  // 参考:https://github.com/facebook/react-native/issues/28794 (Android only)
476
- const needMultilineFix = isAndroid && !multiline
472
+ const conditionalTextInputProps: {
473
+ multiline?: boolean
474
+ numberOfLines?: number
475
+ enterKeyHint?: ConfirmType
476
+ } = {}
477
+ if (isAndroid && !multiline && props.placeholder && normalStyle.textAlign === 'center') {
478
+ conditionalTextInputProps.multiline = true
479
+ conditionalTextInputProps.numberOfLines = 1
480
+ }
481
+ if (!multiline || confirmType !== 'return') {
482
+ conditionalTextInputProps.enterKeyHint = confirmType
483
+ }
477
484
 
478
485
  const innerProps = useInnerProps(
479
486
  extendObject(
@@ -494,13 +501,14 @@ const Input = forwardRef<HandlerRef<TextInput, FinalInputProps>, FinalInputProps
494
501
  autoFocus: isAutoFocus,
495
502
  selection: selectionStart > -1 || typeof cursor === 'number' ? selection : undefined,
496
503
  selectionColor: cursorColor,
497
- blurOnSubmit: multiline ? confirmType !== 'return' : !confirmHold,
504
+ submitBehavior: multiline ? (confirmType === 'return' ? 'newline' : 'blurAndSubmit') : (confirmHold ? 'submit' : 'blurAndSubmit'),
498
505
  underlineColorAndroid: 'rgba(0,0,0,0)',
499
506
  textAlignVertical: textAlignVertical,
500
507
  placeholderTextColor: placeholderStyle?.color,
501
- multiline: multiline || needMultilineFix,
508
+ multiline,
502
509
  onTouchStart,
503
- onTouchEnd,
510
+ onTouchEnd: markEventOrigin,
511
+ onTouchMove: markEventOrigin,
504
512
  onFocus,
505
513
  onBlur,
506
514
  onChange,
@@ -508,8 +516,7 @@ const Input = forwardRef<HandlerRef<TextInput, FinalInputProps>, FinalInputProps
508
516
  onContentSizeChange,
509
517
  onSubmitEditing: bindconfirm && onSubmitEditing
510
518
  },
511
- needMultilineFix ? { numberOfLines: 1 } : {},
512
- !!multiline && confirmType === 'return' ? {} : { enterKeyHint: confirmType }
519
+ conditionalTextInputProps
513
520
  ),
514
521
  [
515
522
  'name',
@@ -6,7 +6,7 @@ import { View, ViewStyle, NativeSyntheticEvent } from 'react-native'
6
6
  import { noop, warn } from '@mpxjs/utils'
7
7
  import useInnerProps, { getCustomEvent } from './getInnerListeners'
8
8
  import useNodesRef, { HandlerRef } from './useNodesRef'
9
- import { splitProps, splitStyle, useLayout, useTransformStyle, wrapChildren, extendObject, useTextPassThroughValue } from './utils'
9
+ import { splitProps, splitStyle, useLayout, useTransformStyle, wrapChildren, extendObject, useTextPassThrough } from './utils'
10
10
  import { LabelContext, LabelContextValue } from './context'
11
11
  import Portal from './mpx-portal'
12
12
 
@@ -15,8 +15,7 @@ export interface LabelProps {
15
15
  style?: ViewStyle & Record<string, any>
16
16
  'enable-offset'?: boolean
17
17
  'enable-var'?: boolean
18
- 'external-var-context'?: Record<string, any>
19
- 'parent-font-size'?: number
18
+ 'enable-text-pass-through'?: boolean
20
19
  'parent-width'?: number
21
20
  'parent-height'?: number
22
21
  children: ReactNode
@@ -31,8 +30,7 @@ const Label = forwardRef<HandlerRef<View, LabelProps>, LabelProps>(
31
30
  const {
32
31
  style = {},
33
32
  'enable-var': enableVar,
34
- 'external-var-context': externalVarContext,
35
- 'parent-font-size': parentFontSize,
33
+ 'enable-text-pass-through': enableTextPassThrough,
36
34
  'parent-width': parentWidth,
37
35
  'parent-height': parentHeight
38
36
  } = props
@@ -43,8 +41,6 @@ const Label = forwardRef<HandlerRef<View, LabelProps>, LabelProps>(
43
41
  flexDirection: 'row'
44
42
  }
45
43
 
46
- const styleObj = extendObject({}, defaultStyle, style)
47
-
48
44
  const {
49
45
  hasPositionFixed,
50
46
  hasSelfPercent,
@@ -53,7 +49,7 @@ const Label = forwardRef<HandlerRef<View, LabelProps>, LabelProps>(
53
49
  varContextRef,
54
50
  setWidth,
55
51
  setHeight
56
- } = useTransformStyle(styleObj, { enableVar, externalVarContext, parentFontSize, parentWidth, parentHeight })
52
+ } = useTransformStyle(style, { enableVar, parentWidth, parentHeight, defaultStyle })
57
53
 
58
54
  const nodeRef = useRef(null)
59
55
  useNodesRef(props, ref, nodeRef, { style: normalStyle })
@@ -61,7 +57,7 @@ const Label = forwardRef<HandlerRef<View, LabelProps>, LabelProps>(
61
57
  const { layoutRef, layoutStyle, layoutProps } = useLayout({ props, hasSelfPercent, setWidth, setHeight, nodeRef })
62
58
 
63
59
  const { textStyle, backgroundStyle, innerStyle = {} } = splitStyle(normalStyle)
64
- const textPassThrough = useTextPassThroughValue(textStyle, textProps)
60
+ const textPassThrough = useTextPassThrough(textStyle, textProps, { enableTextPassThrough })
65
61
 
66
62
  if (backgroundStyle) {
67
63
  warn('Label does not support background image-related styles!')
@@ -100,7 +96,7 @@ const Label = forwardRef<HandlerRef<View, LabelProps>, LabelProps>(
100
96
  LabelContext.Provider,
101
97
  { value: contextRef },
102
98
  wrapChildren(
103
- props,
99
+ props.children,
104
100
  {
105
101
  hasVarDec,
106
102
  varContext: varContextRef.current,
@@ -17,14 +17,12 @@ interface MovableAreaProps {
17
17
  height?: number
18
18
  'enable-offset'?: boolean
19
19
  'enable-var'?: boolean
20
- 'external-var-context'?: Record<string, any>
21
- 'parent-font-size'?: number
22
20
  'parent-width'?: number
23
21
  'parent-height'?: number
24
22
  }
25
23
 
26
24
  const _MovableArea = forwardRef<HandlerRef<View, MovableAreaProps>, MovableAreaProps>((props: MovableAreaProps, ref): JSX.Element => {
27
- const { style = {}, 'enable-var': enableVar, 'external-var-context': externalVarContext, 'parent-font-size': parentFontSize, 'parent-width': parentWidth, 'parent-height': parentHeight } = props
25
+ const { style = {}, 'enable-var': enableVar, 'parent-width': parentWidth, 'parent-height': parentHeight } = props
28
26
 
29
27
  const {
30
28
  hasSelfPercent,
@@ -34,7 +32,7 @@ const _MovableArea = forwardRef<HandlerRef<View, MovableAreaProps>, MovableAreaP
34
32
  hasPositionFixed,
35
33
  setWidth,
36
34
  setHeight
37
- } = useTransformStyle(style, { enableVar, externalVarContext, parentFontSize, parentWidth, parentHeight })
35
+ } = useTransformStyle(style, { enableVar, parentWidth, parentHeight })
38
36
 
39
37
  const movableViewRef = useRef(null)
40
38
  useNodesRef(props, ref, movableViewRef, {
@@ -66,7 +64,7 @@ const _MovableArea = forwardRef<HandlerRef<View, MovableAreaProps>, MovableAreaP
66
64
  View,
67
65
  innerProps,
68
66
  wrapChildren(
69
- props,
67
+ props.children,
70
68
  {
71
69
  hasVarDec,
72
70
  varContext: varContextRef.current
@@ -22,7 +22,7 @@ import { StyleSheet, View, LayoutChangeEvent } from 'react-native'
22
22
  import useInnerProps, { getCustomEvent } from './getInnerListeners'
23
23
  import useNodesRef, { HandlerRef } from './useNodesRef'
24
24
  import { MovableAreaContext } from './context'
25
- import { useTransformStyle, splitProps, splitStyle, HIDDEN_STYLE, wrapChildren, GestureHandler, flatGesture, extendObject, omit, useNavigation, useRunOnJSCallback, useTextPassThroughValue } from './utils'
25
+ import { useTransformStyle, splitProps, splitStyle, hiddenStyle, wrapChildren, GestureHandler, flatGesture, extendObject, omit, useNavigation, useRunOnJSCallback, useTextPassThrough } from './utils'
26
26
  import { GestureDetector, Gesture, GestureTouchEvent, GestureStateChangeEvent, PanGestureHandlerEventPayload, PanGesture } from 'react-native-gesture-handler'
27
27
  import Animated, {
28
28
  useSharedValue,
@@ -179,8 +179,7 @@ interface MovableViewProps {
179
179
  'simultaneous-handlers'?: Array<GestureHandler>
180
180
  inertia?: boolean
181
181
  'enable-var'?: boolean
182
- 'external-var-context'?: Record<string, any>
183
- 'parent-font-size'?: number
182
+ 'enable-text-pass-through'?: boolean
184
183
  'parent-width'?: number
185
184
  'parent-height'?: number
186
185
  'disable-event-passthrough'?: boolean
@@ -213,8 +212,7 @@ const _MovableView = forwardRef<HandlerRef<View, MovableViewProps>, MovableViewP
213
212
  friction = 2,
214
213
  'out-of-bounds': outOfBounds = false,
215
214
  'enable-var': enableVar,
216
- 'external-var-context': externalVarContext,
217
- 'parent-font-size': parentFontSize,
215
+ 'enable-text-pass-through': enableTextPassThrough,
218
216
  'parent-width': parentWidth,
219
217
  'parent-height': parentHeight,
220
218
  direction = 'none',
@@ -243,7 +241,7 @@ const _MovableView = forwardRef<HandlerRef<View, MovableViewProps>, MovableViewP
243
241
  varContextRef,
244
242
  setWidth,
245
243
  setHeight
246
- } = useTransformStyle(Object.assign({}, style, styles.container), { enableVar, externalVarContext, parentFontSize, parentWidth, parentHeight })
244
+ } = useTransformStyle(Object.assign({}, style, styles.container), { enableVar, parentWidth, parentHeight })
247
245
 
248
246
  const navigation = useNavigation()
249
247
 
@@ -251,7 +249,7 @@ const _MovableView = forwardRef<HandlerRef<View, MovableViewProps>, MovableViewP
251
249
  const prevWaitForHandlersRef = useRef<Array<GestureHandler>>(waitFor || [])
252
250
  const gestureSwitch = useRef(false)
253
251
  const { textStyle, innerStyle } = splitStyle(normalStyle)
254
- const textPassThrough = useTextPassThroughValue(textStyle, textProps)
252
+ const textPassThrough = useTextPassThrough(textStyle, textProps, { enableTextPassThrough })
255
253
 
256
254
  const offsetX = useSharedValue(x)
257
255
  const offsetY = useSharedValue(y)
@@ -719,7 +717,7 @@ const _MovableView = forwardRef<HandlerRef<View, MovableViewProps>, MovableViewP
719
717
  return handlers
720
718
  }
721
719
 
722
- const layoutStyle = !hasLayoutRef.current && hasSelfPercent ? HIDDEN_STYLE : {}
720
+ const layoutStyle = !hasLayoutRef.current && hasSelfPercent ? hiddenStyle : {}
723
721
 
724
722
  // bind 相关 touch 事件直接由 gesture 触发,无须重复挂载
725
723
  // catch 相关 touch 事件需要重写并通过 useInnerProps 注入阻止冒泡逻辑
@@ -769,7 +767,7 @@ const _MovableView = forwardRef<HandlerRef<View, MovableViewProps>, MovableViewP
769
767
  Animated.View,
770
768
  innerProps,
771
769
  wrapChildren(
772
- props,
770
+ props.children,
773
771
  {
774
772
  hasVarDec,
775
773
  varContext: varContextRef.current,
@@ -95,7 +95,7 @@ const MpxNav = memo(({ pageConfig, navigation }: MpxNavProps) => {
95
95
  }
96
96
  const isCustom = innerPageConfig.navigationStyle === 'custom'
97
97
  const navigationBarTextStyle = useMemo(() => validBarTextStyle(innerPageConfig.navigationBarTextStyle), [innerPageConfig.navigationBarTextStyle])
98
- // 状态栏的颜色
98
+ // 状态栏由 MpxNav 根据页面配置统一控制,避免 native-stack screenOptions 在页面切换时覆盖页面级配置。
99
99
  const statusBarElement = (
100
100
  <StatusBar
101
101
  translucent