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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (158) hide show
  1. package/lib/dependencies/RecordGlobalComponentsDependency.js +11 -12
  2. package/lib/dependencies/RecordRuntimeInfoDependency.js +1 -1
  3. package/lib/index.js +29 -8
  4. package/lib/json-compiler/index.js +2 -11
  5. package/lib/loader.js +24 -45
  6. package/lib/native-loader.js +49 -64
  7. package/lib/platform/json/wx/index.js +24 -18
  8. package/lib/platform/style/wx/index.js +49 -47
  9. package/lib/platform/template/wx/component-config/canvas.js +8 -0
  10. package/lib/platform/template/wx/component-config/fix-component-name.js +15 -12
  11. package/lib/platform/template/wx/component-config/index.js +1 -1
  12. package/lib/platform/template/wx/component-config/input.js +1 -1
  13. package/lib/platform/template/wx/component-config/rich-text.js +8 -0
  14. package/lib/platform/template/wx/component-config/swiper.js +1 -1
  15. package/lib/platform/template/wx/component-config/textarea.js +1 -1
  16. package/lib/platform/template/wx/component-config/unsupported.js +1 -1
  17. package/lib/react/index.js +4 -3
  18. package/lib/react/processJSON.js +5 -13
  19. package/lib/react/processMainScript.js +7 -3
  20. package/lib/react/processScript.js +3 -4
  21. package/lib/react/processStyles.js +14 -4
  22. package/lib/react/processTemplate.js +5 -2
  23. package/lib/resolver/AddModePlugin.js +20 -7
  24. package/lib/runtime/components/react/context.ts +6 -0
  25. package/lib/runtime/components/react/dist/context.js +2 -0
  26. package/lib/runtime/components/react/dist/event.config.js +24 -24
  27. package/lib/runtime/components/react/dist/getInnerListeners.js +183 -174
  28. package/lib/runtime/components/react/dist/mpx-button.jsx +78 -50
  29. package/lib/runtime/components/react/dist/mpx-canvas/Bus.js +60 -0
  30. package/lib/runtime/components/react/dist/mpx-canvas/CanvasGradient.js +15 -0
  31. package/lib/runtime/components/react/dist/mpx-canvas/CanvasRenderingContext2D.js +84 -0
  32. package/lib/runtime/components/react/dist/mpx-canvas/Image.js +87 -0
  33. package/lib/runtime/components/react/dist/mpx-canvas/ImageData.js +15 -0
  34. package/lib/runtime/components/react/dist/mpx-canvas/constructorsRegistry.js +28 -0
  35. package/lib/runtime/components/react/dist/mpx-canvas/html.js +343 -0
  36. package/lib/runtime/components/react/dist/mpx-canvas/index.jsx +232 -0
  37. package/lib/runtime/components/react/dist/mpx-canvas/utils.jsx +89 -0
  38. package/lib/runtime/components/react/dist/mpx-checkbox-group.jsx +41 -34
  39. package/lib/runtime/components/react/dist/mpx-checkbox.jsx +30 -39
  40. package/lib/runtime/components/react/dist/mpx-form.jsx +47 -41
  41. package/lib/runtime/components/react/dist/mpx-icon.jsx +9 -17
  42. package/lib/runtime/components/react/dist/mpx-image.jsx +291 -0
  43. package/lib/runtime/components/react/dist/mpx-input.jsx +95 -62
  44. package/lib/runtime/components/react/dist/mpx-label.jsx +24 -28
  45. package/lib/runtime/components/react/dist/mpx-movable-area.jsx +20 -30
  46. package/lib/runtime/components/react/dist/mpx-movable-view.jsx +377 -293
  47. package/lib/runtime/components/react/dist/mpx-navigator.jsx +3 -5
  48. package/lib/runtime/components/react/dist/mpx-picker/date.jsx +6 -2
  49. package/lib/runtime/components/react/dist/mpx-picker/index.jsx +5 -3
  50. package/lib/runtime/components/react/dist/mpx-picker/multiSelector.jsx +6 -2
  51. package/lib/runtime/components/react/dist/mpx-picker/region.jsx +6 -2
  52. package/lib/runtime/components/react/dist/mpx-picker/selector.jsx +6 -2
  53. package/lib/runtime/components/react/dist/mpx-picker/time.jsx +10 -15
  54. package/lib/runtime/components/react/dist/mpx-picker-view-column-item.jsx +39 -0
  55. package/lib/runtime/components/react/dist/mpx-picker-view-column.jsx +160 -88
  56. package/lib/runtime/components/react/dist/mpx-picker-view.jsx +80 -121
  57. package/lib/runtime/components/react/dist/mpx-radio-group.jsx +39 -34
  58. package/lib/runtime/components/react/dist/mpx-radio.jsx +28 -43
  59. package/lib/runtime/components/react/dist/mpx-rich-text/html.js +39 -0
  60. package/lib/runtime/components/react/dist/mpx-rich-text/index.jsx +63 -0
  61. package/lib/runtime/components/react/dist/mpx-root-portal.jsx +7 -5
  62. package/lib/runtime/components/react/dist/mpx-scroll-view.jsx +77 -51
  63. package/lib/runtime/components/react/dist/mpx-simple-text.jsx +11 -0
  64. package/lib/runtime/components/react/dist/mpx-swiper-item.jsx +5 -3
  65. package/lib/runtime/components/react/dist/mpx-swiper.jsx +606 -0
  66. package/lib/runtime/components/react/dist/mpx-switch.jsx +28 -11
  67. package/lib/runtime/components/react/dist/mpx-text.jsx +12 -11
  68. package/lib/runtime/components/react/dist/mpx-textarea.jsx +9 -4
  69. package/lib/runtime/components/react/dist/mpx-view.jsx +66 -62
  70. package/lib/runtime/components/react/dist/mpx-web-view.jsx +113 -36
  71. package/lib/runtime/components/react/dist/pickerFaces.js +81 -0
  72. package/lib/runtime/components/react/dist/pickerVIewContext.js +9 -0
  73. package/lib/runtime/components/react/dist/pickerViewMask.jsx +18 -0
  74. package/lib/runtime/components/react/dist/pickerViewOverlay.jsx +23 -0
  75. package/lib/runtime/components/react/dist/useAnimationHooks.js +126 -12
  76. package/lib/runtime/components/react/dist/utils.jsx +80 -24
  77. package/lib/runtime/components/react/event.config.ts +25 -26
  78. package/lib/runtime/components/react/getInnerListeners.ts +237 -198
  79. package/lib/runtime/components/react/mpx-button.tsx +105 -58
  80. package/lib/runtime/components/react/mpx-canvas/Bus.ts +70 -0
  81. package/lib/runtime/components/react/mpx-canvas/CanvasGradient.ts +18 -0
  82. package/lib/runtime/components/react/mpx-canvas/CanvasRenderingContext2D.ts +87 -0
  83. package/lib/runtime/components/react/mpx-canvas/Image.ts +102 -0
  84. package/lib/runtime/components/react/mpx-canvas/ImageData.ts +23 -0
  85. package/lib/runtime/components/react/mpx-canvas/constructorsRegistry.ts +38 -0
  86. package/lib/runtime/components/react/mpx-canvas/html.ts +343 -0
  87. package/lib/runtime/components/react/mpx-canvas/index.tsx +296 -0
  88. package/lib/runtime/components/react/mpx-canvas/utils.tsx +150 -0
  89. package/lib/runtime/components/react/mpx-checkbox-group.tsx +77 -51
  90. package/lib/runtime/components/react/mpx-checkbox.tsx +49 -50
  91. package/lib/runtime/components/react/mpx-form.tsx +62 -57
  92. package/lib/runtime/components/react/mpx-icon.tsx +13 -18
  93. package/lib/runtime/components/react/mpx-image.tsx +436 -0
  94. package/lib/runtime/components/react/mpx-input.tsx +139 -117
  95. package/lib/runtime/components/react/mpx-label.tsx +36 -34
  96. package/lib/runtime/components/react/mpx-movable-area.tsx +26 -39
  97. package/lib/runtime/components/react/mpx-movable-view.tsx +455 -337
  98. package/lib/runtime/components/react/mpx-navigator.tsx +3 -9
  99. package/lib/runtime/components/react/mpx-picker/date.tsx +5 -2
  100. package/lib/runtime/components/react/mpx-picker/index.tsx +3 -2
  101. package/lib/runtime/components/react/mpx-picker/multiSelector.tsx +5 -2
  102. package/lib/runtime/components/react/mpx-picker/region.tsx +5 -2
  103. package/lib/runtime/components/react/mpx-picker/selector.tsx +5 -2
  104. package/lib/runtime/components/react/mpx-picker/time.tsx +10 -15
  105. package/lib/runtime/components/react/mpx-picker/type.ts +48 -43
  106. package/lib/runtime/components/react/mpx-picker-view-column.tsx +236 -104
  107. package/lib/runtime/components/react/mpx-picker-view.tsx +132 -122
  108. package/lib/runtime/components/react/mpx-radio-group.tsx +77 -54
  109. package/lib/runtime/components/react/mpx-radio.tsx +46 -55
  110. package/lib/runtime/components/react/mpx-rich-text/html.ts +40 -0
  111. package/lib/runtime/components/react/mpx-rich-text/index.tsx +121 -0
  112. package/lib/runtime/components/react/mpx-root-portal.tsx +4 -6
  113. package/lib/runtime/components/react/mpx-scroll-view.tsx +122 -76
  114. package/lib/runtime/components/react/mpx-simple-text.tsx +18 -0
  115. package/lib/runtime/components/react/mpx-swiper/carouse.tsx +6 -4
  116. package/lib/runtime/components/react/mpx-swiper/index.tsx +2 -1
  117. package/lib/runtime/components/react/mpx-swiper-item.tsx +4 -3
  118. package/lib/runtime/components/react/mpx-switch.tsx +39 -25
  119. package/lib/runtime/components/react/mpx-text.tsx +15 -19
  120. package/lib/runtime/components/react/mpx-textarea.tsx +12 -11
  121. package/lib/runtime/components/react/mpx-view.tsx +93 -77
  122. package/lib/runtime/components/react/mpx-web-view.tsx +117 -55
  123. package/lib/runtime/components/react/pickerFaces.ts +104 -0
  124. package/lib/runtime/components/react/pickerOverlay.tsx +32 -0
  125. package/lib/runtime/components/react/types/common.ts +2 -0
  126. package/lib/runtime/components/react/types/global.d.ts +5 -17
  127. package/lib/runtime/components/react/useAnimationHooks.ts +127 -18
  128. package/lib/runtime/components/react/useNodesRef.ts +1 -0
  129. package/lib/runtime/components/react/utils.tsx +113 -27
  130. package/lib/runtime/components/web/getInnerListeners.js +6 -6
  131. package/lib/runtime/components/web/mpx-movable-view.vue +334 -344
  132. package/lib/runtime/components/web/mpx-picker-view-column.vue +75 -75
  133. package/lib/runtime/components/web/mpx-picker.vue +382 -385
  134. package/lib/runtime/components/web/mpx-web-view.vue +175 -161
  135. package/lib/runtime/optionProcessor.js +7 -38
  136. package/lib/runtime/optionProcessorReact.js +0 -15
  137. package/lib/runtime/swanHelper.wxs +1 -1
  138. package/lib/runtime/utils.js +2 -0
  139. package/lib/style-compiler/index.js +1 -1
  140. package/lib/style-compiler/plugins/scope-id.js +31 -2
  141. package/lib/template-compiler/bind-this.js +7 -2
  142. package/lib/template-compiler/compiler.js +118 -56
  143. package/lib/template-compiler/gen-node-react.js +3 -3
  144. package/lib/template-compiler/index.js +4 -4
  145. package/lib/utils/pre-process-json.js +117 -0
  146. package/lib/web/index.js +5 -4
  147. package/lib/web/processJSON.js +5 -13
  148. package/lib/web/processTemplate.js +2 -2
  149. package/package.json +6 -4
  150. package/LICENSE +0 -433
  151. package/lib/runtime/components/react/dist/mpx-image/index.jsx +0 -226
  152. package/lib/runtime/components/react/dist/mpx-image/svg.jsx +0 -7
  153. package/lib/runtime/components/react/dist/mpx-swiper/carouse.jsx +0 -478
  154. package/lib/runtime/components/react/dist/mpx-swiper/index.jsx +0 -68
  155. package/lib/runtime/components/react/dist/mpx-swiper/type.js +0 -1
  156. package/lib/runtime/components/react/mpx-image/index.tsx +0 -346
  157. package/lib/runtime/components/react/mpx-image/svg.tsx +0 -22
  158. package/lib/runtime/components/web/event.js +0 -105
