@mpxjs/webpack-plugin 2.9.66 → 2.9.69
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.
- package/lib/dependencies/RecordGlobalComponentsDependency.js +11 -12
- package/lib/dependencies/RecordRuntimeInfoDependency.js +1 -1
- package/lib/index.js +29 -8
- package/lib/json-compiler/index.js +2 -11
- package/lib/loader.js +24 -45
- package/lib/native-loader.js +49 -64
- package/lib/platform/json/wx/index.js +3 -10
- package/lib/platform/style/wx/index.js +15 -10
- package/lib/platform/template/wx/component-config/canvas.js +8 -0
- package/lib/platform/template/wx/component-config/unsupported.js +1 -1
- package/lib/react/index.js +4 -3
- package/lib/react/processJSON.js +5 -13
- package/lib/react/processMainScript.js +7 -3
- package/lib/react/processScript.js +3 -4
- package/lib/react/processStyles.js +14 -4
- package/lib/react/processTemplate.js +2 -2
- package/lib/resolver/AddModePlugin.js +20 -7
- package/lib/runtime/components/react/context.ts +2 -0
- package/lib/runtime/components/react/dist/context.js +1 -0
- package/lib/runtime/components/react/dist/getInnerListeners.js +3 -12
- package/lib/runtime/components/react/dist/mpx-button.jsx +44 -9
- package/lib/runtime/components/react/dist/mpx-canvas/Bus.js +60 -0
- package/lib/runtime/components/react/dist/mpx-canvas/CanvasGradient.js +15 -0
- package/lib/runtime/components/react/dist/mpx-canvas/CanvasRenderingContext2D.js +84 -0
- package/lib/runtime/components/react/dist/mpx-canvas/Image.js +87 -0
- package/lib/runtime/components/react/dist/mpx-canvas/ImageData.js +15 -0
- package/lib/runtime/components/react/dist/mpx-canvas/constructorsRegistry.js +28 -0
- package/lib/runtime/components/react/dist/mpx-canvas/html.js +343 -0
- package/lib/runtime/components/react/dist/mpx-canvas/index.jsx +214 -0
- package/lib/runtime/components/react/dist/mpx-canvas/utils.jsx +89 -0
- package/lib/runtime/components/react/dist/mpx-checkbox-group.jsx +30 -17
- package/lib/runtime/components/react/dist/mpx-checkbox.jsx +1 -1
- package/lib/runtime/components/react/dist/mpx-form.jsx +33 -24
- package/lib/runtime/components/react/dist/mpx-icon.jsx +1 -1
- package/lib/runtime/components/react/dist/mpx-image/index.jsx +1 -1
- package/lib/runtime/components/react/dist/mpx-input.jsx +44 -38
- package/lib/runtime/components/react/dist/mpx-label.jsx +10 -7
- package/lib/runtime/components/react/dist/mpx-movable-area.jsx +10 -17
- package/lib/runtime/components/react/dist/mpx-movable-view.jsx +378 -294
- package/lib/runtime/components/react/dist/mpx-navigator.jsx +1 -1
- package/lib/runtime/components/react/dist/mpx-picker-view-column.jsx +143 -84
- package/lib/runtime/components/react/dist/mpx-picker-view.jsx +69 -113
- package/lib/runtime/components/react/dist/mpx-radio-group.jsx +30 -17
- package/lib/runtime/components/react/dist/mpx-radio.jsx +1 -1
- package/lib/runtime/components/react/dist/mpx-root-portal.jsx +1 -1
- package/lib/runtime/components/react/dist/mpx-scroll-view.jsx +49 -29
- package/lib/runtime/components/react/dist/mpx-swiper/carouse.jsx +1 -1
- package/lib/runtime/components/react/dist/mpx-swiper/index.jsx +1 -1
- package/lib/runtime/components/react/dist/mpx-swiper-item.jsx +1 -1
- package/lib/runtime/components/react/dist/mpx-switch.jsx +8 -1
- package/lib/runtime/components/react/dist/mpx-text.jsx +1 -1
- package/lib/runtime/components/react/dist/mpx-textarea.jsx +1 -1
- package/lib/runtime/components/react/dist/mpx-view.jsx +46 -27
- package/lib/runtime/components/react/dist/mpx-web-view.jsx +20 -6
- package/lib/runtime/components/react/dist/pickerFaces.js +75 -0
- package/lib/runtime/components/react/dist/pickerOverlay.jsx +21 -0
- package/lib/runtime/components/react/dist/useAnimationHooks.js +96 -8
- package/lib/runtime/components/react/dist/utils.jsx +66 -6
- package/lib/runtime/components/react/getInnerListeners.ts +3 -16
- package/lib/runtime/components/react/mpx-button.tsx +42 -9
- package/lib/runtime/components/react/mpx-canvas/Bus.ts +70 -0
- package/lib/runtime/components/react/mpx-canvas/CanvasGradient.ts +18 -0
- package/lib/runtime/components/react/mpx-canvas/CanvasRenderingContext2D.ts +87 -0
- package/lib/runtime/components/react/mpx-canvas/Image.ts +102 -0
- package/lib/runtime/components/react/mpx-canvas/ImageData.ts +23 -0
- package/lib/runtime/components/react/mpx-canvas/constructorsRegistry.ts +38 -0
- package/lib/runtime/components/react/mpx-canvas/html.ts +343 -0
- package/lib/runtime/components/react/mpx-canvas/index.tsx +302 -0
- package/lib/runtime/components/react/mpx-canvas/utils.tsx +150 -0
- package/lib/runtime/components/react/mpx-checkbox-group.tsx +52 -29
- package/lib/runtime/components/react/mpx-checkbox.tsx +1 -1
- package/lib/runtime/components/react/mpx-form.tsx +42 -34
- package/lib/runtime/components/react/mpx-icon.tsx +1 -1
- package/lib/runtime/components/react/mpx-image/index.tsx +2 -3
- package/lib/runtime/components/react/mpx-input.tsx +68 -66
- package/lib/runtime/components/react/mpx-label.tsx +11 -8
- package/lib/runtime/components/react/mpx-movable-area.tsx +11 -19
- package/lib/runtime/components/react/mpx-movable-view.tsx +456 -334
- package/lib/runtime/components/react/mpx-navigator.tsx +1 -1
- package/lib/runtime/components/react/mpx-picker-view-column.tsx +232 -103
- package/lib/runtime/components/react/mpx-picker-view.tsx +126 -122
- package/lib/runtime/components/react/mpx-radio-group.tsx +55 -29
- package/lib/runtime/components/react/mpx-radio.tsx +1 -1
- package/lib/runtime/components/react/mpx-root-portal.tsx +1 -1
- package/lib/runtime/components/react/mpx-scroll-view.tsx +81 -36
- package/lib/runtime/components/react/mpx-swiper/carouse.tsx +2 -2
- package/lib/runtime/components/react/mpx-swiper/index.tsx +2 -1
- package/lib/runtime/components/react/mpx-swiper-item.tsx +1 -1
- package/lib/runtime/components/react/mpx-switch.tsx +10 -2
- package/lib/runtime/components/react/mpx-text.tsx +1 -1
- package/lib/runtime/components/react/mpx-textarea.tsx +1 -1
- package/lib/runtime/components/react/mpx-view.tsx +58 -28
- package/lib/runtime/components/react/mpx-web-view.tsx +23 -6
- package/lib/runtime/components/react/pickerFaces.ts +104 -0
- package/lib/runtime/components/react/pickerOverlay.tsx +32 -0
- package/lib/runtime/components/react/types/common.ts +2 -0
- package/lib/runtime/components/react/types/global.d.ts +2 -0
- package/lib/runtime/components/react/useAnimationHooks.ts +97 -13
- package/lib/runtime/components/react/useNodesRef.ts +1 -0
- package/lib/runtime/components/react/utils.tsx +94 -8
- package/lib/runtime/optionProcessorReact.js +0 -15
- package/lib/runtime/swanHelper.wxs +1 -1
- package/lib/style-compiler/index.js +1 -1
- package/lib/style-compiler/plugins/scope-id.js +1 -0
- package/lib/template-compiler/compiler.js +47 -16
- package/lib/template-compiler/gen-node-react.js +2 -2
- package/lib/template-compiler/index.js +4 -4
- package/lib/utils/pre-process-json.js +113 -0
- package/lib/web/index.js +5 -4
- package/lib/web/processJSON.js +5 -13
- package/lib/web/processTemplate.js +2 -2
- package/package.json +5 -4
|
@@ -1,9 +1,19 @@
|
|
|
1
1
|
import { View } from 'react-native'
|
|
2
|
-
import {
|
|
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 {
|
|
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
|
|
31
|
+
// 初始的defaultValue数组中的数字依次表示 picker-view 内的 picker-view-column 选择的第几项(下标从 0 开始),
|
|
32
|
+
// 数字大于 picker-view-column 可选项长度时,选择最后一项。
|
|
22
33
|
value?: Array<number>
|
|
23
|
-
bindchange?:
|
|
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 {
|
|
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,
|
|
78
|
+
const { height: indicatorH, ...pickerOverlayStyle } = indicatorStyle
|
|
79
|
+
const [pickMaxH, setPickMaxH] = useState(0)
|
|
69
80
|
const nodeRef = useRef(null)
|
|
70
|
-
|
|
71
|
-
|
|
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,85 @@ const _PickerView = forwardRef<HandlerRef<View, PickerViewProps>, PickerViewProp
|
|
|
77
90
|
setWidth,
|
|
78
91
|
setHeight
|
|
79
92
|
} = useTransformStyle(style, { enableVar, externalVarContext })
|
|
80
|
-
|
|
81
|
-
const { textProps } = splitProps(props)
|
|
93
|
+
useNodesRef<View, PickerViewProps>(props, ref, nodeRef, {})
|
|
82
94
|
const {
|
|
83
95
|
// 存储layout布局信息
|
|
84
96
|
layoutRef,
|
|
85
97
|
layoutProps,
|
|
86
98
|
layoutStyle
|
|
87
99
|
} = useLayout({ props, hasSelfPercent, setWidth, setHeight, nodeRef: nodeRef })
|
|
100
|
+
const { textProps } = splitProps(props)
|
|
101
|
+
const { textStyle } = splitStyle(normalStyle)
|
|
88
102
|
|
|
89
|
-
const
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
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
|
|
103
|
+
const onColumnItemRawHChange = (height: number) => {
|
|
104
|
+
if (height > pickMaxH) {
|
|
105
|
+
setPickMaxH(height)
|
|
106
|
+
}
|
|
98
107
|
}
|
|
99
108
|
|
|
100
|
-
const
|
|
101
|
-
|
|
102
|
-
|
|
109
|
+
const bindchangeDebounce = useDebounceCallback(useStableCallback(bindchange), 300)
|
|
110
|
+
|
|
111
|
+
const onSelectChange = (columnIndex: number, selectedIndex: number) => {
|
|
112
|
+
bindchangeDebounce.clear()
|
|
113
|
+
const activeValue = activeValueRef.current
|
|
114
|
+
activeValue[columnIndex] = selectedIndex
|
|
115
|
+
const eventData = getCustomEvent(
|
|
116
|
+
'change',
|
|
117
|
+
{},
|
|
118
|
+
{ detail: { value: activeValue, source: 'change' }, layoutRef }
|
|
119
|
+
)
|
|
120
|
+
bindchangeDebounce(eventData)
|
|
103
121
|
}
|
|
104
122
|
|
|
105
|
-
const
|
|
106
|
-
const
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
123
|
+
const onInitialChange = (value: number[]) => {
|
|
124
|
+
const eventData = getCustomEvent(
|
|
125
|
+
'change',
|
|
126
|
+
{},
|
|
127
|
+
{ detail: { value, source: 'change' }, layoutRef }
|
|
128
|
+
)
|
|
129
|
+
bindchange?.(eventData) // immediate
|
|
110
130
|
}
|
|
111
131
|
|
|
112
|
-
const innerProps = useInnerProps(
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
132
|
+
const innerProps = useInnerProps(
|
|
133
|
+
props,
|
|
134
|
+
extendObject({
|
|
135
|
+
ref: nodeRef,
|
|
136
|
+
style: extendObject(
|
|
137
|
+
normalStyle,
|
|
138
|
+
layoutStyle,
|
|
139
|
+
{
|
|
140
|
+
position: 'relative',
|
|
141
|
+
overflow: 'hidden'
|
|
142
|
+
}
|
|
143
|
+
),
|
|
144
|
+
layoutProps
|
|
145
|
+
}),
|
|
146
|
+
['enable-offset'],
|
|
147
|
+
{ layoutRef }
|
|
148
|
+
)
|
|
149
|
+
|
|
150
|
+
const renderColumn = (child: React.ReactElement, index: number, columnData: React.ReactNode[], initialIndex: number) => {
|
|
127
151
|
const extraProps = {}
|
|
128
|
-
const childProps = {
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
152
|
+
const childProps = child?.props || {}
|
|
153
|
+
const wrappedProps = extendObject(
|
|
154
|
+
childProps,
|
|
155
|
+
{
|
|
156
|
+
columnData,
|
|
157
|
+
ref: cloneRef,
|
|
158
|
+
columnIndex: index,
|
|
159
|
+
key: `pick-view-${index}`,
|
|
160
|
+
wrapperStyle: {
|
|
161
|
+
height: normalStyle?.height || 0,
|
|
162
|
+
itemHeight: indicatorH || 0
|
|
163
|
+
},
|
|
164
|
+
onColumnItemRawHChange,
|
|
165
|
+
onSelectChange: onSelectChange.bind(null, index),
|
|
166
|
+
initialIndex,
|
|
167
|
+
pickerOverlayStyle
|
|
136
168
|
},
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
...extraProps
|
|
141
|
-
}
|
|
142
|
-
const realElement = React.cloneElement(child as ReactElement, childProps)
|
|
169
|
+
extraProps
|
|
170
|
+
)
|
|
171
|
+
const realElement = React.cloneElement(child, wrappedProps)
|
|
143
172
|
return wrapChildren(
|
|
144
173
|
{
|
|
145
174
|
children: realElement
|
|
@@ -153,69 +182,44 @@ const _PickerView = forwardRef<HandlerRef<View, PickerViewProps>, PickerViewProp
|
|
|
153
182
|
)
|
|
154
183
|
}
|
|
155
184
|
|
|
156
|
-
const
|
|
157
|
-
|
|
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}/>)
|
|
185
|
+
const validateChildInitialIndex = (index: number, data: React.ReactNode[]) => {
|
|
186
|
+
return Math.max(0, Math.min(value[index] || 0, data.length - 1))
|
|
169
187
|
}
|
|
170
188
|
|
|
171
|
-
const
|
|
172
|
-
const
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
{
|
|
177
|
-
height: maskPos.height,
|
|
178
|
-
bottom: 0,
|
|
179
|
-
pointerEvents: 'none'
|
|
180
|
-
}
|
|
181
|
-
]
|
|
189
|
+
const flatColumnChildren = (data: React.ReactElement) => {
|
|
190
|
+
const columnData = React.Children.toArray(data?.props?.children)
|
|
191
|
+
if (columnData.length === 1 && React.isValidElement(columnData[0]) && columnData[0].type === React.Fragment) {
|
|
192
|
+
// 只有一个 Fragment 嵌套情况
|
|
193
|
+
return React.Children.toArray(columnData[0].props.children)
|
|
182
194
|
}
|
|
183
|
-
return
|
|
195
|
+
return columnData
|
|
184
196
|
}
|
|
185
197
|
|
|
186
|
-
const
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
+
const renderPickerColumns = () => {
|
|
199
|
+
const columns = React.Children.toArray(children)
|
|
200
|
+
const renderColumns: React.ReactNode[] = []
|
|
201
|
+
const validValue: number[] = []
|
|
202
|
+
let isInvalid = false
|
|
203
|
+
columns.forEach((item: React.ReactElement, index) => {
|
|
204
|
+
const columnData = flatColumnChildren(item)
|
|
205
|
+
const validIndex = validateChildInitialIndex(index, columnData)
|
|
206
|
+
if (validIndex !== value[index]) {
|
|
207
|
+
isInvalid = true
|
|
208
|
+
}
|
|
209
|
+
validValue.push(validIndex)
|
|
210
|
+
renderColumns.push(renderColumn(item, index, columnData, validIndex))
|
|
211
|
+
})
|
|
212
|
+
isInvalid && onInitialChange(validValue)
|
|
213
|
+
return renderColumns
|
|
198
214
|
}
|
|
199
215
|
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
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()}
|
|
216
|
+
return (
|
|
217
|
+
<View {...innerProps}>
|
|
218
|
+
<View style={[styles.wrapper]}>{renderPickerColumns()}</View>
|
|
213
219
|
</View>
|
|
214
|
-
|
|
215
|
-
{!isSetW && renderLine()}
|
|
216
|
-
</View>)
|
|
220
|
+
)
|
|
217
221
|
})
|
|
218
222
|
|
|
219
|
-
_PickerView.displayName = '
|
|
223
|
+
_PickerView.displayName = 'MpxPickerView'
|
|
220
224
|
|
|
221
225
|
export default _PickerView
|
|
@@ -1,9 +1,22 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* ✔ bindchange
|
|
3
3
|
*/
|
|
4
|
-
import {
|
|
5
|
-
|
|
4
|
+
import {
|
|
5
|
+
JSX,
|
|
6
|
+
useRef,
|
|
7
|
+
forwardRef,
|
|
8
|
+
ReactNode,
|
|
9
|
+
useContext,
|
|
10
|
+
useMemo,
|
|
11
|
+
useEffect
|
|
12
|
+
} from 'react'
|
|
13
|
+
import {
|
|
14
|
+
View,
|
|
15
|
+
NativeSyntheticEvent,
|
|
16
|
+
ViewStyle
|
|
17
|
+
} from 'react-native'
|
|
6
18
|
import { warn } from '@mpxjs/utils'
|
|
19
|
+
|
|
7
20
|
import { FormContext, FormFieldValue, RadioGroupContext, GroupValue } from './context'
|
|
8
21
|
import useInnerProps, { getCustomEvent } from './getInnerListeners'
|
|
9
22
|
import useNodesRef, { HandlerRef } from './useNodesRef'
|
|
@@ -32,10 +45,13 @@ const radioGroup = forwardRef<
|
|
|
32
45
|
'external-var-context': externalVarContext,
|
|
33
46
|
'parent-font-size': parentFontSize,
|
|
34
47
|
'parent-width': parentWidth,
|
|
35
|
-
'parent-height': parentHeight
|
|
36
|
-
bindchange
|
|
48
|
+
'parent-height': parentHeight
|
|
37
49
|
} = props
|
|
38
50
|
|
|
51
|
+
const propsRef = useRef<any>({})
|
|
52
|
+
|
|
53
|
+
propsRef.current = props
|
|
54
|
+
|
|
39
55
|
const formContext = useContext(FormContext)
|
|
40
56
|
|
|
41
57
|
let formValuesMap: Map<string, FormFieldValue> | undefined
|
|
@@ -70,7 +86,7 @@ const radioGroup = forwardRef<
|
|
|
70
86
|
|
|
71
87
|
const { layoutRef, layoutStyle, layoutProps } = useLayout({ props, hasSelfPercent, setWidth, setHeight, nodeRef })
|
|
72
88
|
|
|
73
|
-
const
|
|
89
|
+
const getValue = (): string | undefined => {
|
|
74
90
|
for (const key in groupValue) {
|
|
75
91
|
if (groupValue[key].checked) {
|
|
76
92
|
return key
|
|
@@ -78,10 +94,6 @@ const radioGroup = forwardRef<
|
|
|
78
94
|
}
|
|
79
95
|
}
|
|
80
96
|
|
|
81
|
-
const getValue = () => {
|
|
82
|
-
return getSelectionValue()
|
|
83
|
-
}
|
|
84
|
-
|
|
85
97
|
const resetValue = () => {
|
|
86
98
|
Object.keys(groupValue).forEach((key) => {
|
|
87
99
|
groupValue[key].checked = false
|
|
@@ -96,25 +108,39 @@ const radioGroup = forwardRef<
|
|
|
96
108
|
formValuesMap.set(props.name, { getValue, resetValue })
|
|
97
109
|
}
|
|
98
110
|
}
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
111
|
+
useEffect(() => {
|
|
112
|
+
return () => {
|
|
113
|
+
if (formValuesMap && props.name) {
|
|
114
|
+
formValuesMap.delete(props.name)
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}, [])
|
|
118
|
+
|
|
119
|
+
const contextValue = useMemo(() => {
|
|
120
|
+
const notifyChange = (
|
|
121
|
+
evt: NativeSyntheticEvent<TouchEvent>
|
|
122
|
+
) => {
|
|
123
|
+
const { bindchange } = propsRef.current
|
|
124
|
+
bindchange &&
|
|
125
|
+
bindchange(
|
|
126
|
+
getCustomEvent(
|
|
127
|
+
'tap',
|
|
128
|
+
evt,
|
|
129
|
+
{
|
|
130
|
+
layoutRef,
|
|
131
|
+
detail: {
|
|
132
|
+
value: getValue()
|
|
133
|
+
}
|
|
134
|
+
},
|
|
135
|
+
propsRef.current
|
|
136
|
+
)
|
|
115
137
|
)
|
|
116
|
-
|
|
117
|
-
|
|
138
|
+
}
|
|
139
|
+
return {
|
|
140
|
+
groupValue,
|
|
141
|
+
notifyChange
|
|
142
|
+
}
|
|
143
|
+
}, [])
|
|
118
144
|
|
|
119
145
|
const innerProps = useInnerProps(
|
|
120
146
|
props,
|
|
@@ -131,7 +157,7 @@ const radioGroup = forwardRef<
|
|
|
131
157
|
|
|
132
158
|
return (
|
|
133
159
|
<View {...innerProps}>
|
|
134
|
-
<RadioGroupContext.Provider value={
|
|
160
|
+
<RadioGroupContext.Provider value={contextValue}>
|
|
135
161
|
{
|
|
136
162
|
wrapChildren(
|
|
137
163
|
props,
|
|
@@ -146,6 +172,6 @@ const radioGroup = forwardRef<
|
|
|
146
172
|
)
|
|
147
173
|
})
|
|
148
174
|
|
|
149
|
-
radioGroup.displayName = '
|
|
175
|
+
radioGroup.displayName = 'MpxRadioGroup'
|
|
150
176
|
|
|
151
177
|
export default radioGroup
|