@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
@@ -6,10 +6,11 @@ import PickerMultiSelector from './multiSelector'
6
6
  import PickerTime from './time'
7
7
  import PickerDate from './date'
8
8
  import PickerRegion from './region'
9
+ import Portal from '../mpx-portal'
9
10
  import { FormContext, FormFieldValue, RouteContext } from '../context'
10
11
  import useNodesRef, { HandlerRef } from '../useNodesRef'
11
12
  import useInnerProps, { getCustomEvent } from '../getInnerListeners'
12
- import { extendObject, useLayout } from '../utils'
13
+ import { extendObject, splitProps, splitStyle, useLayout, useTextPassThrough, useTransformStyle, wrapChildren } from '../utils'
13
14
  import { createPopupManager } from '../mpx-popup'
14
15
  import { EventType, LanguageCode, PickerMode, PickerProps } from './type'
15
16
 
@@ -78,13 +79,13 @@ const styles = StyleSheet.create({
78
79
  }
79
80
  })
80
81
 
81
- const pickerModalMap: Record<PickerMode, React.ComponentType<PickerProps>> = {
82
+ const pickerModalMap = {
82
83
  [PickerMode.SELECTOR]: PickerSelector,
83
84
  [PickerMode.MULTI_SELECTOR]: PickerMultiSelector,
84
85
  [PickerMode.TIME]: PickerTime,
85
86
  [PickerMode.DATE]: PickerDate,
86
87
  [PickerMode.REGION]: PickerRegion
87
- }
88
+ } satisfies Record<PickerMode, React.ComponentType<any>>
88
89
 