@@ -1,9 +1,19 @@
1
1
  import { View } from 'react-native'
2
- import { LinearGradient, LinearGradientProps } from 'react-native-linear-gradient'
3
- import React, { forwardRef, useState, useRef, ReactElement, JSX } from 'react'
2
+ import React, { forwardRef, useState, useRef } from 'react'
4
3
  import useInnerProps, { getCustomEvent } from './getInnerListeners'
5
- import useNodesRef, { HandlerRef } from './useNodesRef' // 引入辅助函数
6
- import { parseInlineStyle, useTransformStyle, splitStyle, splitProps, useLayout, wrapChildren } from './utils'
4
+ import useNodesRef, { HandlerRef } from './useNodesRef'
5
+ import {
6
+ useLayout,
7
+ splitProps,
8
+ splitStyle,
9
+ wrapChildren,
10
+ parseInlineStyle,
11
+ useTransformStyle,
12
+ useDebounceCallback,
13
+ useStableCallback,
14
+ extendObject
15
+ } from './utils'
16
+ import type { AnyFunc } from './types/common'
7
17
  /**
8
18
  * ✔ value
9
19
  * ✔ bindchange
@@ -18,9 +28,10 @@ import { parseInlineStyle, useTransformStyle, splitStyle, splitProps, useLayout,
18
28
 
19
29
  interface PickerViewProps {
20
30
  children: React.ReactNode
21
- // 初始的defaultValue数组中的数字依次表示 picker-view 内的 picker-view-column 选择的第几项(下标从 0 开始),数字大于 picker-view-column 可选项长度时,选择最后一项。
31
+ // 初始的defaultValue数组中的数字依次表示 picker-view 内的 picker-view-column 选择的第几项(下标从 0 开始),
32
+ // 数字大于 picker-view-column 可选项长度时,选择最后一项。
22
33
  value?: Array<number>
23
- bindchange?: Function
34
+ bindchange?: AnyFunc
24
35
  style: {
25
36
  [key: string]: any
26
37
  }
@@ -48,27 +59,29 @@ const styles: { [key: string]: Object } = {
48
59
  justifyContent: 'space-around',
49
60
  overflow: 'hidden',
50
61
  alignItems: 'center'
51
- },
52
- maskTop: {
53
- position: 'absolute',
54
- width: 1000,
55
- zIndex: 100
56
- },
57
- maskBottom: {
58
- position: 'absolute',
59
- width: 1000,
60
- zIndex: 100
61
62
  }
62
63
  }
64
+
63
65
  const _PickerView = forwardRef<HandlerRef<View, PickerViewProps>, PickerViewProps>((props: PickerViewProps, ref) => {
64
- const { children, value = [], bindchange, style, 'enable-var': enableVar, 'external-var-context': externalVarContext } = props
66
+ const {
67
+ children,
68
+ value = [],
69
+ bindchange,
70
+ style,
71
+ 'enable-var': enableVar,
72
+ 'external-var-context': externalVarContext
73
+ } = props
74
+
65
75
  // indicatorStyle 需要转换为rn的style
66
76
  // 微信设置到pick-view上上设置的normalStyle如border等需要转换成RN的style然后进行透传
67
77
  const indicatorStyle = parseInlineStyle(props['indicator-style'])
68
- const { height: indicatorH, width: indicatorW } = indicatorStyle
78
+ const { height: indicatorH, ...pickerOverlayStyle } = indicatorStyle
79
+ const [pickMaxH, setPickMaxH] = useState(0)
69
80
  const nodeRef = useRef(null)
70
- useNodesRef<View, PickerViewProps>(props, ref, nodeRef, {})
71
- // picker-view 设置的color等textStyle,在小程序上的表现是可以继承到最内层的text样式, 但是RN内部column是slot无法设置, 需要业务自己在column内的元素上设置
81
+ const cloneRef = useRef(null)
82
+ const activeValueRef = useRef(value)
83
+ activeValueRef.current = value.slice()
84
+
72
85
  const {
73
86
  normalStyle,
74
87
  hasVarDec,
@@ -77,69 +90,91 @@ const _PickerView = forwardRef<HandlerRef<View, PickerViewProps>, PickerViewProp
77
90
  setWidth,
78
91
  setHeight
79
92
  } = useTransformStyle(style, { enableVar, externalVarContext })
80
- const { textStyle } = splitStyle(normalStyle)
81
- const { textProps } = splitProps(props)
93
+
94
+ useNodesRef<View, PickerViewProps>(props, ref, nodeRef, {
95
+ style: normalStyle
96
+ })
97
+
82
98
  const {
83
99
  // 存储layout布局信息
84
100
  layoutRef,
85
101
  layoutProps,
86
102
  layoutStyle
87
103
  } = useLayout({ props, hasSelfPercent, setWidth, setHeight, nodeRef: nodeRef })
104
+ const { textProps } = splitProps(props)
105
+ const { textStyle } = splitStyle(normalStyle)
88
106
 
89
- const isSetW = indicatorW !== undefined ? 1 : 0
90
- const cloneRef = useRef(null)
91
- const maskPos: PosType = {}
92
- let [pickH, setPickH] = useState(0)
93
- const itemH = pickH / 5
94
- if (normalStyle?.height && pickH && pickH !== normalStyle?.height) {
95
- maskPos.height = itemH * 2 + Math.ceil((normalStyle.height - pickH) / 2)
96
- } else {
97
- maskPos.height = itemH * 2
107
+ const onColumnItemRawHChange = (height: number) => {
108
+ if (height > pickMaxH) {
109
+ setPickMaxH(height)
110
+ }
98
111
  }
99
112
 
100
- const onColumnLayoutChange = (layoutConfig: PickerLayout) => {
101
- pickH = layoutConfig.height
102
- setPickH(layoutConfig.height)
113
+ const bindchangeDebounce = useDebounceCallback(useStableCallback(bindchange), 300)
114
+
115
+ const onSelectChange = (columnIndex: number, selectedIndex: number) => {
116
+ bindchangeDebounce.clear()
117
+ const activeValue = activeValueRef.current
118
+ activeValue[columnIndex] = selectedIndex
119
+ const eventData = getCustomEvent(
120
+ 'change',
121
+ {},
122
+ { detail: { value: activeValue, source: 'change' }, layoutRef }
123
+ )
124
+ bindchangeDebounce(eventData)
103
125
  }
104
126
 
105
- const onSelectChange = (columnIndex: number, selIndex: number) => {
106
- const changeValue = value.slice()
107
- changeValue[columnIndex] = selIndex
108
- const eventData = getCustomEvent('change', {}, { detail: { value: changeValue, source: 'change' }, layoutRef })
109
- bindchange && bindchange(eventData)
127
+ const onInitialChange = (value: number[]) => {
128
+ const eventData = getCustomEvent(
129
+ 'change',
130
+ {},
131
+ { detail: { value, source: 'change' }, layoutRef }
132
+ )
133
+ bindchange?.(eventData) // immediate
110
134
  }
111
135
 
112
- const innerProps = useInnerProps(props, {
113
- ref: nodeRef,
114
- style: {
115
- ...normalStyle,
116
- ...layoutStyle,
117
- position: 'relative',
118
- overflow: 'hidden'
119
- },
120
- ...layoutProps
121
- }, [
122
- 'enable-offset'
123
- ], { layoutRef })
124
-
125
- const cloneChild = (child: React.ReactNode, index: number) => {
126
- // const extraProps = index === 0 ? { getInnerLayout: getInnerLayout, innerProps } : {}
136
+ const innerProps = useInnerProps(
137
+ props,
138
+ extendObject({
139
+ ref: nodeRef,
140
+ style: extendObject(
141
+ {},
142
+ normalStyle,
143
+ layoutStyle,
144
+ {
145
+ position: 'relative',
146
+ overflow: 'hidden'
147
+ }
148
+ ),
149
+ layoutProps
150
+ }),
151
+ ['enable-offset'],
152
+ { layoutRef }
153
+ )
154
+
155
+ const renderColumn = (child: React.ReactElement, index: number, columnData: React.ReactNode[], initialIndex: number) => {
127
156
  const extraProps = {}
128
- const childProps = {
129
- ...(child as ReactElement)?.props,
130
- ref: cloneRef,
131
- prefix: index,
132
- key: 'pick-view' + index,
133
- wrapperStyle: {
134
- height: normalStyle?.height || 0,
135
- itemHeight: indicatorH || 0
157
+ const childProps = child?.props || {}
158
+ const wrappedProps = extendObject(
159
+ {},
160
+ childProps,
161
+ {
162
+ columnData,
163
+ ref: cloneRef,
164
+ columnIndex: index,
165
+ key: `pick-view-${index}`,
166
+ wrapperStyle: {
167
+ height: normalStyle?.height || 0,
168
+ itemHeight: indicatorH || 0
169
+ },
170
+ onColumnItemRawHChange,
171
+ onSelectChange: onSelectChange.bind(null, index),
172
+ initialIndex,
173
+ pickerOverlayStyle
136
174
  },
137
- onColumnLayoutChange,
138
- onSelectChange: onSelectChange.bind(null, index),
139
- selectedIndex: value?.[index] || 0,
140
- ...extraProps
141
- }
142
- const realElement = React.cloneElement(child as ReactElement, childProps)
175
+ extraProps
176
+ )
177
+ const realElement = React.cloneElement(child, wrappedProps)
143
178
  return wrapChildren(
144
179
  {
145
180
  children: realElement
@@ -153,69 +188,44 @@ const _PickerView = forwardRef<HandlerRef<View, PickerViewProps>, PickerViewProp
153
188
  )
154
189
  }
155
190
 
156
- const renderTopMask = () => {
157
- const linearProps: LinearGradientProps = {
158
- colors: ['rgba(255,255,255,0.8)', 'rgba(255,255,255,0.2)'],
159
- style: [
160
- styles.maskTop,
161
- {
162
- height: maskPos.height,
163
- top: 0,
164
- pointerEvents: 'none'
165
- }
166
- ]
167
- }
168
- return (<LinearGradient {...linearProps}/>)
191
+ const validateChildInitialIndex = (index: number, data: React.ReactNode[]) => {
192
+ return Math.max(0, Math.min(value[index] || 0, data.length - 1))
169
193
  }
170
194
 
171
- const renderBottomMask = () => {
172
- const linearProps: LinearGradientProps = {
173
- colors: ['rgba(255,255,255,0.2)', 'rgba(255,255,255,0.8)'],
174
- style: [
175
- styles.maskBottom,
176
- {
177
- height: maskPos.height,
178
- bottom: 0,
179
- pointerEvents: 'none'
180
- }
181
- ]
195
+ const flatColumnChildren = (data: React.ReactElement) => {
196
+ const columnData = React.Children.toArray(data?.props?.children)
197
+ if (columnData.length === 1 && React.isValidElement(columnData[0]) && columnData[0].type === React.Fragment) {
198
+ // 只有一个 Fragment 嵌套情况
199
+ return React.Children.toArray(columnData[0].props.children)
182
200
  }
183
- return <LinearGradient {...linearProps}></LinearGradient>
201
+ return columnData
184
202
  }
185
203
 
186
- const renderLine = () => {
187
- return <View style={[{
188
- position: 'absolute',
189
- top: '50%',
190
- transform: [{ translateY: -(itemH / 2) }],
191
- height: itemH,
192
- borderTopWidth: 1,
193
- borderBottomWidth: 1,
194
- borderColor: '#f0f0f0',
195
- width: '100%',
196
- zIndex: 101
197
- }]}></View>
204
+ const renderPickerColumns = () => {
205
+ const columns = React.Children.toArray(children)
206
+ const renderColumns: React.ReactNode[] = []
207
+ const validValue: number[] = []
208
+ let isInvalid = false
209
+ columns.forEach((item: React.ReactElement, index) => {
210
+ const columnData = flatColumnChildren(item)
211
+ const validIndex = validateChildInitialIndex(index, columnData)
212
+ if (validIndex !== value[index]) {
213
+ isInvalid = true
214
+ }
215
+ validValue.push(validIndex)
216
+ renderColumns.push(renderColumn(item, index, columnData, validIndex))
217
+ })
218
+ isInvalid && onInitialChange(validValue)
219
+ return renderColumns
198
220
  }
199
221
 
200
- const renderSubChild = () => {
201
- if (Array.isArray(children)) {
202
- return children.map((item, index) => {
203
- return cloneChild(item, index)
204
- })
205
- } else {
206
- return cloneChild(children, 0)
207
- }
208
- }
209
- return (<View {...innerProps}>
210
- {renderTopMask()}
211
- <View style={[styles.wrapper]}>
212
- {renderSubChild()}
222
+ return (
223
+ <View {...innerProps}>
224
+ <View style={[styles.wrapper]}>{renderPickerColumns()}</View>
213
225
  </View>
214
- {renderBottomMask()}
215
- {!isSetW && renderLine()}
216
- </View>)
226
+ )
217
227
  })
218
228
 
219
- _PickerView.displayName = 'mpx-picker-view'
229
+ _PickerView.displayName = 'MpxPickerView'
220
230
 
221
231
  export default _PickerView
@@ -1,13 +1,27 @@
1
1
  /**
2
2
  * ✔ bindchange
3
3
  */
