@mpxjs/webpack-plugin 2.9.62 → 2.9.64
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/index.js +1 -3
- package/lib/platform/style/wx/index.js +67 -53
- package/lib/react/processStyles.js +1 -0
- package/lib/react/processTemplate.js +2 -3
- package/lib/react/style-helper.js +12 -7
- package/lib/runtime/components/react/context.ts +9 -7
- package/lib/runtime/components/react/dist/context.js +1 -0
- package/lib/runtime/components/react/dist/getInnerListeners.js +12 -1
- package/lib/runtime/components/react/dist/mpx-button.jsx +52 -74
- package/lib/runtime/components/react/dist/mpx-checkbox-group.jsx +19 -18
- package/lib/runtime/components/react/dist/mpx-checkbox.jsx +28 -41
- package/lib/runtime/components/react/dist/mpx-form.jsx +16 -14
- package/lib/runtime/components/react/dist/mpx-icon.jsx +14 -17
- package/lib/runtime/components/react/dist/mpx-image/index.jsx +34 -33
- package/lib/runtime/components/react/dist/mpx-image/svg.jsx +3 -1
- package/lib/runtime/components/react/dist/mpx-input.jsx +35 -31
- package/lib/runtime/components/react/dist/mpx-label.jsx +29 -37
- package/lib/runtime/components/react/dist/mpx-movable-area.jsx +13 -18
- package/lib/runtime/components/react/dist/mpx-movable-view.jsx +8 -8
- package/lib/runtime/components/react/dist/mpx-picker/index.jsx +9 -9
- package/lib/runtime/components/react/dist/mpx-picker/multiSelector.jsx +7 -4
- package/lib/runtime/components/react/dist/mpx-picker/region.jsx +11 -7
- package/lib/runtime/components/react/dist/mpx-picker/selector.jsx +1 -1
- package/lib/runtime/components/react/dist/mpx-picker/time.jsx +18 -18
- package/lib/runtime/components/react/dist/mpx-picker-view-column.jsx +102 -10
- package/lib/runtime/components/react/dist/mpx-picker-view.jsx +147 -53
- package/lib/runtime/components/react/dist/mpx-radio-group.jsx +19 -18
- package/lib/runtime/components/react/dist/mpx-radio.jsx +28 -43
- package/lib/runtime/components/react/dist/mpx-root-portal.jsx +8 -4
- package/lib/runtime/components/react/dist/mpx-scroll-view.jsx +33 -26
- package/lib/runtime/components/react/dist/mpx-swiper/carouse.jsx +139 -74
- package/lib/runtime/components/react/dist/mpx-swiper/index.jsx +14 -6
- package/lib/runtime/components/react/dist/mpx-swiper-item.jsx +19 -11
- package/lib/runtime/components/react/dist/mpx-switch.jsx +17 -14
- package/lib/runtime/components/react/dist/mpx-text.jsx +19 -35
- package/lib/runtime/components/react/dist/mpx-textarea.jsx +1 -1
- package/lib/runtime/components/react/dist/mpx-view.jsx +284 -209
- package/lib/runtime/components/react/dist/mpx-web-view.jsx +8 -5
- package/lib/runtime/components/react/dist/parser.js +218 -0
- package/lib/runtime/components/react/dist/utils.jsx +433 -0
- package/lib/runtime/components/react/getInnerListeners.ts +18 -8
- package/lib/runtime/components/react/mpx-button.tsx +81 -91
- package/lib/runtime/components/react/mpx-checkbox-group.tsx +48 -43
- package/lib/runtime/components/react/mpx-checkbox.tsx +52 -63
- package/lib/runtime/components/react/mpx-form.tsx +49 -21
- package/lib/runtime/components/react/mpx-icon.tsx +30 -27
- package/lib/runtime/components/react/mpx-image/index.tsx +52 -46
- package/lib/runtime/components/react/mpx-image/svg.tsx +5 -3
- package/lib/runtime/components/react/mpx-input.tsx +58 -38
- package/lib/runtime/components/react/mpx-label.tsx +54 -59
- package/lib/runtime/components/react/mpx-movable-area.tsx +38 -24
- package/lib/runtime/components/react/mpx-movable-view.tsx +27 -28
- package/lib/runtime/components/react/mpx-navigator.tsx +2 -2
- package/lib/runtime/components/react/mpx-picker/date.tsx +2 -3
- package/lib/runtime/components/react/mpx-picker/index.tsx +10 -10
- package/lib/runtime/components/react/mpx-picker/multiSelector.tsx +15 -12
- package/lib/runtime/components/react/mpx-picker/region.tsx +21 -18
- package/lib/runtime/components/react/mpx-picker/selector.tsx +5 -6
- package/lib/runtime/components/react/mpx-picker/time.tsx +25 -29
- package/lib/runtime/components/react/mpx-picker/type.ts +1 -1
- package/lib/runtime/components/react/mpx-picker-view-column.tsx +148 -20
- package/lib/runtime/components/react/mpx-picker-view.tsx +179 -63
- package/lib/runtime/components/react/mpx-radio-group.tsx +50 -47
- package/lib/runtime/components/react/mpx-radio.tsx +56 -72
- package/lib/runtime/components/react/mpx-root-portal.tsx +10 -8
- package/lib/runtime/components/react/mpx-scroll-view.tsx +133 -103
- package/lib/runtime/components/react/mpx-swiper/carouse.tsx +174 -96
- package/lib/runtime/components/react/mpx-swiper/index.tsx +18 -9
- package/lib/runtime/components/react/mpx-swiper/type.ts +16 -5
- package/lib/runtime/components/react/mpx-swiper-item.tsx +46 -13
- package/lib/runtime/components/react/mpx-switch.tsx +44 -23
- package/lib/runtime/components/react/mpx-text.tsx +37 -45
- package/lib/runtime/components/react/mpx-textarea.tsx +1 -1
- package/lib/runtime/components/react/mpx-view.tsx +388 -240
- package/lib/runtime/components/react/mpx-web-view.tsx +19 -20
- package/lib/runtime/components/react/parser.ts +245 -0
- package/lib/runtime/components/react/types/common.ts +4 -4
- package/lib/runtime/components/react/types/global.d.ts +14 -2
- package/lib/runtime/components/react/useNodesRef.ts +1 -2
- package/lib/runtime/components/react/utils.tsx +505 -0
- package/lib/template-compiler/compiler.js +28 -20
- package/lib/template-compiler/gen-node-react.js +1 -3
- package/lib/web/processStyles.js +2 -5
- package/package.json +6 -4
- package/lib/runtime/components/react/dist/utils.js +0 -148
- package/lib/runtime/components/react/utils.ts +0 -170
|
@@ -4,7 +4,7 @@ import React, { forwardRef, useState, useRef, useEffect } from 'react'
|
|
|
4
4
|
import useNodesRef, { HandlerRef } from '../useNodesRef' // 引入辅助函数
|
|
5
5
|
import { DateProps, LayoutType } from './type'
|
|
6
6
|
|
|
7
|
-
function formatTimeStr(time = ''): Date {
|
|
7
|
+
function formatTimeStr (time = ''): Date {
|
|
8
8
|
let [year, month, day]: any = time.split('-')
|
|
9
9
|
year = ~~year || 2000
|
|
10
10
|
month = ~~month || 1
|
|
@@ -26,8 +26,7 @@ function dateToString (date: Date, fields: 'day' | 'month' | 'year' = 'day'): st
|
|
|
26
26
|
return ret
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
-
|
|
30
|
-
const _DatePicker = forwardRef<HandlerRef<View, DateProps>, DateProps>((props: DateProps, ref): React.JSX.Element => {
|
|
29
|
+
const _DatePicker = forwardRef<HandlerRef<View, DateProps>, DateProps>((props: DateProps, ref): React.JSX.Element => {
|
|
31
30
|
const { children, start = '1970-01-01', end = '2999-01-01', value, bindchange, bindcancel, disabled, fields } = props
|
|
32
31
|
const [datevalue, setDateValue] = useState(value)
|
|
33
32
|
// 存储layout布局信息
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { View } from 'react-native'
|
|
2
2
|
import { PickerValue } from '@ant-design/react-native'
|
|
3
3
|
import React, { forwardRef, useRef, useContext, useState } from 'react'
|
|
4
|
+
import { warn } from '@mpxjs/utils'
|
|
4
5
|
import useInnerProps, { getCustomEvent } from '../getInnerListeners'
|
|
5
6
|
import useNodesRef, { HandlerRef } from '../useNodesRef' // 引入辅助函数
|
|
6
7
|
import Selector from './selector'
|
|
@@ -10,7 +11,6 @@ import MultiSelector from './multiSelector'
|
|
|
10
11
|
import RegionSelector from './region'
|
|
11
12
|
import { PickerProps, EventType, ValueType } from './type'
|
|
12
13
|
import { FormContext, FormFieldValue } from '../context'
|
|
13
|
-
import { throwReactWarning } from '../utils'
|
|
14
14
|
|
|
15
15
|
/**
|
|
16
16
|
* ✔ mode
|
|
@@ -33,7 +33,7 @@ import { throwReactWarning } from '../utils'
|
|
|
33
33
|
|
|
34
34
|
const _Picker = forwardRef<HandlerRef<View, PickerProps>, PickerProps>((props: PickerProps, ref): React.JSX.Element => {
|
|
35
35
|
const { mode = 'selector', value, bindcancel, bindchange, children, bindcolumnchange } = props
|
|
36
|
-
|
|
36
|
+
const innerLayout = useRef({})
|
|
37
37
|
const { nodeRef } = useNodesRef<View, PickerProps>(props, ref, {
|
|
38
38
|
})
|
|
39
39
|
const innerProps = useInnerProps(props, {
|
|
@@ -69,7 +69,7 @@ const _Picker = forwardRef<HandlerRef<View, PickerProps>, PickerProps>((props: P
|
|
|
69
69
|
}
|
|
70
70
|
if (formValuesMap) {
|
|
71
71
|
if (!props.name) {
|
|
72
|
-
|
|
72
|
+
warn('If a form component is used, the name attribute is required.')
|
|
73
73
|
} else {
|
|
74
74
|
formValuesMap.set(props.name, { getValue, resetValue })
|
|
75
75
|
}
|
|
@@ -103,29 +103,29 @@ const _Picker = forwardRef<HandlerRef<View, PickerProps>, PickerProps>((props: P
|
|
|
103
103
|
const selectorProps = {
|
|
104
104
|
...commonProps,
|
|
105
105
|
value: pickerValue as PickerValue,
|
|
106
|
-
range: props
|
|
106
|
+
range: props.range,
|
|
107
107
|
'range-key': props['range-key']
|
|
108
108
|
}
|
|
109
109
|
|
|
110
110
|
const multiProps = {
|
|
111
111
|
...commonProps,
|
|
112
112
|
value: pickerValue as Array<number>,
|
|
113
|
-
range: props
|
|
113
|
+
range: props.range,
|
|
114
114
|
'range-key': props['range-key']
|
|
115
115
|
}
|
|
116
116
|
|
|
117
117
|
const timeProps = {
|
|
118
118
|
...commonProps,
|
|
119
119
|
value: pickerValue as string,
|
|
120
|
-
start: props
|
|
121
|
-
end: props
|
|
120
|
+
start: props.start,
|
|
121
|
+
end: props.end
|
|
122
122
|
}
|
|
123
123
|
|
|
124
124
|
const dateProps = {
|
|
125
125
|
...commonProps,
|
|
126
126
|
value: pickerValue as string,
|
|
127
|
-
start: props
|
|
128
|
-
end: props
|
|
127
|
+
start: props.start,
|
|
128
|
+
end: props.end,
|
|
129
129
|
fileds: props.fields || 'day'
|
|
130
130
|
}
|
|
131
131
|
|
|
@@ -150,6 +150,6 @@ const _Picker = forwardRef<HandlerRef<View, PickerProps>, PickerProps>((props: P
|
|
|
150
150
|
}
|
|
151
151
|
})
|
|
152
152
|
|
|
153
|
-
_Picker.displayName = 'mpx-picker'
|
|
153
|
+
_Picker.displayName = 'mpx-picker'
|
|
154
154
|
|
|
155
155
|
export default _Picker
|
|
@@ -4,7 +4,7 @@ import React, { forwardRef, useState, useRef, useEffect } from 'react'
|
|
|
4
4
|
import { MultiSelectorProps, LayoutType } from './type'
|
|
5
5
|
import useNodesRef, { HandlerRef } from '../useNodesRef' // 引入辅助函数
|
|
6
6
|
|
|
7
|
-
function convertToObj(item?: any, rangeKey = ''): any {
|
|
7
|
+
function convertToObj (item?: any, rangeKey = ''): any {
|
|
8
8
|
if (typeof item === 'object') {
|
|
9
9
|
return { value: item[rangeKey], label: item[rangeKey] }
|
|
10
10
|
} else {
|
|
@@ -13,13 +13,13 @@ function convertToObj(item?: any, rangeKey = ''): any {
|
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
// eslint-disable-next-line default-param-last
|
|
16
|
-
function formatRangeFun(range: any[][] = [], rangeKey?: string): any[] {
|
|
16
|
+
function formatRangeFun (range: any[][] = [], rangeKey?: string): any[] {
|
|
17
17
|
const result = (range[0] || []).map(item => {
|
|
18
18
|
return convertToObj(item, rangeKey)
|
|
19
19
|
})
|
|
20
20
|
let tmp = result
|
|
21
21
|
for (let i = 1; i < range.length; i++) {
|
|
22
|
-
|
|
22
|
+
const child = Array.isArray(range[i]) ? range[i] : []
|
|
23
23
|
const nextColData = child.map(item => {
|
|
24
24
|
return convertToObj(item, rangeKey)
|
|
25
25
|
})
|
|
@@ -31,7 +31,7 @@ function formatRangeFun(range: any[][] = [], rangeKey?: string): any[] {
|
|
|
31
31
|
return result
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
-
function getIndexByValues(range: any[] = [], value: any[] = []): number[] {
|
|
34
|
+
function getIndexByValues (range: any[] = [], value: any[] = []): number[] {
|
|
35
35
|
let tmp = range
|
|
36
36
|
return value.map(v => {
|
|
37
37
|
for (let i = 0; i < tmp.length; i++) {
|
|
@@ -44,16 +44,16 @@ function getIndexByValues(range: any[] = [], value: any[] = []): number[] {
|
|
|
44
44
|
})
|
|
45
45
|
}
|
|
46
46
|
// [1,1,2] 寻找出[]
|
|
47
|
-
function getInnerValueByIndex(range: any[] = [], value: any[] = []): string[] {
|
|
47
|
+
function getInnerValueByIndex (range: any[] = [], value: any[] = []): string[] {
|
|
48
48
|
let tmp = range
|
|
49
49
|
return value.map(v => {
|
|
50
|
-
|
|
50
|
+
const current = tmp[v].value
|
|
51
51
|
tmp = tmp[v].children
|
|
52
52
|
return current
|
|
53
53
|
})
|
|
54
54
|
}
|
|
55
55
|
// column = 1 value = ['无脊柱动物', '扁性动物', '吸血虫'] 根据column 和value 获取到当前列变动选择的值所在当前列的索引
|
|
56
|
-
function getColumnIndexByValue(range: any[] = [], column: number, value: any[] = []): number {
|
|
56
|
+
function getColumnIndexByValue (range: any[] = [], column: number, value: any[] = []): number {
|
|
57
57
|
let curRange = range
|
|
58
58
|
let changeIndex = 0
|
|
59
59
|
let tmpRange: any[] = []
|
|
@@ -63,23 +63,26 @@ function getColumnIndexByValue(range: any[] = [], column: number, value: any[] =
|
|
|
63
63
|
if (ritem.value === item) {
|
|
64
64
|
changeIndex = rindex
|
|
65
65
|
}
|
|
66
|
+
return ritem
|
|
66
67
|
})
|
|
67
68
|
} else {
|
|
68
|
-
|
|
69
|
+
curRange.map((citem, cindex) => {
|
|
69
70
|
if (citem.value === item) {
|
|
70
71
|
tmpRange = citem.children
|
|
71
72
|
}
|
|
72
|
-
|
|
73
|
-
|
|
73
|
+
return citem
|
|
74
|
+
})
|
|
75
|
+
curRange = tmpRange
|
|
74
76
|
}
|
|
77
|
+
return item
|
|
75
78
|
})
|
|
76
79
|
return changeIndex
|
|
77
80
|
}
|
|
78
81
|
|
|
79
82
|
const _MultiSelectorPicker = forwardRef<HandlerRef<View, MultiSelectorProps>, MultiSelectorProps>((props: MultiSelectorProps, ref): React.JSX.Element => {
|
|
80
83
|
const { range, value, disabled, bindchange, bindcancel, children, bindcolumnchange } = props
|
|
81
|
-
|
|
82
|
-
|
|
84
|
+
const formatRange = formatRangeFun(range, props['range-key'])
|
|
85
|
+
const initValue = getInnerValueByIndex(formatRange, value)
|
|
83
86
|
// 选中的索引值
|
|
84
87
|
const [selected, setSelected] = useState(initValue)
|
|
85
88
|
// range数据源
|
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
import { View, TouchableWithoutFeedback } from 'react-native'
|
|
2
|
-
import { Picker } from '@ant-design/react-native'
|
|
2
|
+
import { Picker, PickerColumnItem } from '@ant-design/react-native'
|
|
3
3
|
import { regionData } from './regionData'
|
|
4
4
|
import React, { forwardRef, useState, useRef } from 'react'
|
|
5
5
|
import useNodesRef, { HandlerRef } from '../useNodesRef' // 引入辅助函数
|
|
6
|
-
import { RegionProps, RegionObj,
|
|
6
|
+
import { RegionProps, RegionObj, LayoutType } from './type'
|
|
7
7
|
|
|
8
|
-
function formateRegionData(clObj: RegionObj[] = [], customItem?: string, depth = 2):
|
|
8
|
+
function formateRegionData (clObj: RegionObj[] = [], customItem?: string, depth = 2): PickerColumnItem[] {
|
|
9
9
|
const l = depth
|
|
10
|
-
|
|
10
|
+
// 'PickerData[]' is not assignable to type 'PickerColumn | PickerColumn[]'.
|
|
11
|
+
// const obj: PickerColumnItem[] = []
|
|
12
|
+
const obj: PickerColumnItem[] = []
|
|
11
13
|
if (customItem) {
|
|
12
|
-
const objClone:
|
|
14
|
+
const objClone: PickerColumnItem = {
|
|
13
15
|
value: customItem,
|
|
14
16
|
label: customItem,
|
|
15
17
|
children: []
|
|
@@ -18,14 +20,14 @@ function formateRegionData(clObj: RegionObj[] = [], customItem?: string, depth =
|
|
|
18
20
|
let loop = panding
|
|
19
21
|
while (depth-- > 0) {
|
|
20
22
|
loop.children = [{ ...objClone }]
|
|
21
|
-
loop = loop.children[0] as
|
|
23
|
+
loop = loop.children[0] as PickerColumnItem
|
|
22
24
|
}
|
|
23
|
-
obj.push(panding)
|
|
25
|
+
obj.push(panding as PickerColumnItem)
|
|
24
26
|
}
|
|
25
27
|
for (let i = 0; i < clObj.length; i++) {
|
|
26
|
-
const region:
|
|
28
|
+
const region: PickerColumnItem = {
|
|
27
29
|
value: clObj[i].value,
|
|
28
|
-
label: clObj[i].value
|
|
30
|
+
label: clObj[i].value
|
|
29
31
|
}
|
|
30
32
|
if (clObj[i].children) {
|
|
31
33
|
region.children = formateRegionData(clObj[i].children, customItem, l - 1)
|
|
@@ -35,11 +37,9 @@ function formateRegionData(clObj: RegionObj[] = [], customItem?: string, depth =
|
|
|
35
37
|
return obj
|
|
36
38
|
}
|
|
37
39
|
|
|
38
|
-
|
|
39
|
-
|
|
40
40
|
const _RegionPicker = forwardRef<HandlerRef<View, RegionProps>, RegionProps>((props: RegionProps, ref): React.JSX.Element => {
|
|
41
41
|
const { children, value, bindchange, bindcancel, disabled } = props
|
|
42
|
-
|
|
42
|
+
const formatRegionData = formateRegionData(regionData, props['custom-item'])
|
|
43
43
|
|
|
44
44
|
const [regionvalue, setRegionValue] = useState(value)
|
|
45
45
|
// 存储layout布局信息
|
|
@@ -60,6 +60,7 @@ const _RegionPicker = forwardRef<HandlerRef<View, RegionProps>, RegionProps>((pr
|
|
|
60
60
|
return code
|
|
61
61
|
}
|
|
62
62
|
}
|
|
63
|
+
return item
|
|
63
64
|
}).filter(code => !!code)
|
|
64
65
|
const detail: Record<string, any> = { value, code }
|
|
65
66
|
if (postcode[2]) detail.postcode = postcode[2]
|
|
@@ -75,13 +76,17 @@ const _RegionPicker = forwardRef<HandlerRef<View, RegionProps>, RegionProps>((pr
|
|
|
75
76
|
props.getInnerLayout && props.getInnerLayout(layoutRef)
|
|
76
77
|
})
|
|
77
78
|
}
|
|
78
|
-
|
|
79
|
+
|
|
80
|
+
const onDismiss = (): void => {
|
|
81
|
+
bindcancel && bindcancel()
|
|
82
|
+
}
|
|
83
|
+
|
|
79
84
|
const regionProps = {
|
|
80
85
|
data: formatRegionData,
|
|
81
86
|
value: regionvalue,
|
|
82
87
|
onChange,
|
|
83
88
|
disabled,
|
|
84
|
-
onDismiss
|
|
89
|
+
onDismiss
|
|
85
90
|
}
|
|
86
91
|
|
|
87
92
|
const touchProps = {
|
|
@@ -90,15 +95,13 @@ const _RegionPicker = forwardRef<HandlerRef<View, RegionProps>, RegionProps>((pr
|
|
|
90
95
|
}
|
|
91
96
|
|
|
92
97
|
return (
|
|
93
|
-
// @ts-ignore
|
|
94
98
|
<Picker {...regionProps}>
|
|
95
99
|
<TouchableWithoutFeedback>
|
|
96
100
|
<View {...touchProps}>{children}</View>
|
|
97
101
|
</TouchableWithoutFeedback>
|
|
98
102
|
</Picker>
|
|
99
103
|
)
|
|
100
|
-
|
|
101
104
|
})
|
|
102
105
|
|
|
103
|
-
_RegionPicker.displayName
|
|
104
|
-
export default _RegionPicker
|
|
106
|
+
_RegionPicker.displayName = 'mpx-picker-region'
|
|
107
|
+
export default _RegionPicker
|
|
@@ -9,7 +9,7 @@ import useNodesRef, { HandlerRef } from '../useNodesRef' // 引入辅助函数
|
|
|
9
9
|
|
|
10
10
|
type RangeItemType = Obj | number | string
|
|
11
11
|
|
|
12
|
-
const
|
|
12
|
+
const formatRangeFun = (range: Array<RangeItemType>, rangeKey = ''): any => {
|
|
13
13
|
let newRange: Object[] = []
|
|
14
14
|
newRange = (range || []).map((item: RangeItemType, index) => {
|
|
15
15
|
if (typeof item === 'object') {
|
|
@@ -24,7 +24,7 @@ const formatRangeFun = (range: Array<RangeItemType>, rangeKey = ''): any => {
|
|
|
24
24
|
const _SelectorPicker = forwardRef<HandlerRef<View, SelectorProps>, SelectorProps>((props: SelectorProps, ref): React.JSX.Element => {
|
|
25
25
|
const { range, children, value, disabled, bindchange, bindcancel } = props
|
|
26
26
|
// 格式化数据为Array<*>
|
|
27
|
-
|
|
27
|
+
const formatRange: PickerColumn = formatRangeFun(range, props['range-key'])
|
|
28
28
|
// 选中的索引值
|
|
29
29
|
const [selected, setSelected] = useState<PickerValue>(value || 0)
|
|
30
30
|
// range数据源
|
|
@@ -44,7 +44,7 @@ const _SelectorPicker = forwardRef<HandlerRef<View, SelectorProps>, SelectorProp
|
|
|
44
44
|
})
|
|
45
45
|
}, [range, value])
|
|
46
46
|
const defaultValue = [value]
|
|
47
|
-
|
|
47
|
+
|
|
48
48
|
const onChange = (value: PickerValue[]) => {
|
|
49
49
|
bindchange && bindchange({
|
|
50
50
|
detail: {
|
|
@@ -60,7 +60,6 @@ const _SelectorPicker = forwardRef<HandlerRef<View, SelectorProps>, SelectorProp
|
|
|
60
60
|
})
|
|
61
61
|
}
|
|
62
62
|
|
|
63
|
-
|
|
64
63
|
const antPickerProps = {
|
|
65
64
|
data,
|
|
66
65
|
value: [selected],
|
|
@@ -69,7 +68,7 @@ const _SelectorPicker = forwardRef<HandlerRef<View, SelectorProps>, SelectorProp
|
|
|
69
68
|
itemHeight: 40,
|
|
70
69
|
onChange,
|
|
71
70
|
onDismiss: bindcancel && bindcancel
|
|
72
|
-
}
|
|
71
|
+
} as any
|
|
73
72
|
|
|
74
73
|
const touchProps = {
|
|
75
74
|
onLayout: onElementLayout,
|
|
@@ -87,6 +86,6 @@ const _SelectorPicker = forwardRef<HandlerRef<View, SelectorProps>, SelectorProp
|
|
|
87
86
|
)
|
|
88
87
|
})
|
|
89
88
|
|
|
90
|
-
_SelectorPicker.displayName = 'mpx-picker-selector'
|
|
89
|
+
_SelectorPicker.displayName = 'mpx-picker-selector'
|
|
91
90
|
|
|
92
91
|
export default _SelectorPicker
|
|
@@ -8,48 +8,47 @@ import { TimeProps } from './type'
|
|
|
8
8
|
// const { height: dHeight, width: dWidth } = Dimensions.get('window');
|
|
9
9
|
// modal属性: {"height": 298.33331298828125, "offsetLeft": 0, "offsetTop": 513.6666870117188, "width": 375, "x": 0, "y": 513.6666870117188}
|
|
10
10
|
// const { height: sHeight, width: sWidth } = Dimensions.get('screen');
|
|
11
|
-
//
|
|
12
|
-
|
|
11
|
+
// 设备屏幕的大小。 screen
|
|
13
12
|
const styles: { [key: string]: Object } = {
|
|
14
13
|
showModal: {
|
|
15
|
-
backgroundColor:
|
|
14
|
+
backgroundColor: 'black',
|
|
16
15
|
opacity: 0.5,
|
|
17
|
-
position:
|
|
18
|
-
width:
|
|
16
|
+
position: 'absolute',
|
|
17
|
+
width: '100%'
|
|
19
18
|
},
|
|
20
19
|
hideModal: {
|
|
21
20
|
opacity: 1,
|
|
22
21
|
height: 0
|
|
23
22
|
},
|
|
24
23
|
modal: {
|
|
25
|
-
backgroundColor:
|
|
24
|
+
backgroundColor: 'black',
|
|
26
25
|
opacity: 0.5
|
|
27
26
|
},
|
|
28
27
|
centeredView: {
|
|
29
28
|
position: 'absolute',
|
|
30
29
|
bottom: 0,
|
|
31
|
-
width:
|
|
30
|
+
width: '100%',
|
|
32
31
|
overflow: 'scroll'
|
|
33
32
|
},
|
|
34
33
|
btnLine: {
|
|
35
|
-
width:
|
|
34
|
+
width: '100%',
|
|
36
35
|
flex: 1,
|
|
37
|
-
flexDirection:
|
|
38
|
-
justifyContent:
|
|
36
|
+
flexDirection: 'row',
|
|
37
|
+
justifyContent: 'space-between',
|
|
39
38
|
borderColor: 20,
|
|
40
39
|
borderBottomWidth: 1,
|
|
41
|
-
backgroundColor:
|
|
40
|
+
backgroundColor: 'white',
|
|
42
41
|
paddingLeft: 40,
|
|
43
42
|
paddingRight: 40
|
|
44
43
|
},
|
|
45
44
|
cancel: {
|
|
46
45
|
height: 50,
|
|
47
|
-
display:
|
|
46
|
+
display: 'flex',
|
|
48
47
|
justifyContent: 'center'
|
|
49
48
|
},
|
|
50
49
|
ok: {
|
|
51
50
|
height: 50,
|
|
52
|
-
display:
|
|
51
|
+
display: 'flex',
|
|
53
52
|
justifyContent: 'center'
|
|
54
53
|
},
|
|
55
54
|
btntext: {
|
|
@@ -58,12 +57,12 @@ const styles: { [key: string]: Object } = {
|
|
|
58
57
|
}
|
|
59
58
|
}
|
|
60
59
|
|
|
61
|
-
function formatStrToInt(timestr: string) {
|
|
62
|
-
|
|
60
|
+
function formatStrToInt (timestr: string) {
|
|
61
|
+
const [start, end] = timestr.split(':')
|
|
63
62
|
return [parseInt(start), parseInt(end)]
|
|
64
63
|
}
|
|
65
64
|
// [9, 59] to 09:59
|
|
66
|
-
function formatStr(arr: any[]) {
|
|
65
|
+
function formatStr (arr: any[]) {
|
|
67
66
|
let [hour, minute] = arr
|
|
68
67
|
if (hour < 10) {
|
|
69
68
|
hour = '0' + hour
|
|
@@ -74,10 +73,10 @@ function formatStr(arr: any[]) {
|
|
|
74
73
|
return hour + ':' + minute
|
|
75
74
|
}
|
|
76
75
|
|
|
77
|
-
function generateMinute() {
|
|
78
|
-
|
|
76
|
+
function generateMinute () {
|
|
77
|
+
const arrMinute: any[] = []
|
|
79
78
|
for (let i = 0; i <= 59; i++) {
|
|
80
|
-
|
|
79
|
+
const obj = {
|
|
81
80
|
label: toSingleStr(i),
|
|
82
81
|
value: i,
|
|
83
82
|
children: []
|
|
@@ -86,10 +85,10 @@ function generateMinute() {
|
|
|
86
85
|
}
|
|
87
86
|
return arrMinute
|
|
88
87
|
}
|
|
89
|
-
function generateColumns(): any[] {
|
|
90
|
-
|
|
88
|
+
function generateColumns (): any[] {
|
|
89
|
+
const pickData: any[] = []
|
|
91
90
|
for (let i = 0; i <= 23; i++) {
|
|
92
|
-
|
|
91
|
+
const obj = {
|
|
93
92
|
label: toSingleStr(i),
|
|
94
93
|
value: i,
|
|
95
94
|
children: generateMinute()
|
|
@@ -100,18 +99,18 @@ function generateColumns(): any[] {
|
|
|
100
99
|
return pickData
|
|
101
100
|
}
|
|
102
101
|
|
|
103
|
-
function toSingleStr(str: number) {
|
|
102
|
+
function toSingleStr (str: number) {
|
|
104
103
|
return str < 10 ? '0' + str : str
|
|
105
104
|
}
|
|
106
105
|
|
|
107
|
-
function toStr(time: string): string {
|
|
106
|
+
function toStr (time: string): string {
|
|
108
107
|
const [hour, minute]: any = formatStrToInt(time)
|
|
109
108
|
const newHour = toSingleStr(hour)
|
|
110
109
|
const newMinute = toSingleStr(minute)
|
|
111
110
|
return '' + newHour + newMinute
|
|
112
111
|
}
|
|
113
112
|
|
|
114
|
-
function checkSelectedIsValid(strStart: string, strEnd: string, selected: number[]):
|
|
113
|
+
function checkSelectedIsValid (strStart: string, strEnd: string, selected: number[]): boolean {
|
|
115
114
|
const strSel = '' + toSingleStr(selected[0]) + toSingleStr(selected[1])
|
|
116
115
|
if (strSel < strStart || strSel > strEnd) return false
|
|
117
116
|
return true
|
|
@@ -196,7 +195,6 @@ const _TimePicker = forwardRef<HandlerRef<View, TimeProps>, TimeProps>((props: T
|
|
|
196
195
|
}
|
|
197
196
|
}
|
|
198
197
|
|
|
199
|
-
|
|
200
198
|
const onElementLayout = () => {
|
|
201
199
|
viewRef.current?.measure((x: number, y: number, width: number, height: number, offsetLeft: number, offsetTop: number) => {
|
|
202
200
|
layoutRef.current = { x, y, width, height, offsetLeft, offsetTop }
|
|
@@ -211,7 +209,6 @@ const _TimePicker = forwardRef<HandlerRef<View, TimeProps>, TimeProps>((props: T
|
|
|
211
209
|
})
|
|
212
210
|
}
|
|
213
211
|
|
|
214
|
-
|
|
215
212
|
const renderModalChildren = () => {
|
|
216
213
|
const pickerProps = {
|
|
217
214
|
data,
|
|
@@ -250,7 +247,7 @@ const _TimePicker = forwardRef<HandlerRef<View, TimeProps>, TimeProps>((props: T
|
|
|
250
247
|
</TouchableWithoutFeedback>
|
|
251
248
|
</View>
|
|
252
249
|
}
|
|
253
|
-
const strStyle = visible ? styles
|
|
250
|
+
const strStyle = visible ? styles.showModal : styles.hideModal
|
|
254
251
|
const mheight = Math.floor(offsetTop)
|
|
255
252
|
|
|
256
253
|
// Animated.View
|
|
@@ -271,4 +268,3 @@ const _TimePicker = forwardRef<HandlerRef<View, TimeProps>, TimeProps>((props: T
|
|
|
271
268
|
_TimePicker.displayName = 'mpx-picker-time'
|
|
272
269
|
|
|
273
270
|
export default _TimePicker
|
|
274
|
-
|
|
@@ -1,28 +1,156 @@
|
|
|
1
1
|
|
|
2
|
-
import { View } from 'react-native'
|
|
3
|
-
import React, { forwardRef,
|
|
4
|
-
import
|
|
2
|
+
import { View, Animated, SafeAreaView, NativeScrollEvent, NativeSyntheticEvent, LayoutChangeEvent, ScrollView } from 'react-native'
|
|
3
|
+
import React, { forwardRef, useState, useEffect, ReactElement, ReactNode } from 'react'
|
|
4
|
+
import { useTransformStyle, splitStyle, splitProps, wrapChildren, useLayout } from './utils'
|
|
5
5
|
import useNodesRef, { HandlerRef } from './useNodesRef' // 引入辅助函数
|
|
6
|
-
|
|
7
6
|
interface ColumnProps {
|
|
8
|
-
children: React.ReactNode
|
|
7
|
+
children: React.ReactNode,
|
|
8
|
+
selectedIndex: number,
|
|
9
|
+
onColumnLayoutChange: Function,
|
|
10
|
+
getInnerLayout: Function,
|
|
11
|
+
onSelectChange: Function,
|
|
12
|
+
style: {
|
|
13
|
+
[key: string]: any
|
|
14
|
+
},
|
|
15
|
+
'enable-var': boolean
|
|
16
|
+
'external-var-context'?: Record<string, any>
|
|
17
|
+
wrapperStyle: {
|
|
18
|
+
height?: number,
|
|
19
|
+
itemHeight: string
|
|
20
|
+
},
|
|
21
|
+
prefix: number
|
|
9
22
|
}
|
|
23
|
+
const defaultItemHeight = 36
|
|
24
|
+
// 每个Column 都有个外层的高度, 内部的元素高度
|
|
25
|
+
// 默认的高度
|
|
26
|
+
const _PickerViewColumn = forwardRef<HandlerRef<ScrollView & View, ColumnProps>, ColumnProps>((props: ColumnProps, ref) => {
|
|
27
|
+
const { children, selectedIndex, onColumnLayoutChange, onSelectChange, getInnerLayout, style, wrapperStyle, 'enable-var': enableVar, 'external-var-context': externalVarContext } = props
|
|
28
|
+
// PickerViewColumn
|
|
29
|
+
const {
|
|
30
|
+
normalStyle,
|
|
31
|
+
hasVarDec,
|
|
32
|
+
varContextRef,
|
|
33
|
+
hasSelfPercent,
|
|
34
|
+
setWidth,
|
|
35
|
+
setHeight
|
|
36
|
+
} = useTransformStyle(style, { enableVar, externalVarContext })
|
|
37
|
+
const { textStyle } = splitStyle(normalStyle)
|
|
38
|
+
const { textProps } = splitProps(props)
|
|
39
|
+
// const { innerStyle } = splitStyle(normalStyle)
|
|
40
|
+
// scrollView的ref
|
|
41
|
+
const { nodeRef: scrollViewRef } = useNodesRef(props, ref, {})
|
|
42
|
+
// 每个元素的高度
|
|
43
|
+
let [itemH, setItemH] = useState(0)
|
|
10
44
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
<View
|
|
18
|
-
ref={nodeRef}
|
|
19
|
-
{...innerProps}>
|
|
20
|
-
{children}
|
|
21
|
-
</View>
|
|
22
|
-
)
|
|
23
|
-
})
|
|
45
|
+
useEffect(() => {
|
|
46
|
+
if (selectedIndex && itemH) {
|
|
47
|
+
const offsetY = selectedIndex * itemH
|
|
48
|
+
scrollViewRef.current?.scrollTo({ x: 0, y: offsetY, animated: true })
|
|
49
|
+
}
|
|
50
|
+
}, [selectedIndex, itemH])
|
|
24
51
|
|
|
25
|
-
|
|
52
|
+
const onScrollViewLayout = () => {
|
|
53
|
+
getInnerLayout && getInnerLayout(layoutRef)
|
|
54
|
+
}
|
|
26
55
|
|
|
27
|
-
|
|
56
|
+
const {
|
|
57
|
+
// 存储layout布局信息
|
|
58
|
+
layoutRef,
|
|
59
|
+
layoutProps
|
|
60
|
+
} = useLayout({ props, hasSelfPercent, setWidth, setHeight, nodeRef: scrollViewRef, onLayout: onScrollViewLayout })
|
|
61
|
+
|
|
62
|
+
const onItemLayout = (e: LayoutChangeEvent) => {
|
|
63
|
+
const layout = e.nativeEvent.layout
|
|
64
|
+
if (layout.height && itemH !== layout.height) {
|
|
65
|
+
itemH = layout.height
|
|
66
|
+
setItemH(layout.height)
|
|
67
|
+
onColumnLayoutChange && onColumnLayoutChange({ height: layout.height * 5 })
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const onMomentumScrollEnd = (e: NativeSyntheticEvent<NativeScrollEvent>) => {
|
|
72
|
+
if (scrollViewRef && itemH) {
|
|
73
|
+
const { y: scrollY } = e.nativeEvent.contentOffset
|
|
74
|
+
const selIndex = Math.floor(scrollY / itemH)
|
|
75
|
+
onSelectChange(selIndex)
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const renderInnerchild = () => {
|
|
80
|
+
// Fragment 节点
|
|
81
|
+
let realElement: Array<ReactNode> = []
|
|
82
|
+
const getRealChilds = () => {
|
|
83
|
+
if (Array.isArray(children)) {
|
|
84
|
+
realElement = children
|
|
85
|
+
} else {
|
|
86
|
+
const tempChild = children as ReactElement
|
|
87
|
+
if (tempChild.props.children && tempChild.props.children) {
|
|
88
|
+
realElement = tempChild.props.children
|
|
89
|
+
} else {
|
|
90
|
+
realElement = [children]
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
return realElement
|
|
94
|
+
}
|
|
28
95
|
|
|
96
|
+
const realChilds = getRealChilds()
|
|
97
|
+
const arrChild = realChilds.map((item: React.ReactNode, index: number) => {
|
|
98
|
+
const InnerProps = index === 0 ? { onLayout: onItemLayout } : {}
|
|
99
|
+
const strKey = 'picker' + props.prefix + '-column' + index
|
|
100
|
+
const arrHeight = (wrapperStyle.itemHeight + '').match(/\d+/g) || []
|
|
101
|
+
const iHeight = (arrHeight[0] || defaultItemHeight) as number
|
|
102
|
+
return <View key={strKey} {...InnerProps} style={[{ height: iHeight, width: '100%' }]}>
|
|
103
|
+
{wrapChildren(
|
|
104
|
+
{
|
|
105
|
+
children: item
|
|
106
|
+
},
|
|
107
|
+
{
|
|
108
|
+
hasVarDec,
|
|
109
|
+
varContext: varContextRef.current,
|
|
110
|
+
textStyle,
|
|
111
|
+
textProps
|
|
112
|
+
}
|
|
113
|
+
)}
|
|
114
|
+
</View>
|
|
115
|
+
})
|
|
116
|
+
const totalHeight = itemH * 5
|
|
117
|
+
if (wrapperStyle.height && totalHeight !== wrapperStyle.height) {
|
|
118
|
+
const fix = Math.ceil((totalHeight - wrapperStyle.height) / 2)
|
|
119
|
+
arrChild.unshift(<View key="picker-column-0" style={[{ height: itemH - fix }]}></View>)
|
|
120
|
+
arrChild.unshift(<View key="picker-column-1" style={[{ height: itemH }]}></View>)
|
|
121
|
+
arrChild.push(<View key="picker-column-2" style={[{ height: itemH }]}></View>)
|
|
122
|
+
arrChild.push(<View key="picker-column-3" style={[{ height: itemH - fix }]}></View>)
|
|
123
|
+
} else {
|
|
124
|
+
arrChild.unshift(<View key="picker-column-0" style={[{ height: itemH }]}></View>)
|
|
125
|
+
arrChild.unshift(<View key="picker-column-1" style={[{ height: itemH }]}></View>)
|
|
126
|
+
arrChild.push(<View key="picker-column-2" style={[{ height: itemH }]}></View>)
|
|
127
|
+
arrChild.push(<View key="picker-column-3" style={[{ height: itemH }]}></View>)
|
|
128
|
+
}
|
|
129
|
+
return arrChild
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
const renderScollView = () => {
|
|
133
|
+
return (<Animated.ScrollView
|
|
134
|
+
horizontal={false}
|
|
135
|
+
ref={scrollViewRef}
|
|
136
|
+
bounces={false}
|
|
137
|
+
scrollsToTop={false}
|
|
138
|
+
removeClippedSubviews={true}
|
|
139
|
+
showsHorizontalScrollIndicator={false}
|
|
140
|
+
showsVerticalScrollIndicator={false}
|
|
141
|
+
pagingEnabled={false}
|
|
142
|
+
snapToInterval={itemH}
|
|
143
|
+
automaticallyAdjustContentInsets={false}
|
|
144
|
+
{...layoutProps}
|
|
145
|
+
onMomentumScrollEnd={onMomentumScrollEnd}>
|
|
146
|
+
{renderInnerchild()}
|
|
147
|
+
</Animated.ScrollView>)
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
return (<SafeAreaView style={[{ display: 'flex', flex: 1 }]}>
|
|
151
|
+
{ renderScollView() }
|
|
152
|
+
</SafeAreaView>)
|
|
153
|
+
})
|
|
154
|
+
|
|
155
|
+
_PickerViewColumn.displayName = 'mpx-picker-view-column'
|
|
156
|
+
export default _PickerViewColumn
|