@mpxjs/webpack-plugin 2.10.3 → 2.10.4

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 (103) hide show
  1. package/lib/config.js +2 -1
  2. package/lib/index.js +1 -1
  3. package/lib/platform/json/wx/index.js +6 -3
  4. package/lib/platform/style/wx/index.js +23 -12
  5. package/lib/platform/template/wx/component-config/button.js +19 -2
  6. package/lib/platform/template/wx/component-config/canvas.js +4 -0
  7. package/lib/platform/template/wx/component-config/checkbox-group.js +4 -0
  8. package/lib/platform/template/wx/component-config/checkbox.js +4 -0
  9. package/lib/platform/template/wx/component-config/cover-image.js +7 -1
  10. package/lib/platform/template/wx/component-config/cover-view.js +4 -0
  11. package/lib/platform/template/wx/component-config/fix-component-name.js +3 -2
  12. package/lib/platform/template/wx/component-config/form.js +7 -1
  13. package/lib/platform/template/wx/component-config/icon.js +4 -0
  14. package/lib/platform/template/wx/component-config/image.js +7 -1
  15. package/lib/platform/template/wx/component-config/input.js +18 -3
  16. package/lib/platform/template/wx/component-config/label.js +4 -0
  17. package/lib/platform/template/wx/component-config/movable-area.js +7 -1
  18. package/lib/platform/template/wx/component-config/movable-view.js +12 -3
  19. package/lib/platform/template/wx/component-config/navigator.js +4 -0
  20. package/lib/platform/template/wx/component-config/picker-view-column.js +4 -0
  21. package/lib/platform/template/wx/component-config/picker-view.js +7 -1
  22. package/lib/platform/template/wx/component-config/picker.js +7 -1
  23. package/lib/platform/template/wx/component-config/radio-group.js +4 -0
  24. package/lib/platform/template/wx/component-config/radio.js +4 -0
  25. package/lib/platform/template/wx/component-config/rich-text.js +4 -0
  26. package/lib/platform/template/wx/component-config/root-portal.js +4 -0
  27. package/lib/platform/template/wx/component-config/scroll-view.js +10 -2
  28. package/lib/platform/template/wx/component-config/swiper-item.js +7 -1
  29. package/lib/platform/template/wx/component-config/swiper.js +12 -3
  30. package/lib/platform/template/wx/component-config/switch.js +4 -0
  31. package/lib/platform/template/wx/component-config/text.js +24 -3
  32. package/lib/platform/template/wx/component-config/textarea.js +17 -2
  33. package/lib/platform/template/wx/component-config/unsupported.js +7 -0
  34. package/lib/platform/template/wx/component-config/video.js +10 -2
  35. package/lib/platform/template/wx/component-config/view.js +11 -1
  36. package/lib/platform/template/wx/component-config/web-view.js +4 -0
  37. package/lib/platform/template/wx/index.js +42 -75
  38. package/lib/react/processScript.js +1 -18
  39. package/lib/runtime/components/react/dist/event.config.js +1 -0
  40. package/lib/runtime/components/react/dist/getInnerListeners.js +18 -7
  41. package/lib/runtime/components/react/dist/mpx-canvas/index.jsx +1 -1
  42. package/lib/runtime/components/react/dist/mpx-inline-text.jsx +11 -0
  43. package/lib/runtime/components/react/dist/mpx-input.jsx +3 -6
  44. package/lib/runtime/components/react/dist/mpx-keyboard-avoiding-view.jsx +2 -2
  45. package/lib/runtime/components/react/dist/mpx-picker/date.jsx +194 -68
  46. package/lib/runtime/components/react/dist/mpx-picker/dateData.js +17 -0
  47. package/lib/runtime/components/react/dist/mpx-picker/index.jsx +178 -96
  48. package/lib/runtime/components/react/dist/mpx-picker/multiSelector.jsx +79 -139
  49. package/lib/runtime/components/react/dist/mpx-picker/region.jsx +190 -90
  50. package/lib/runtime/components/react/dist/mpx-picker/selector.jsx +60 -75
  51. package/lib/runtime/components/react/dist/mpx-picker/time.jsx +100 -228
  52. package/lib/runtime/components/react/dist/{mpx-picker-view.jsx → mpx-picker-view/index.jsx} +3 -3
  53. package/lib/runtime/components/react/dist/{mpx-picker-view-column.jsx → mpx-picker-view-column/index.jsx} +64 -16
  54. package/lib/runtime/components/react/dist/{mpx-picker-view-column-item.jsx → mpx-picker-view-column/pickerViewColumnItem.jsx} +8 -5
  55. package/lib/runtime/components/react/dist/{pickerFaces.js → mpx-picker-view-column/pickerViewFaces.js} +6 -0
  56. package/lib/runtime/components/react/dist/mpx-popup/index.jsx +61 -0
  57. package/lib/runtime/components/react/dist/mpx-popup/popupBase.jsx +92 -0
  58. package/lib/runtime/components/react/dist/mpx-scroll-view.jsx +192 -25
  59. package/lib/runtime/components/react/dist/mpx-simple-text.jsx +8 -7
  60. package/lib/runtime/components/react/dist/mpx-simple-view.jsx +11 -15
  61. package/lib/runtime/components/react/dist/mpx-video.jsx +3 -3
  62. package/lib/runtime/components/react/dist/mpx-web-view.jsx +7 -4
  63. package/lib/runtime/components/react/dist/utils.jsx +2 -1
  64. package/lib/runtime/components/react/event.config.ts +2 -0
  65. package/lib/runtime/components/react/getInnerListeners.ts +28 -25
  66. package/lib/runtime/components/react/mpx-canvas/index.tsx +2 -2
  67. package/lib/runtime/components/react/mpx-inline-text.tsx +18 -0
  68. package/lib/runtime/components/react/mpx-input.tsx +2 -6
  69. package/lib/runtime/components/react/mpx-keyboard-avoiding-view.tsx +1 -1
  70. package/lib/runtime/components/react/mpx-picker/date.tsx +226 -69
  71. package/lib/runtime/components/react/mpx-picker/dateData.ts +22 -0
  72. package/lib/runtime/components/react/mpx-picker/index.tsx +239 -118
  73. package/lib/runtime/components/react/mpx-picker/multiSelector.tsx +96 -139
  74. package/lib/runtime/components/react/mpx-picker/region.tsx +217 -89
  75. package/lib/runtime/components/react/mpx-picker/selector.tsx +75 -80
  76. package/lib/runtime/components/react/mpx-picker/time.tsx +119 -236
  77. package/lib/runtime/components/react/mpx-picker/type.ts +85 -71
  78. package/lib/runtime/components/react/{mpx-picker-view.tsx → mpx-picker-view/index.tsx} +7 -7
  79. package/lib/runtime/components/react/{mpx-picker-view-column.tsx → mpx-picker-view-column/index.tsx} +70 -19
  80. package/lib/runtime/components/react/{mpx-picker-view-column-item.tsx → mpx-picker-view-column/pickerViewColumnItem.tsx} +8 -5
  81. package/lib/runtime/components/react/{pickerFaces.ts → mpx-picker-view-column/pickerViewFaces.ts} +7 -0
  82. package/lib/runtime/components/react/mpx-popup/index.tsx +86 -0
  83. package/lib/runtime/components/react/mpx-popup/popupBase.tsx +130 -0
  84. package/lib/runtime/components/react/mpx-scroll-view.tsx +249 -43
  85. package/lib/runtime/components/react/mpx-simple-text.tsx +10 -8
  86. package/lib/runtime/components/react/mpx-simple-view.tsx +11 -16
  87. package/lib/runtime/components/react/mpx-video.tsx +2 -2
  88. package/lib/runtime/components/react/mpx-web-view.tsx +7 -4
  89. package/lib/runtime/components/react/types/getInnerListeners.d.ts +5 -1
  90. package/lib/runtime/components/react/types/global.d.ts +1 -1
  91. package/lib/runtime/components/react/utils.tsx +3 -2
  92. package/lib/runtime/components/web/mini-video-controls.min.js +1 -1
  93. package/lib/runtime/components/web/mpx-input.vue +1 -1
  94. package/lib/runtime/stringify.wxs +2 -2
  95. package/lib/template-compiler/compiler.js +8 -8
  96. package/lib/utils/env.js +1 -1
  97. package/package.json +4 -5
  98. /package/lib/runtime/components/react/dist/{pickerVIewContext.js → mpx-picker-view/pickerVIewContext.js} +0 -0
  99. /package/lib/runtime/components/react/dist/{pickerViewIndicator.jsx → mpx-picker-view-column/pickerViewIndicator.jsx} +0 -0
  100. /package/lib/runtime/components/react/dist/{pickerViewMask.jsx → mpx-picker-view-column/pickerViewMask.jsx} +0 -0
  101. /package/lib/runtime/components/react/{pickerVIewContext.ts → mpx-picker-view/pickerVIewContext.ts} +0 -0
  102. /package/lib/runtime/components/react/{pickerViewIndicator.tsx → mpx-picker-view-column/pickerViewIndicator.tsx} +0 -0
  103. /package/lib/runtime/components/react/{pickerViewMask.tsx → mpx-picker-view-column/pickerViewMask.tsx} +0 -0