4
- import { JSX, useRef, forwardRef, ReactNode, useContext } from 'react'
5
- import { View, NativeSyntheticEvent, ViewStyle } from 'react-native'
4
+ import {
5
+ JSX,
6
+ useRef,
7
+ forwardRef,
8
+ ReactNode,
9
+ useContext,
10
+ useMemo,
11
+ useEffect,
12
+ createElement
13
+ } from 'react'
14
+ import {
15
+ View,
16
+ NativeSyntheticEvent,
17
+ ViewStyle
18
+ } from 'react-native'
6
19
  import { warn } from '@mpxjs/utils'
20
+
7
21
  import { FormContext, FormFieldValue, RadioGroupContext, GroupValue } from './context'
8
22
  import useInnerProps, { getCustomEvent } from './getInnerListeners'
9
23
  import useNodesRef, { HandlerRef } from './useNodesRef'
10
- import { useLayout, useTransformStyle, wrapChildren } from './utils'
24
+ import { useLayout, useTransformStyle, wrapChildren, extendObject } from './utils'
11
25
 
12
26
  export interface RadioGroupProps {
13
27
  name: string
@@ -32,10 +46,13 @@ const radioGroup = forwardRef<
32
46
  'external-var-context': externalVarContext,
33
47
  'parent-font-size': parentFontSize,
34
48
  'parent-width': parentWidth,
35
- 'parent-height': parentHeight,
36
- bindchange
49
+ 'parent-height': parentHeight
37
50
  } = props