89
90
  const getDefaultValue = (mode: PickerMode) => {
90
91
  switch (mode) {
@@ -111,17 +112,26 @@ const buttonTextMap: Record<LanguageCode, { cancel: string; confirm: string }> =
111
112
  }
112
113
 
113
114
  const Picker = forwardRef<HandlerRef<View, PickerProps>, PickerProps>(
114
- (props: PickerProps, ref): React.JSX.Element => {
115
+ (pickerProps: PickerProps, ref): React.JSX.Element => {
116
+ const { textProps, innerProps: splitInnerProps } = splitProps(pickerProps)
117
+ const props = (splitInnerProps || {}) as PickerProps
115
118
  const {
116
119
  mode,
117
120
  value,
118
- range = null,
121
+ range = [],
119
122
  children,
120
123
  disabled,
121
124
  bindcancel,
122
125
  bindchange,
123
- 'header-text': headerText = ''
126
+ 'header-text': headerText = '',
127
+ style,
128
+ 'enable-var': enableVar,
129
+ 'enable-text-pass-through': enableTextPassThrough,
130
+ 'parent-width': parentWidth,
131
+ 'parent-height': parentHeight
124
132
  } = props
133
+ const modalProps = props as any
134
+ const rangeKey = modalProps['range-key']
125
135
 
126
136
  const { pageId } = useContext(RouteContext) || {}
127
137
  const buttonText = buttonTextMap[(global.__mpx?.i18n?.locale as LanguageCode) || 'zh-CN']
@@ -129,12 +139,31 @@ const Picker = forwardRef<HandlerRef<View, PickerProps>, PickerProps>(
129
139
  pickerValue.current = Array.isArray(value) ? value.slice() : value
130
140
  const nodeRef = useRef<View>(null)
131
141
  const pickerRef = useRef<any>(null)
132
- const { open, show, hide, remove } = useRef(createPopupManager()).current
142
+ const { open, show, hide, remove, update } = useRef(createPopupManager()).current
143
+ const {
144
+ normalStyle,
145
+ hasVarDec,
146
+ varContextRef,
147
+ hasSelfPercent,
148
+ hasPositionFixed,
149
+ setWidth,
150
+ setHeight
151
+ } = useTransformStyle(style, { enableVar, parentWidth, parentHeight })
152
+ const { textStyle, backgroundStyle, innerStyle = {} } = splitStyle(normalStyle)
153
+ const textPassThrough = useTextPassThrough(textStyle, textProps, { enableTextPassThrough })
133
154
 
134
- useNodesRef<View, PickerProps>(props, ref, nodeRef)
135
- const { layoutRef, layoutProps } = useLayout({
155
+ if (backgroundStyle) {
156
+ warn('Picker does not support background image-related styles!')
157
+ }
158
+
159
+ useNodesRef<View, PickerProps>(props, ref, nodeRef, {
160
+ style: normalStyle
161
+ })
162
+ const { layoutRef, layoutProps, layoutStyle } = useLayout({
136
163
  props,
137
- hasSelfPercent: false,
164
+ hasSelfPercent,
165
+ setWidth,
166
+ setHeight,
138
167
  nodeRef
139
168
  })
140
169
 
@@ -143,7 +172,8 @@ const Picker = forwardRef<HandlerRef<View, PickerProps>, PickerProps>(
143
172
  {},
144
173
  props,
145
174
  {
146
- ref: nodeRef
175
+ ref: nodeRef,
176
+ style: extendObject({}, innerStyle, layoutStyle)
147
177
  },
148
178
  layoutProps
149
179
  ),
@@ -151,6 +181,12 @@ const Picker = forwardRef<HandlerRef<View, PickerProps>, PickerProps>(
151
181
  'mode',
152
182
  'value',
153
183
  'range',
184
+ 'range-key',
185
+ 'start',
186
+ 'end',
187
+ 'fields',
188
+ 'level',
189
+ 'custom-item',
154
190
  'disabled',
155
191
  'bindcancel',
156
192
  'bindchange',
@@ -163,9 +199,9 @@ const Picker = forwardRef<HandlerRef<View, PickerProps>, PickerProps>(
163
199
 
164
200
  useEffect(() => {
165
201
  if (range && pickerRef.current && mode === PickerMode.MULTI_SELECTOR) {
166
- pickerRef.current.updateRange?.(range)
202
+ pickerRef.current.updateRange?.(range, rangeKey)
167
203
  }
168
- }, [JSON.stringify(range)])
204
+ }, [JSON.stringify(range), rangeKey, mode])
169
205
 
170
206
  /** --- form 表单组件内部方法 --- */
171
207
  const getValue = () => {
@@ -228,15 +264,9 @@ const Picker = forwardRef<HandlerRef<View, PickerProps>, PickerProps>(
228
264
  hide()
229
265
  }
230
266
 
231
- const specificProps = extendObject({}, innerProps, {
232
- mode,
233
- children,
234
- bindchange: onChange,
235
- bindcolumnchange: onColumnChange,
236
- getRange: () => range
237
- })
267
+ const getContentHeight = () => headerText ? 350 : 310
238
268
 
239
- const renderPickerContent = () => {
269
+ const getPickerContent = () => {
240
270
  if (disabled) {
241
271
  return null
242
272
  }
@@ -244,9 +274,21 @@ const Picker = forwardRef<HandlerRef<View, PickerProps>, PickerProps>(
244
274
  if (!(_mode in pickerModalMap)) {
245
275
  return warn(`[Mpx runtime warn]: Unsupported <picker> mode: ${mode}`)
246
276
  }
277
+ const specificProps = {
278
+ mode: _mode,
279
+ range,
280
+ 'range-key': rangeKey,
281
+ start: modalProps.start,
282
+ end: modalProps.end,
283
+ fields: modalProps.fields,
284
+ level: modalProps.level,
285
+ 'custom-item': modalProps['custom-item'],
286
+ bindchange: onChange,
287
+ bindcolumnchange: onColumnChange
288
+ } as PickerProps
247
289
  const _value: any = value
248
- const PickerModal = pickerModalMap[_mode]
249
- const renderPickerModal = (
290
+ const PickerModal = pickerModalMap[_mode] as React.ComponentType<PickerProps>
291
+ return (
250
292
  <>
251
293
  {headerText && (
252
294
  <View style={[styles.header]}>
@@ -270,22 +312,51 @@ const Picker = forwardRef<HandlerRef<View, PickerProps>, PickerProps>(
270
312
  </View>
271
313
  </>
272
314
  )
273
- const contentHeight = headerText ? 350 : 310
274
- open(renderPickerModal, pageId, { contentHeight })
315
+ }
316
+
317
+ const openPickerContent = () => {
318
+ const renderPickerModal = getPickerContent()
319
+ if (!renderPickerModal) {
320
+ return
321
+ }
322
+ open(renderPickerModal, pageId, { contentHeight: getContentHeight() })
275
323
  }
276
324
 
277
325
  useEffect(() => {
278
- renderPickerContent()
326
+ openPickerContent()
279
327
  return () => {
280
328
  remove()
281
329
  }
282
330
  }, [])
283
331
 
284
- return createElement(
332
+ const showPicker = () => {
333
+ const renderPickerModal = getPickerContent()
334
+ if (!renderPickerModal) {
335
+ return
336
+ }
337
+ update(renderPickerModal, { contentHeight: getContentHeight() })
338
+ show()
339
+ }
340
+
341
+ const finalComponent = createElement(
285
342
  TouchableWithoutFeedback,
286
- { onPress: show },
287
- createElement(View, innerProps, children)
343
+ { onPress: showPicker },
344
+ createElement(
345
+ View,
346
+ innerProps,
347
+ wrapChildren(children, {
348
+ hasVarDec,
349
+ varContext: varContextRef.current,
350
+ textPassThrough
351
+ })
352
+ )
288
353
  )
354
+
355
+ if (hasPositionFixed) {
356
+ return createElement(Portal, null, finalComponent)
357
+ }
358
+
359
+ return finalComponent
289
360
  }
290
361
  )
291
362
 
@@ -23,7 +23,7 @@ const styles = StyleSheet.create({
23
23
  })
24
24
 
25
25
  const formatRangeFun = (range: RangeItem[], rangeKey = '') =>
26
- rangeKey ? range.map((item: Obj) => item[rangeKey]) : range
26
+ rangeKey ? range.map((item) => (item as Obj)[rangeKey]) : range
27
27
 
28
28
  const formatValueFn = (value: number | number[]) => {
29
29
  return Array.isArray(value) ? value : [value]
@@ -54,8 +54,8 @@ const PickerMultiSelector = forwardRef<
54
54
  }
55
55
  }, [formatValue])
56
56
 
57
- const updateRange = (newRange: RangeItem[]) => {
58
- const range = formatRangeFun(newRange.slice(), props['range-key'])
57
+ const updateRange = (newRange: RangeItem[], rangeKey?: string) => {
58
+ const range = formatRangeFun(newRange.slice(), rangeKey)
59
59
  setFormatRange(range)
60
60
  }
61
61
 
@@ -24,7 +24,7 @@ const styles = StyleSheet.create({
24
24
  })
25
25
 
26
26
  const formatRangeFun = (range: RangeItem[], rangeKey = '') =>
27
- rangeKey ? range.map((item: Obj) => item[rangeKey]) : range
27
+ rangeKey ? range.map((item) => (item as Obj)[rangeKey]) : range
28
28
 
29
29
  const formatValueFn = (value: number | number[] = 0) => {
30
30
  const _value = Array.isArray(value) ? value[0] : value
@@ -28,6 +28,10 @@ export interface BasePickerProps {
28
28
  /** 作为表单组件时的名称 */
29
29
  name?: string
30
30
  style?: Record<string, any>
31
+ 'enable-var'?: boolean
32
+ 'enable-text-pass-through'?: boolean
33
+ 'parent-width'?: number
34
+ 'parent-height'?: number
31
35
  children?: React.ReactNode
32
36
  range?: RangeItem[]
33
37
  ref?: any
@@ -9,9 +9,8 @@ import {
9
9
  wrapChildren,
10
10
  useTransformStyle,
11
11
  extendObject,
12
- useTextPassThroughValue
12
+ useTextPassThrough
13
13
  } from '../utils'
14
- import { PickerViewStyleContext } from './pickerVIewContext'
15
14
  import Portal from '../mpx-portal'
16
15
  import type { AnyFunc } from '../types/common'
17
16
  /**
@@ -38,7 +37,7 @@ interface PickerViewProps {
38
37
  'indicator-style'?: Record<string, any>,
39
38
  'mask-style'?: Record<string, any>,
40
39
  'enable-var'?: boolean
41
- 'external-var-context'?: Record<string, any>,
40
+ 'enable-text-pass-through'?: boolean
42
41
  'enable-offset'?: boolean
43
42
  }
44
43
 
@@ -75,7 +74,8 @@ const _PickerView = forwardRef<HandlerRef<View, PickerViewProps>, PickerViewProp
75
74
  'indicator-style': indicatorStyle = {},
76
75
  'mask-style': pickerMaskStyle = {},
77
76
  'enable-var': enableVar,
78
- 'external-var-context': externalVarContext
77
+ 'enable-text-pass-through': enableTextPassThrough
78
+
79
79
  } = props
80
80
  const { height: indicatorH, ...pickerIndicatorStyle } = indicatorStyle
81
81
  const nodeRef = useRef(null)
@@ -92,7 +92,7 @@ const _PickerView = forwardRef<HandlerRef<View, PickerViewProps>, PickerViewProp
92
92
  setWidth,
93
93
  setHeight,
94
94
  hasPositionFixed
95
- } = useTransformStyle(style, { enableVar, externalVarContext })
95
+ } = useTransformStyle(style, { enableVar })
96
96
 
97
97
  useNodesRef<View, PickerViewProps>(props, ref, nodeRef, {
98
98
  style: normalStyle
@@ -105,7 +105,7 @@ const _PickerView = forwardRef<HandlerRef<View, PickerViewProps>, PickerViewProp
105
105
  } = useLayout({ props, hasSelfPercent, setWidth, setHeight, nodeRef: nodeRef })
106
106
  const { textProps } = splitProps(props)
107
107
  const { textStyle } = splitStyle(normalStyle)
108
- const textPassThrough = useTextPassThroughValue(textStyle, textProps)
108
+ const textPassThrough = useTextPassThrough(textStyle, textProps, { enableTextPassThrough })
109
109
 
110
110
  const onSelectChange = (columnIndex: number, selectedIndex: number) => {
111
111
  const activeValue = activeValueRef.current
@@ -187,17 +187,7 @@ const _PickerView = forwardRef<HandlerRef<View, PickerViewProps>, PickerViewProp
187
187
  enableWheelAnimation
188
188
  }
189
189
  )
190
- const realElement = React.cloneElement(child, wrappedProps)
191
- return wrapChildren(
192
- {
193
- children: realElement
194
- },
195
- {
196
- hasVarDec,
197
- varContext: varContextRef.current,
198
- textPassThrough
199
- }
200
- )
190
+ return React.cloneElement(child, wrappedProps)
201
191
  }
202
192
 
203
193
  const validateChildInitialIndex = (index: number, data: React.ReactNode[]) => {
@@ -232,15 +222,18 @@ const _PickerView = forwardRef<HandlerRef<View, PickerViewProps>, PickerViewProp
232
222
  }
233
223
 
234
224
  const finalComponent = createElement(
235
- PickerViewStyleContext.Provider,
236
- { value: textStyle },
225
+ View,
226
+ innerProps,
237
227
  createElement(
238
228
  View,
239
- innerProps,
240
- createElement(
241
- View,
242
- { style: [styles.wrapper] },
243
- renderPickerColumns()
229
+ { style: [styles.wrapper] },
230
+ wrapChildren(
231
+ renderPickerColumns(),
232
+ {
233
+ hasVarDec,
234
+ varContext: varContextRef.current,
235
+ textPassThrough
236
+ }
244
237
  )
245
238
  )
246
239
  )
@@ -16,12 +16,3 @@ export const usePickerViewColumnAnimationContext = () => {
16
16
  }
17
17
  return value
18
18
  }
19
-
20
- export const PickerViewStyleContext = createContext<
21
- Record<string, any> | undefined
22
- >(undefined)
23
-
24
- export const usePickerViewStyleContext = () => {
25
- const value = useContext(PickerViewStyleContext)
26
- return value
27
- }
@@ -1,7 +1,7 @@
1
1
  import React, { forwardRef, useRef, useState, useMemo, useEffect, useCallback, createElement } from 'react'
2
2
  import { GestureResponderEvent, LayoutChangeEvent, NativeScrollEvent, NativeSyntheticEvent, ScrollView, StyleSheet, View } from 'react-native'
3
3
  import Reanimated, { AnimatedRef, useAnimatedRef, useScrollViewOffset } from 'react-native-reanimated'
4
- import { useTransformStyle, splitStyle, splitProps, useLayout, usePrevious, isAndroid, isIOS, isHarmony, extendObject } from '../utils'
4
+ import { useTransformStyle, splitStyle, splitProps, useLayout, usePrevious, isAndroid, isIOS, isHarmony, extendObject, useTextPassThrough, wrapChildren } from '../utils'
5
5
  import useNodesRef, { HandlerRef } from '../useNodesRef'
6
6
  import PickerIndicator from './pickerViewIndicator'
7
7
  import PickerMask from './pickerViewMask'
@@ -19,7 +19,6 @@ interface ColumnProps {
19
19
  [key: string]: any
20
20
  }
21
21
  'enable-var'?: boolean
22
- 'external-var-context'?: Record<string, any>
23
22
  wrapperStyle: {
24
23
  height: number
25
24
  itemHeight: number
@@ -27,6 +26,7 @@ interface ColumnProps {
27
26
  pickerMaskStyle: Record<string, any>
28
27
  pickerIndicatorStyle: Record<string, any>
29
28
  enableWheelAnimation?: boolean
29
+ 'enable-text-pass-through'?: boolean
30
30
  }
31
31
 
32
32
  const visibleCount = 5
@@ -43,17 +43,21 @@ const _PickerViewColumn = forwardRef<HandlerRef<ScrollView & View, ColumnProps>,
43
43
  pickerIndicatorStyle,
44
44
  enableWheelAnimation = true,
45
45
  'enable-var': enableVar,
46
- 'external-var-context': externalVarContext
46
+ 'enable-text-pass-through': enableTextPassThrough
47
+
47
48
  } = props
48
49
 
49
50
  const {
50
51
  normalStyle,
52
+ hasVarDec,
53
+ varContextRef,
51
54
  hasSelfPercent,
52
55
  setWidth,
53
56
  setHeight
54
- } = useTransformStyle(style, { enableVar, externalVarContext })
55
- const { textStyle = {} } = splitStyle(normalStyle)
56
- const { textProps = {} } = splitProps(props)
57
+ } = useTransformStyle(style, { enableVar })
58
+ const { textStyle } = splitStyle(normalStyle)
59
+ const { textProps } = splitProps(props)
60
+ const textPassThrough = useTextPassThrough(textStyle, textProps, { enableTextPassThrough })
57
61
  const scrollViewRef = useAnimatedRef<Reanimated.ScrollView>()
58
62
  const offsetYShared = useScrollViewOffset(scrollViewRef as AnimatedRef<Reanimated.ScrollView>)
59
63
 
@@ -62,14 +66,14 @@ const _PickerViewColumn = forwardRef<HandlerRef<ScrollView & View, ColumnProps>,
62
66
  })
63
67
 
64
68
  const { height: pickerH, itemHeight } = wrapperStyle
65
- const [itemRawH, setItemRawH] = useState(itemHeight)
69
+ const [itemRawH, setItemRawH] = useState(Math.round(itemHeight))
66
70
  const maxIndex = useMemo(() => columnData.length - 1, [columnData])
67
71
  const prevScrollingInfo = useRef({ index: initialIndex, y: 0 })
68
72
  const dragging = useRef(false)
69
73
  const scrolling = useRef(false)
70
- const timerResetPosition = useRef<NodeJS.Timeout | null>(null)
71
- const timerScrollTo = useRef<NodeJS.Timeout | null>(null)
72
- const timerClickOnce = useRef<NodeJS.Timeout | null>(null)
74
+ const timerResetPosition = useRef<ReturnType<typeof setTimeout> | null>(null)
75
+ const timerScrollTo = useRef<ReturnType<typeof setTimeout> | null>(null)
76
+ const timerClickOnce = useRef<ReturnType<typeof setTimeout> | null>(null)
73
77
  const activeIndex = useRef(initialIndex)
74
78
  const prevIndex = usePrevious(initialIndex)
75
79
  const prevMaxIndex = usePrevious(maxIndex)
@@ -85,8 +89,8 @@ const _PickerViewColumn = forwardRef<HandlerRef<ScrollView & View, ColumnProps>,
85
89
  })
86
90
 
87
91
  const paddingHeight = useMemo(
88
- () => Math.round((pickerH - itemHeight) / 2),
89
- [pickerH, itemHeight]
92
+ () => (pickerH - itemRawH) / 2,
93
+ [pickerH, itemRawH]
90
94
  )
91
95
 
92
96
  const snapToOffsets = useMemo(
@@ -136,6 +140,16 @@ const _PickerViewColumn = forwardRef<HandlerRef<ScrollView & View, ColumnProps>,
136
140
  }
137
141
  }, [])
138
142
 
143
+ // `contentOffset` prop sets visual position but does not fire scroll events,
144
+ // so `offsetYShared` (from `useScrollViewOffset`) stays at 0 until the user scrolls.
145
+ // Directly sync it whenever `itemRawH` is established so wheel animation renders correctly.
146
+ useEffect(() => {
147
+ if (!itemRawH || dragging.current || scrolling.current) {
148
+ return
149
+ }
150
+ offsetYShared.value = activeIndex.current * itemRawH
151
+ }, [itemRawH])
152
+
139
153
  useEffect(() => {
140
154
  if (
141
155
  !scrollViewRef.current ||
@@ -160,13 +174,20 @@ const _PickerViewColumn = forwardRef<HandlerRef<ScrollView & View, ColumnProps>,
160
174
  }, isIOS ? 0 : 200)
161
175
  }, [itemRawH, maxIndex, initialIndex])
162
176
 
177
+ useEffect(() => {
178
+ const roundedH = Math.round(itemHeight)
179
+ if (roundedH) {
180
+ setItemRawH(roundedH)
181
+ }
182
+ }, [itemHeight])
183
+
163
184
  const onItemLayout = useCallback((e: LayoutChangeEvent) => {
164
185
  const { height: rawH } = e.nativeEvent.layout
165
186
  const roundedH = Math.round(rawH)
166
- if (roundedH && roundedH !== itemRawH) {
187
+ if (roundedH) {
167
188
  setItemRawH(roundedH)
168
189
  }
169
- }, [itemRawH])
190
+ }, [])
170
191
 
171
192
  const resetScrollPosition = useCallback((y: number) => {
172
193
  if (dragging.current || scrolling.current) {
@@ -289,9 +310,7 @@ const _PickerViewColumn = forwardRef<HandlerRef<ScrollView & View, ColumnProps>,
289
310
  key={index}
290
311
  item={item}
291
312
  index={index}
292
- itemHeight={itemHeight}
293
- textStyle={textStyle}
294
- textProps={textProps}
313
+ itemHeight={itemRawH}
295
314
  visibleCount={visibleCount}
296
315
  onItemLayout={onItemLayout}
297
316
  />)
@@ -299,9 +318,7 @@ const _PickerViewColumn = forwardRef<HandlerRef<ScrollView & View, ColumnProps>,
299
318
  key={index}
300
319
  item={item}
301
320
  index={index}
302
- itemHeight={itemHeight}
303
- textStyle={textStyle}
304
- textProps={textProps}
321
+ itemHeight={itemRawH}
305
322
  onItemLayout={onItemLayout}
306
323
  />)
307
324
  })
@@ -335,21 +352,25 @@ const _PickerViewColumn = forwardRef<HandlerRef<ScrollView & View, ColumnProps>,
335
352
  createElement(
336
353
  Reanimated.ScrollView,
337
354
  innerProps,
338
- renderInnerchild()
355
+ wrapChildren(renderInnerchild(), {
356
+ hasVarDec,
357
+ varContext: varContextRef.current,
358
+ textPassThrough
359
+ })
339
360
  )
340
361
  )
341
362
  }
342
363
 
343
364
  const renderIndicator = () => (
344
365
  <PickerIndicator
345
- itemHeight={itemHeight}
366
+ itemHeight={itemRawH}
346
367
  indicatorItemStyle={pickerIndicatorStyle}
347
368
  />
348
369
  )
349
370
 
350
371
  const renderMask = () => (
351
372
  <PickerMask
352
- itemHeight={itemHeight}
373
+ itemHeight={itemRawH}
353
374
  maskContainerStyle={pickerMaskStyle}
354
375
  />
355
376
  )
@@ -3,16 +3,14 @@ import { LayoutChangeEvent } from 'react-native'
3
3
  import Reanimated, { Extrapolation, interpolate, useAnimatedStyle } from 'react-native-reanimated'
4
4
  import { extendObject } from '../utils'
5
5
  import { createFaces } from './pickerViewFaces'
6
- import { usePickerViewColumnAnimationContext, usePickerViewStyleContext } from '../mpx-picker-view/pickerVIewContext'
6
+ import { usePickerViewColumnAnimationContext } from '../mpx-picker-view/pickerVIewContext'
7
7
 
8
8
  interface PickerColumnItemProps {
9
9
  item: React.ReactElement
10
10
  index: number
11
11
  itemHeight: number
12
12
  itemWidth?: number | '100%'
13
- textStyle: Record<string, any>
14
13
  visibleCount: number
15
- textProps?: any
16
14
  onItemLayout?: (e: LayoutChangeEvent) => void
17
15
  }
18
16
 
@@ -21,12 +19,9 @@ const PickerViewColumnItem: React.FC<PickerColumnItemProps> = ({
21
19
  index,
22
20
  itemHeight,
23
21
  itemWidth = '100%',
24
- textStyle,
25
- textProps,
26
22
  visibleCount,
27
23
  onItemLayout
28
24
  }) => {
29
- const textStyleFromAncestor = usePickerViewStyleContext()
30
25
  const offsetYShared = usePickerViewColumnAnimationContext()
31
26
  const facesShared = useMemo(() => createFaces(itemHeight, visibleCount), [itemHeight, visibleCount])
32
27
 
@@ -48,12 +43,9 @@ const PickerViewColumnItem: React.FC<PickerColumnItemProps> = ({
48
43
  {
49
44
  style: extendObject(
50
45
  { height: itemHeight, width: '100%' },
51
- textStyleFromAncestor,
52
- textStyle,
53
46
  item.props.style
54
47
  )
55
48
  },
56
- textProps,
57
49
  restProps
58
50
  )
59
51
  const realItem = React.cloneElement(item, itemProps)
@@ -1,15 +1,12 @@
1
1
  import React from 'react'
2
2
  import { LayoutChangeEvent, View } from 'react-native'
3
3
  import { extendObject } from '../utils'
4
- import { usePickerViewStyleContext } from '../mpx-picker-view/pickerVIewContext'
5
4
 
6
5
  interface PickerColumnItemProps {
7
6
  item: React.ReactElement
8
7
  index: number
9
8
  itemHeight: number
10
9
  itemWidth?: number | '100%'
11
- textStyle: Record<string, any>
12
- textProps?: any
13
10
  onItemLayout?: (e: LayoutChangeEvent) => void
14
11
  }
15
12
 
@@ -18,23 +15,17 @@ const PickerViewColumnItem: React.FC<PickerColumnItemProps> = ({
18
15
  index,
19
16
  itemHeight,
20
17
  itemWidth = '100%',
21
- textStyle,
22
- textProps,
23
18
  onItemLayout
24
19
  }) => {
25
- const textStyleFromAncestor = usePickerViewStyleContext()
26
20
  const strKey = `picker-column-item-${index}`
27
21
  const restProps = index === 0 ? { onLayout: onItemLayout } : {}
28
22
  const itemProps = extendObject(
29
23
  {
30
24
  style: extendObject(
31
25
  { height: itemHeight, width: '100%' },
32
- textStyleFromAncestor,
33
- textStyle,
34
26
  item.props.style
35
27
  )
36
28
  },
37
- textProps,
38
29
  restProps
39
30
  )
40
31
  const realItem = React.cloneElement(item, itemProps)
@@ -11,6 +11,10 @@ export interface IUsePopupOptions {
11
11
  type?: PopupType
12
12
  }
13
13
 
14
+ type PopupOptions = {
15
+ contentHeight?: number
16
+ }
17
+
14
18
  /**
15
19
  * 根据 type 返回对应的弹窗壳子组件
16
20
  */
@@ -44,7 +48,7 @@ const createPopupManager = (options: IUsePopupOptions = {}) => {
44
48
  const open = (
45
49
  childComponent: React.ReactNode,
46
50
  pageId: number | undefined,
47
- options?: { contentHeight?: number }
51
+ options?: PopupOptions
48
52
  ) => {
49
53
  if (!isOpen && pageId != null) {
50
54
  isOpen = true
@@ -57,9 +61,9 @@ const createPopupManager = (options: IUsePopupOptions = {}) => {
57
61
  }
58
62
  }
59
63
 
60
- const update = (updatedChild: ReactElement | null) => {
64
+ const update = (updatedChild: ReactElement | null, options?: PopupOptions) => {
61
65
  if (popupKey !== null && child !== null && updatedChild !== null) {
62
- child = cloneElement(child, { children: updatedChild })
66
+ child = cloneElement(child, Object.assign({ children: updatedChild }, options))
63
67
  Portal.update(popupKey, child)
64
68
  }
65
69
  }
@@ -59,8 +59,9 @@ const PopupBase = (props: PopupBaseProps = {}) => {
59
59
  contentHeight = MOVEOUT_HEIGHT,
60
60
  visible = false
61
61
  } = props
62
+ const moveoutHeight = contentHeight + bottom
62
63
  const fade = useSharedValue<number>(MASK_OFF)
63
- const slide = useSharedValue<number>(contentHeight)
64
+ const slide = useSharedValue<number>(moveoutHeight)
64
65
 
65
66
  const animatedStylesMask = useAnimatedStyle(() => ({
66
67
  opacity: fade.value
@@ -87,7 +88,7 @@ const PopupBase = (props: PopupBaseProps = {}) => {
87
88
  duration: 300
88
89
  })
89
90
  slide.value = withTiming(
90
- contentHeight,
91
+ moveoutHeight,
91
92
  {
92
93
  easing: Easing.inOut(Easing.poly(3)),
93
94
  duration: 300