@@ -1,111 +1,239 @@
1
- import { View, TouchableWithoutFeedback } from 'react-native'
2
- import { Picker, PickerColumnItem } from '@ant-design/react-native'
1
+ import React, { forwardRef, useCallback, useImperativeHandle, useMemo, useRef, useState } from 'react'
2
+ import { StyleSheet, Text, View } from 'react-native'
3
+ import MpxPickerView from '../mpx-picker-view'
4
+ import MpxPickerViewColumn from '../mpx-picker-view-column'
5
+ import { RegionProps } from './type'
3
6
  import { regionData } from './regionData'
4
- import React, { forwardRef, useState, useRef } from 'react'
5
- import useNodesRef, { HandlerRef } from '../useNodesRef' // 引入辅助函数
6
- import { RegionProps, RegionObj, LayoutType } from './type'
7
-
8
- function formateRegionData (clObj: RegionObj[] = [], customItem?: string, depth = 2): PickerColumnItem[] {
9
- const l = depth
10
- // 'PickerData[]' is not assignable to type 'PickerColumn | PickerColumn[]'.
11
- // const obj: PickerColumnItem[] = []
12
- const obj: PickerColumnItem[] = []
13
- if (customItem) {
14
- const objClone: PickerColumnItem = {
15
- value: customItem,
16
- label: customItem,
17
- children: []
7
+ import { HandlerRef } from '../useNodesRef'
8
+ import { extendObject, useUpdateEffect } from '../utils'
9
+
10
+ type FormatObj = {
11
+ indexArr: number[]
12
+ rangeArr: string[][]
13
+ nameArr?: string[]
14
+ }
15
+
16
+ const styles = StyleSheet.create({
17
+ pickerContainer: {
18
+ height: 240,
19
+ paddingHorizontal: 10,
20
+ borderTopLeftRadius: 10,
21
+ borderTopRightRadius: 10
22
+ },
23
+ pickerIndicator: {
24
+ height: 45
25
+ },
26
+ pickerItem: {
27
+ fontSize: 16,
28
+ lineHeight: 45,
29
+ textAlign: 'center'
30
+ }
31
+ })
32
+
33
+ const rangeProvince = regionData.map(item => item.value)
34
+
35
+ const findIndex = (arr: string[], val: string) => {
36
+ const res = arr.findIndex(item => item === val)
37
+ return res === -1 ? 0 : res
38
+ }
39
+
40
+ const getColumnLength = (level: RegionProps['level']) => {
41
+ if (level === 'province') {
42
+ return 1
43
+ } else if (level === 'city') {
44
+ return 2
45
+ } else {
46
+ return 3
47
+ }
48
+ }
49
+
50
+ const valueStr2Obj = (
51
+ value: string[] = [],
52
+ limit: number,
53
+ customItem = ''
54
+ ): FormatObj => {
55
+ const offsetIndex = customItem ? 1 : 0
56
+ let indexProvince = 0
57
+ if (customItem && value[0] === customItem) {
58
+ indexProvince = 0
59
+ } else {
60
+ indexProvince = findIndex(rangeProvince, value[0]) + offsetIndex
61
+ }
62
+ const ans: FormatObj = {
63
+ indexArr: [indexProvince],
64
+ rangeArr: [customItem ? [customItem, ...rangeProvince] : rangeProvince]
65
+ }
66
+ for (
67
+ let i = 1,
68
+ lastIndex = indexProvince,
69
+ lastData = regionData,
70
+ lastRange = rangeProvince;
71
+ i < limit;
72
+ i++
73
+ ) {
74
+ if (customItem) {
75
+ if (lastIndex === 0) {
76
+ if (i === 1) {
77
+ ans.indexArr.push(0, 0)
78
+ ans.rangeArr.push([customItem], [customItem])
79
+ } else {
80
+ ans.indexArr.push(0)
81
+ ans.rangeArr.push([customItem])
82
+ }
83
+ return ans
84
+ }
18
85
  }
19
- const panding = { ...objClone }
20
- let loop = panding
21
- while (depth-- > 0) {
22
- loop.children = [{ ...objClone }]
23
- loop = loop.children[0] as PickerColumnItem
86
+ lastData = lastData[lastIndex - offsetIndex].children!
87
+ lastRange = lastData.map((item) => item.value)
88
+ lastIndex = findIndex(lastRange, value[i]) + offsetIndex
89
+ if (customItem && customItem === value[i]) {
90
+ lastIndex = 0
24
91
  }
25
- obj.push(panding as PickerColumnItem)
92
+ ans.indexArr.push(Math.max(0, lastIndex))
93
+ ans.rangeArr.push(customItem ? [customItem, ...lastRange] : lastRange)
26
94
  }
27
- for (let i = 0; i < clObj.length; i++) {
28
- const region: PickerColumnItem = {
29
- value: clObj[i].value,
30
- label: clObj[i].value
95
+ return ans
96
+ }
97
+
98
+ const valueChanged2Obj = (currentObj: FormatObj, value: number[], limit = 3, customItem = '') => {
99
+ const offsetIndex = customItem ? 1 : 0
100
+ const newValue = new Array(limit).fill(0)
101
+ const currentValue = currentObj.indexArr
102
+ for (let i = 0; i < limit; i++) {
103
+ if (i === limit - 1) {
104
+ return {
105
+ indexArr: value,
106
+ rangeArr: currentObj.rangeArr
107
+ }
31
108
  }
32
- if (clObj[i].children) {
33
- region.children = formateRegionData(clObj[i].children, customItem, l - 1)
109
+ newValue[i] = value[i]
110
+ if (currentValue[i] !== value[i]) {
111
+ break
34
112
  }
35
- obj.push(region)
36
113
  }
37
- return obj
38
- }
39
114
 
40
- const _RegionPicker = forwardRef<HandlerRef<View, RegionProps>, RegionProps>((props: RegionProps, ref): React.JSX.Element => {
41
- const { children, value, bindchange, bindcancel, disabled, style } = props
42
- const formatRegionData = formateRegionData(regionData, props['custom-item'])
115
+ const ans: FormatObj = {
116
+ indexArr: [newValue[0]],
117
+ rangeArr: [currentObj.rangeArr[0]]
118
+ }
119
+ let data = regionData
120
+ for (let i = 1; i < limit; i++) {
121
+ if (customItem) {
122
+ if (newValue[i - 1] === 0) {
123
+ if (i === 1) {
124
+ ans.indexArr.push(0, 0)
125
+ ans.rangeArr.push([customItem], [customItem])
126
+ } else {
127
+ ans.indexArr.push(0)
128
+ ans.rangeArr.push([customItem])
129
+ }
130
+ return ans
131
+ }
132
+ }
133
+ data = data[newValue[i - 1] - offsetIndex].children!
134
+ const range = data.map(item => item.value)
135
+ ans.indexArr.push(newValue[i])
136
+ ans.rangeArr.push(customItem ? [customItem, ...range] : range)
137
+ }
138
+ return ans
139
+ }
43
140
 
44
- const [regionvalue, setRegionValue] = useState(value)
45
- // 存储layout布局信息
46
- const layoutRef = useRef({})
47
- const viewRef = useRef<View>(null)
48
- const nodeRef = useRef(null)
49
- useNodesRef<View, RegionProps>(props, ref, nodeRef, {
50
- style
141
+ const valueNum2String = (value: number[], customItem = '') => {
142
+ let data = regionData
143
+ return value.map(index => {
144
+ if (customItem) {
145
+ if (index === 0) {
146
+ return customItem
147
+ } else {
148
+ index -= 1
149
+ }
150
+ }
151
+ const item = data[index]
152
+ data = item.children!
153
+ return item.value
51
154
  })
155
+ }
52
156
 
53
- const onChange = (value: string[]): void => {
54
- // 通过 value 查找 code
55
- let tmp: RegionObj[] = regionData
56
- const postcode: (string | undefined)[] = []
57
- const code = value.map((item) => {
58
- for (let i = 0; i < tmp.length; i++) {
59
- if (tmp[i].value === item) {
60
- const code = tmp[i].code
61
- postcode.push(tmp[i].postcode)
62
- tmp = tmp[i].children || []
63
- return code
64
- }
65
- }
66
- return item
67
- }).filter(code => !!code)
68
- const detail: Record<string, any> = { value, code }
69
- if (postcode[2]) detail.postcode = postcode[2]
70
- setRegionValue(value)
71
- bindchange && bindchange({
72
- detail
73
- })
157
+ const hasDiff = (currentValue: number[], value: number[], limit = 3) => {
158
+ for (let i = 0; i < limit; i++) {
159
+ if (currentValue[i] !== value[i]) {
160
+ return true
161
+ }
74
162
  }
163
+ return false
164
+ }
165
+
166
+ const PickerRegion = forwardRef<
167
+ HandlerRef<View, RegionProps>,
168
+ RegionProps
169
+ >((props: RegionProps, ref): React.JSX.Element => {
170
+ const { value = [], level = 'region', 'custom-item': customItem = '', bindchange } = props
171
+ const nodeRef = useRef(null)
172
+ const columnLength = useMemo(() => getColumnLength(level), [level])
173
+ const [formatObj, setFormatObj] = useState<FormatObj>(valueStr2Obj(value, columnLength, customItem))
174
+
175
+ const updateValue = useCallback((value: string[] = []) => {
176
+ const calibratedValue = valueStr2Obj(value, columnLength, customItem)
177
+ setFormatObj(calibratedValue)
178
+ }, [columnLength, customItem])
75
179
 
76
- const onElementLayout = (layout: LayoutType) => {
77
- viewRef.current?.measure((x: number, y: number, width: number, height: number, offsetLeft: number, offsetTop: number) => {
78
- layoutRef.current = { x, y, width, height, offsetLeft, offsetTop }
79
- props.getInnerLayout && props.getInnerLayout(layoutRef)
180
+ const _props = useRef(props)
181
+ _props.current = props
182
+ useImperativeHandle(ref, () => ({
183
+ updateValue,
184
+ getNodeInstance: () => ({
185
+ props: _props,
186
+ nodeRef,
187
+ instance: {
188
+ style: {}
189
+ }
80
190
  })
81
- }
191
+ }))
82
192
 
83
- const onDismiss = (): void => {
84
- bindcancel && bindcancel()
85
- }
193
+ useUpdateEffect(() => {
194
+ const calibratedValue = valueStr2Obj(value, columnLength, customItem)
195
+ if (hasDiff(formatObj.indexArr, calibratedValue.indexArr, columnLength)) {
196
+ setFormatObj(calibratedValue)
197
+ }
198
+ }, [value, columnLength, customItem])
86
199
 
87
- const regionProps = {
88
- ref: nodeRef,
89
- data: formatRegionData,
90
- value: regionvalue,
91
- onChange,
92
- disabled,
93
- onDismiss
94
- }
200
+ const onChange = useCallback((e: { detail: { value: number[] } }) => {
201
+ const { value } = e.detail
202
+ const currentValue = formatObj.indexArr
203
+ const newObj = valueChanged2Obj(formatObj, value, columnLength, customItem)
204
+ if (hasDiff(currentValue, value, columnLength)) {
205
+ setFormatObj(newObj)
206
+ }
207
+ bindchange?.({ detail: { value: valueNum2String(newObj.indexArr, customItem) } })
208
+ }, [formatObj, columnLength, customItem, bindchange])
95
209
 
96
- const touchProps = {
97
- onLayout: onElementLayout,
98
- ref: viewRef
210
+ const renderColumn = () => {
211
+ return formatObj.rangeArr?.map((item, index) => (
212
+ // @ts-expect-error ignore
213
+ <MpxPickerViewColumn key={index}>
214
+ {item.map((item, index) => {
215
+ const len = item.length
216
+ const style = extendObject({}, styles.pickerItem, {
217
+ fontSize: len > 5 ? 21 - len : 16
218
+ })
219
+ return <Text key={index} style={style}>
220
+ {item}
221
+ </Text>
222
+ })}
223
+ </MpxPickerViewColumn>
224
+ ))
99
225
  }
100
226
 
101
227
  return (
102
- <Picker {...regionProps}>
103
- <TouchableWithoutFeedback>
104
- <View {...touchProps}>{children}</View>
105
- </TouchableWithoutFeedback>
106
- </Picker>
107
- )
228
+ <MpxPickerView
229
+ style={styles.pickerContainer}
230
+ indicator-style={styles.pickerIndicator}
231
+ value={formatObj.indexArr}
232
+ bindchange={onChange}
233
+ >
234
+ {renderColumn()}
235
+ </MpxPickerView>)
108
236
  })
109
237
 
110
- _RegionPicker.displayName = 'mpx-picker-region'
111
- export default _RegionPicker
238
+ PickerRegion.displayName = 'MpxPickerRegion'
239
+ export default PickerRegion
@@ -1,95 +1,90 @@
1
- /**
2
- * 普通选择器,range可以是Array<Obj> 也可以是Array
3
- */
4
- import { View, TouchableWithoutFeedback } from 'react-native'
5
- import React, { forwardRef, useState, useRef, useEffect } from 'react'
6
- import { Picker, PickerColumn, PickerValue } from '@ant-design/react-native'
7
- import { SelectorProps, Obj, LayoutType } from './type'
8
- import useNodesRef, { HandlerRef } from '../useNodesRef' // 引入辅助函数
1
+ import React, { forwardRef, useImperativeHandle, useRef, useState } from 'react'
2
+ import { StyleSheet, Text, View } from 'react-native'
3
+ import { SelectorProps, Obj, RangeItem } from './type'
4
+ import MpxPickerView from '../mpx-picker-view'
5
+ import MpxPickerViewColumn from '../mpx-picker-view-column'
6
+ import { HandlerRef } from '../useNodesRef'
7
+ import { useUpdateEffect } from '../utils'
9
8
 
10
- type RangeItemType = Obj | number | string
9
+ const styles = StyleSheet.create({
10
+ pickerContainer: {
11
+ height: 240,
12
+ paddingHorizontal: 10,
13
+ borderTopLeftRadius: 10,
14
+ borderTopRightRadius: 10
15
+ },
16
+ pickerIndicator: {
17
+ height: 45
18
+ },
19
+ pickerItem: {
20
+ fontSize: 18,
21
+ lineHeight: 45,
22
+ textAlign: 'center'
23
+ }
24
+ })
11
25
 
12
- const formatRangeFun = (range: Array<RangeItemType>, rangeKey = ''): any => {
13
- let newRange: Object[] = []
14
- newRange = (range || []).map((item: RangeItemType, index) => {
15
- if (typeof item === 'object') {
16
- return { value: index, label: item[rangeKey as string] }
17
- } else {
18
- return { value: index, label: item }
19
- }
20
- })
21
- return newRange as PickerColumn
26
+ const formatRangeFun = (range: RangeItem[], rangeKey = '') =>
27
+ rangeKey ? range.map((item: Obj) => item[rangeKey]) : range
28
+
29
+ const formatValueFn = (value: number | number[] = 0) => {
30
+ const _value = Array.isArray(value) ? value[0] : value
31
+ return +_value
22
32
  }
23
33
 
24
- const _SelectorPicker = forwardRef<HandlerRef<View, SelectorProps>, SelectorProps>((props: SelectorProps, ref): React.JSX.Element => {
25
- const { range, children, value, disabled, bindchange, bindcancel, style } = props
26
- // 格式化数据为Array<*>
27
- const formatRange: PickerColumn = formatRangeFun(range, props['range-key'])
28
- // 选中的索引值
29
- const [selected, setSelected] = useState<PickerValue>(value || 0)
30
- // range数据源
31
- const [data, setData] = useState(formatRange || [])
32
- // 存储layout布局信息
33
- const layoutRef = useRef({})
34
- const viewRef = useRef<View>(null)
34
+ const PickerSelector = forwardRef<
35
+ HandlerRef<View, SelectorProps>,
36
+ SelectorProps
37
+ >((props: SelectorProps, ref): React.JSX.Element => {
38
+ const { value, range = [], bindchange } = props
39
+ const [formatValue, setFormatValue] = useState<number>(formatValueFn(value))
40
+ const formatRange: Array<any> = formatRangeFun(range, props['range-key'])
35
41
  const nodeRef = useRef(null)
36
- useNodesRef<View, SelectorProps>(props, ref, nodeRef, {
37
- style
38
- })
39
42
 
40
- useEffect(() => {
41
- if (range) {
42
- const newFormatRange = formatRangeFun(range, props['range-key'])
43
- setData(newFormatRange)
44
- }
45
- setSelected(() => {
46
- return value
47
- })
48
- }, [range, value])
49
- const defaultValue = [value]
43
+ const updateValue = (value = 0) => {
44
+ const newValue = formatValueFn(value)
45
+ setFormatValue(newValue)
46
+ }
50
47
 
51
- const onChange = (value: PickerValue[]) => {
52
- bindchange && bindchange({
53
- detail: {
54
- value: value && value[0]
48
+ useUpdateEffect(() => {
49
+ updateValue(value)
50
+ }, [value])
51
+
52
+ const _props = useRef(props)
53
+ _props.current = props
54
+ useImperativeHandle(ref, () => ({
55
+ updateValue,
56
+ getNodeInstance: () => ({
57
+ props: _props,
58
+ nodeRef,
59
+ instance: {
60
+ style: {}
55
61
  }
56
62
  })
57
- }
63
+ }))
58
64
 
59
- const onElementLayout = (layout: LayoutType) => {
60
- viewRef.current?.measure((x: number, y: number, width: number, height: number, offsetLeft: number, offsetTop: number) => {
61
- layoutRef.current = { x, y, width, height, offsetLeft, offsetTop }
62
- props.getInnerLayout && props.getInnerLayout(layoutRef)
63
- })
65
+ const onChange = (e: { detail: { value: number[] } }) => {
66
+ const { value } = e.detail
67
+ if (formatValue !== value[0]) {
68
+ setFormatValue(value[0])
69
+ }
70
+ bindchange?.({ detail: { value: value[0] + '' } })
64
71
  }
65
72
 
66
- const antPickerProps = {
67
- ref: nodeRef,
68
- data,
69
- value: [selected],
70
- cols: 1,
71
- defaultValue,
72
- itemHeight: 40,
73
- onChange,
74
- onDismiss: bindcancel && bindcancel
75
- } as any
76
-
77
- const touchProps = {
78
- onLayout: onElementLayout,
79
- ref: viewRef
80
- }
81
73
  return (
82
- <Picker
83
- {...antPickerProps}>
84
- <TouchableWithoutFeedback>
85
- <View {...touchProps}>
86
- {children}
87
- </View>
88
- </TouchableWithoutFeedback>
89
- </Picker>
90
- )
74
+ <MpxPickerView
75
+ style={styles.pickerContainer}
76
+ indicator-style={styles.pickerIndicator}
77
+ value={[formatValue]}
78
+ bindchange={onChange}
79
+ >
80
+ {/* @ts-expect-error ignore */}
81
+ <MpxPickerViewColumn>
82
+ {formatRange.map((item, index) => (
83
+ <Text key={index} style={styles.pickerItem}>{item}</Text>
84
+ ))}
85
+ </MpxPickerViewColumn>
86
+ </MpxPickerView>)
91
87
  })
92
88
 
93
- _SelectorPicker.displayName = 'mpx-picker-selector'
94
-
95
- export default _SelectorPicker
89
+ PickerSelector.displayName = 'MpxPickerSelector'
90
+ export default PickerSelector