38
51
 
52
+ const propsRef = useRef<any>({})
53
+
54
+ propsRef.current = props
55
+
39
56
  const formContext = useContext(FormContext)
40
57
 
41
58
  let formValuesMap: Map<string, FormFieldValue> | undefined
@@ -51,10 +68,7 @@ const radioGroup = forwardRef<
51
68
  flexWrap: 'wrap'
52
69
  }
53
70
 
54
- const styleObj = {
55
- ...defaultStyle,
56
- ...style
57
- }
71
+ const styleObj = extendObject({}, defaultStyle, style)
58
72
 
59
73
  const {
60
74
  hasSelfPercent,
@@ -66,11 +80,11 @@ const radioGroup = forwardRef<
66
80
  } = useTransformStyle(styleObj, { enableVar, externalVarContext, parentFontSize, parentWidth, parentHeight })
67
81
 
68
82
  const nodeRef = useRef(null)
69
- useNodesRef(props, ref, nodeRef, { defaultStyle })
83
+ useNodesRef(props, ref, nodeRef, { style: normalStyle })
70
84
 
71
85
  const { layoutRef, layoutStyle, layoutProps } = useLayout({ props, hasSelfPercent, setWidth, setHeight, nodeRef })
72
86
 
73
- const getSelectionValue = (): string | undefined => {
87
+ const getValue = (): string | undefined => {
74
88
  for (const key in groupValue) {
75
89
  if (groupValue[key].checked) {
76
90
  return key
@@ -78,10 +92,6 @@ const radioGroup = forwardRef<
78
92
  }
79
93
  }
80
94
 
81
- const getValue = () => {
82
- return getSelectionValue()
83
- }
84
-
85
95
  const resetValue = () => {
86
96
  Object.keys(groupValue).forEach((key) => {
87
97
  groupValue[key].checked = false
@@ -96,56 +106,69 @@ const radioGroup = forwardRef<
96
106
  formValuesMap.set(props.name, { getValue, resetValue })
97
107
  }
98
108
  }
99
-
100
- const notifyChange = (
101
- evt: NativeSyntheticEvent<TouchEvent>
102
- ) => {
103
- bindchange &&
104
- bindchange(
105
- getCustomEvent(
106
- 'tap',
107
- evt,
108
- {
109
- layoutRef,
110
- detail: {
111
- value: getSelectionValue()
112
- }
113
- },
114
- props
109
+ useEffect(() => {
110
+ return () => {
111
+ if (formValuesMap && props.name) {
112
+ formValuesMap.delete(props.name)
113
+ }
114
+ }
115
+ }, [])
116
+
117
+ const contextValue = useMemo(() => {
118
+ const notifyChange = (
119
+ evt: NativeSyntheticEvent<TouchEvent>
120
+ ) => {
121
+ const { bindchange } = propsRef.current
122
+ bindchange &&
123
+ bindchange(
124
+ getCustomEvent(
125
+ 'tap',
126
+ evt,
127
+ {
128
+ layoutRef,
129
+ detail: {
130
+ value: getValue()
131
+ }
132
+ },
133
+ propsRef.current
134
+ )
115
135
  )
116
- )
117
- }
136
+ }
137
+ return {
138
+ groupValue,
139
+ notifyChange
140
+ }
141
+ }, [])
118
142
 
119
143
  const innerProps = useInnerProps(
120
144
  props,
121
- {
122
- ref: nodeRef,
123
- style: { ...normalStyle, ...layoutStyle },
124
- ...layoutProps
125
- },
126
- [],
145
+ extendObject(
146
+ {
147
+ ref: nodeRef,
148
+ style: extendObject({}, normalStyle, layoutStyle)
149
+ },
150
+ layoutProps
151
+ ),
152
+ ['name'],
127
153
  {
128
154
  layoutRef
129
155
  }
130
156
  )
131
157
 
132
- return (
133
- <View {...innerProps}>
134
- <RadioGroupContext.Provider value={{ groupValue, notifyChange }}>
135
- {
136
- wrapChildren(
137
- props,
138
- {
139
- hasVarDec,
140
- varContext: varContextRef.current
141
- }
142
- )
143
- }
144
- </RadioGroupContext.Provider>
145
- </View>
158
+ return createElement(View, innerProps, createElement(
159
+ RadioGroupContext.Provider,
160
+ { value: contextValue },
161
+ wrapChildren(
162
+ props,
163
+ {
164
+ hasVarDec,
165
+ varContext: varContextRef.current
166
+ }
167
+ )
168
+ )
146
169
  )
147
170
  })
148
171
 
149
- radioGroup.displayName = 'mpx-radio-group'
172
+ radioGroup.displayName = 'MpxRadioGroup'
150
173
 
151
174
  export default radioGroup
@@ -4,13 +4,13 @@
4
4
  * ✔ checked
5
5
  * ✔ color
6
6
  */
7
- import { JSX, useRef, useState, forwardRef, useEffect, ReactNode, useContext, Dispatch, SetStateAction } from 'react'
7
+ import { JSX, useRef, useState, forwardRef, useEffect, ReactNode, useContext, Dispatch, SetStateAction, createElement } from 'react'
8
8
  import { View, StyleSheet, ViewStyle, NativeSyntheticEvent } from 'react-native'
9
9
  import { warn } from '@mpxjs/utils'
10
10
  import { LabelContext, RadioGroupContext } from './context'
11
11
  import useInnerProps, { getCustomEvent } from './getInnerListeners'
12
12
  import useNodesRef, { HandlerRef } from './useNodesRef'
13
- import { splitProps, splitStyle, useLayout, useTransformStyle, wrapChildren } from './utils'
13
+ import { splitProps, splitStyle, useLayout, useTransformStyle, wrapChildren, extendObject } from './utils'
14
14
  import Icon from './mpx-icon'
15
15
 
16
16
  export interface RadioProps {
@@ -27,7 +27,6 @@ export interface RadioProps {
27
27
  'parent-height'?: number;
28
28
  children: ReactNode
29
29
  bindtap?: (evt: NativeSyntheticEvent<TouchEvent> | unknown) => void
30
- catchtap?: (evt: NativeSyntheticEvent<TouchEvent> | unknown) => void
31
30
  }
32
31
 
33
32
  const styles = StyleSheet.create({
@@ -79,8 +78,7 @@ const Radio = forwardRef<HandlerRef<View, RadioProps>, RadioProps>(
79
78
  'parent-font-size': parentFontSize,
80
79
  'parent-width': parentWidth,
81
80
  'parent-height': parentHeight,
82
- bindtap,
83
- catchtap
81
+ bindtap
84
82
  } = props
85
83
 
86
84
  const [isChecked, setIsChecked] = useState<boolean>(!!checked)
@@ -91,16 +89,14 @@ const Radio = forwardRef<HandlerRef<View, RadioProps>, RadioProps>(
91
89
 
92
90
  const labelContext = useContext(LabelContext)
93
91
 
94
- const defaultStyle = {
95
- ...styles.wrapper,
96
- ...(isChecked && styles.wrapperChecked),
97
- ...(disabled && styles.wrapperDisabled)
98
- }
92
+ const defaultStyle = extendObject(
93
+ {},
94
+ styles.wrapper,
95
+ isChecked ? styles.wrapperChecked : {},
96
+ disabled ? styles.wrapperDisabled : {}
97
+ )
99
98
 
100
- const styleObj = {
101
- ...styles.container,
102
- ...style
103
- }
99
+ const styleObj = extendObject({}, styles.container, style)
104
100
 
105
101
  const onChange = (evt: NativeSyntheticEvent<TouchEvent>) => {
106
102
  if (disabled || isChecked) return
@@ -116,16 +112,10 @@ const Radio = forwardRef<HandlerRef<View, RadioProps>, RadioProps>(
116
112
  }
117
113
 
118
114
  const onTap = (evt: NativeSyntheticEvent<TouchEvent>) => {
119
- if (disabled) return
120
115
  bindtap && bindtap(getCustomEvent('tap', evt, { layoutRef }, props))
121
116
  onChange(evt)
122
117
  }
123
118
 
124
- const catchTap = (evt: NativeSyntheticEvent<TouchEvent>) => {
125
- if (disabled) return
126
- catchtap && catchtap(getCustomEvent('tap', evt, { layoutRef }, props))
127
- }
128
-
129
119
  const {
130
120
  hasSelfPercent,
131
121
  normalStyle,
@@ -135,7 +125,7 @@ const Radio = forwardRef<HandlerRef<View, RadioProps>, RadioProps>(
135
125
  setHeight
136
126
  } = useTransformStyle(styleObj, { enableVar, externalVarContext, parentFontSize, parentWidth, parentHeight })
137
127
 
138
- const { textStyle, backgroundStyle, innerStyle } = splitStyle(normalStyle)
128
+ const { textStyle, backgroundStyle, innerStyle = {} } = splitStyle(normalStyle)
139
129
 
140
130
  if (backgroundStyle) {
141
131
  warn('Radio does not support background image-related styles!')
@@ -143,7 +133,7 @@ const Radio = forwardRef<HandlerRef<View, RadioProps>, RadioProps>(
143
133
 
144
134
  const nodeRef = useRef(null)
145
135
  useNodesRef(props, ref, nodeRef, {
146
- defaultStyle,
136
+ style: extendObject({}, defaultStyle, normalStyle),
147
137
  change: onChange
148
138
  })
149
139
 
@@ -160,14 +150,21 @@ const Radio = forwardRef<HandlerRef<View, RadioProps>, RadioProps>(
160
150
 
161
151
  const innerProps = useInnerProps(
162
152
  props,
163
- {
164
- ref: nodeRef,
165
- style: { ...innerStyle, ...layoutStyle },
166
- ...layoutProps,
167
- bindtap: onTap,
168
- catchtap: catchTap
169
- },
170
- [],
153
+ extendObject(
154
+ {
155
+ ref: nodeRef,
156
+ style: extendObject({}, innerStyle, layoutStyle)
157
+ },
158
+ layoutProps,
159
+ {
160
+ bindtap: !disabled && onTap
161
+ }
162
+ ),
163
+ [
164
+ 'value',
165
+ 'disabled',
166
+ 'checked'
167
+ ],
171
168
  {
172
169
  layoutRef
173
170
  }
@@ -196,36 +193,30 @@ const Radio = forwardRef<HandlerRef<View, RadioProps>, RadioProps>(
196
193
  }
197
194
  }, [checked])
198
195
 
199
- return (
200
- <View {...innerProps}>
201
- <View style={defaultStyle}>
202
- <Icon
203
- type='success'
204
- size={24}
205
- color={disabled ? '#E1E1E1' : color}
206
- style={{
207
- ...styles.icon,
208
- ...(isChecked && styles.iconChecked),
209
- ...(disabled && styles.iconDisabled)
210
- }}
211
- />
212
- </View>
196
+ return createElement(View, innerProps,
197
+ createElement(
198
+ View,
199
+ { style: defaultStyle },
200
+ createElement(Icon, {
201
+ type: 'success',
202
+ size: 24,
203
+ color: disabled ? '#E1E1E1' : color,
204
+ style: extendObject({}, styles.icon, isChecked && styles.iconChecked, disabled && styles.iconDisabled)
205
+ })
206
+ ),
207
+ wrapChildren(
208
+ props,
213
209
  {
214
- wrapChildren(
215
- props,
216
- {
217
- hasVarDec,
218
- varContext: varContextRef.current,
219
- textStyle,
220
- textProps
221
- }
222
- )
210
+ hasVarDec,
211
+ varContext: varContextRef.current,
212
+ textStyle,
213
+ textProps
223
214
  }
224
- </View>
215
+ )
225
216
  )
226
217
  }
227
218
  )
228
219
 
229
- Radio.displayName = 'mpx-radio'
220
+ Radio.displayName = 'MpxRadio'
230
221
 
231
222
  export default Radio