@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
|
@@ -5,6 +5,8 @@ import React, { forwardRef, useState, useRef } from 'react';
|
|
|
5
5
|
import useNodesRef from '../useNodesRef'; // 引入辅助函数
|
|
6
6
|
function formateRegionData(clObj = [], customItem, depth = 2) {
|
|
7
7
|
const l = depth;
|
|
8
|
+
// 'PickerData[]' is not assignable to type 'PickerColumn | PickerColumn[]'.
|
|
9
|
+
// const obj: PickerColumnItem[] = []
|
|
8
10
|
const obj = [];
|
|
9
11
|
if (customItem) {
|
|
10
12
|
const objClone = {
|
|
@@ -23,7 +25,7 @@ function formateRegionData(clObj = [], customItem, depth = 2) {
|
|
|
23
25
|
for (let i = 0; i < clObj.length; i++) {
|
|
24
26
|
const region = {
|
|
25
27
|
value: clObj[i].value,
|
|
26
|
-
label: clObj[i].value
|
|
28
|
+
label: clObj[i].value
|
|
27
29
|
};
|
|
28
30
|
if (clObj[i].children) {
|
|
29
31
|
region.children = formateRegionData(clObj[i].children, customItem, l - 1);
|
|
@@ -34,7 +36,7 @@ function formateRegionData(clObj = [], customItem, depth = 2) {
|
|
|
34
36
|
}
|
|
35
37
|
const _RegionPicker = forwardRef((props, ref) => {
|
|
36
38
|
const { children, value, bindchange, bindcancel, disabled } = props;
|
|
37
|
-
|
|
39
|
+
const formatRegionData = formateRegionData(regionData, props['custom-item']);
|
|
38
40
|
const [regionvalue, setRegionValue] = useState(value);
|
|
39
41
|
// 存储layout布局信息
|
|
40
42
|
const layoutRef = useRef({});
|
|
@@ -52,6 +54,7 @@ const _RegionPicker = forwardRef((props, ref) => {
|
|
|
52
54
|
return code;
|
|
53
55
|
}
|
|
54
56
|
}
|
|
57
|
+
return item;
|
|
55
58
|
}).filter(code => !!code);
|
|
56
59
|
const detail = { value, code };
|
|
57
60
|
if (postcode[2])
|
|
@@ -67,24 +70,25 @@ const _RegionPicker = forwardRef((props, ref) => {
|
|
|
67
70
|
props.getInnerLayout && props.getInnerLayout(layoutRef);
|
|
68
71
|
});
|
|
69
72
|
};
|
|
73
|
+
const onDismiss = () => {
|
|
74
|
+
bindcancel && bindcancel();
|
|
75
|
+
};
|
|
70
76
|
const regionProps = {
|
|
71
77
|
data: formatRegionData,
|
|
72
78
|
value: regionvalue,
|
|
73
79
|
onChange,
|
|
74
80
|
disabled,
|
|
75
|
-
onDismiss
|
|
81
|
+
onDismiss
|
|
76
82
|
};
|
|
77
83
|
const touchProps = {
|
|
78
84
|
onLayout: onElementLayout,
|
|
79
85
|
ref: viewRef
|
|
80
86
|
};
|
|
81
|
-
return (
|
|
82
|
-
// @ts-ignore
|
|
83
|
-
<Picker {...regionProps}>
|
|
87
|
+
return (<Picker {...regionProps}>
|
|
84
88
|
<TouchableWithoutFeedback>
|
|
85
89
|
<View {...touchProps}>{children}</View>
|
|
86
90
|
</TouchableWithoutFeedback>
|
|
87
91
|
</Picker>);
|
|
88
92
|
});
|
|
89
|
-
_RegionPicker.displayName
|
|
93
|
+
_RegionPicker.displayName = 'mpx-picker-region';
|
|
90
94
|
export default _RegionPicker;
|
|
@@ -20,7 +20,7 @@ const formatRangeFun = (range, rangeKey = '') => {
|
|
|
20
20
|
const _SelectorPicker = forwardRef((props, ref) => {
|
|
21
21
|
const { range, children, value, disabled, bindchange, bindcancel } = props;
|
|
22
22
|
// 格式化数据为Array<*>
|
|
23
|
-
|
|
23
|
+
const formatRange = formatRangeFun(range, props['range-key']);
|
|
24
24
|
// 选中的索引值
|
|
25
25
|
const [selected, setSelected] = useState(value || 0);
|
|
26
26
|
// range数据源
|
|
@@ -6,47 +6,47 @@ import useNodesRef from '../useNodesRef'; // 引入辅助函数
|
|
|
6
6
|
// const { height: dHeight, width: dWidth } = Dimensions.get('window');
|
|
7
7
|
// modal属性: {"height": 298.33331298828125, "offsetLeft": 0, "offsetTop": 513.6666870117188, "width": 375, "x": 0, "y": 513.6666870117188}
|
|
8
8
|
// const { height: sHeight, width: sWidth } = Dimensions.get('screen');
|
|
9
|
-
//
|
|
9
|
+
// 设备屏幕的大小。 screen
|
|
10
10
|
const styles = {
|
|
11
11
|
showModal: {
|
|
12
|
-
backgroundColor:
|
|
12
|
+
backgroundColor: 'black',
|
|
13
13
|
opacity: 0.5,
|
|
14
|
-
position:
|
|
15
|
-
width:
|
|
14
|
+
position: 'absolute',
|
|
15
|
+
width: '100%'
|
|
16
16
|
},
|
|
17
17
|
hideModal: {
|
|
18
18
|
opacity: 1,
|
|
19
19
|
height: 0
|
|
20
20
|
},
|
|
21
21
|
modal: {
|
|
22
|
-
backgroundColor:
|
|
22
|
+
backgroundColor: 'black',
|
|
23
23
|
opacity: 0.5
|
|
24
24
|
},
|
|
25
25
|
centeredView: {
|
|
26
26
|
position: 'absolute',
|
|
27
27
|
bottom: 0,
|
|
28
|
-
width:
|
|
28
|
+
width: '100%',
|
|
29
29
|
overflow: 'scroll'
|
|
30
30
|
},
|
|
31
31
|
btnLine: {
|
|
32
|
-
width:
|
|
32
|
+
width: '100%',
|
|
33
33
|
flex: 1,
|
|
34
|
-
flexDirection:
|
|
35
|
-
justifyContent:
|
|
34
|
+
flexDirection: 'row',
|
|
35
|
+
justifyContent: 'space-between',
|
|
36
36
|
borderColor: 20,
|
|
37
37
|
borderBottomWidth: 1,
|
|
38
|
-
backgroundColor:
|
|
38
|
+
backgroundColor: 'white',
|
|
39
39
|
paddingLeft: 40,
|
|
40
40
|
paddingRight: 40
|
|
41
41
|
},
|
|
42
42
|
cancel: {
|
|
43
43
|
height: 50,
|
|
44
|
-
display:
|
|
44
|
+
display: 'flex',
|
|
45
45
|
justifyContent: 'center'
|
|
46
46
|
},
|
|
47
47
|
ok: {
|
|
48
48
|
height: 50,
|
|
49
|
-
display:
|
|
49
|
+
display: 'flex',
|
|
50
50
|
justifyContent: 'center'
|
|
51
51
|
},
|
|
52
52
|
btntext: {
|
|
@@ -55,7 +55,7 @@ const styles = {
|
|
|
55
55
|
}
|
|
56
56
|
};
|
|
57
57
|
function formatStrToInt(timestr) {
|
|
58
|
-
|
|
58
|
+
const [start, end] = timestr.split(':');
|
|
59
59
|
return [parseInt(start), parseInt(end)];
|
|
60
60
|
}
|
|
61
61
|
// [9, 59] to 09:59
|
|
@@ -70,9 +70,9 @@ function formatStr(arr) {
|
|
|
70
70
|
return hour + ':' + minute;
|
|
71
71
|
}
|
|
72
72
|
function generateMinute() {
|
|
73
|
-
|
|
73
|
+
const arrMinute = [];
|
|
74
74
|
for (let i = 0; i <= 59; i++) {
|
|
75
|
-
|
|
75
|
+
const obj = {
|
|
76
76
|
label: toSingleStr(i),
|
|
77
77
|
value: i,
|
|
78
78
|
children: []
|
|
@@ -82,9 +82,9 @@ function generateMinute() {
|
|
|
82
82
|
return arrMinute;
|
|
83
83
|
}
|
|
84
84
|
function generateColumns() {
|
|
85
|
-
|
|
85
|
+
const pickData = [];
|
|
86
86
|
for (let i = 0; i <= 23; i++) {
|
|
87
|
-
|
|
87
|
+
const obj = {
|
|
88
88
|
label: toSingleStr(i),
|
|
89
89
|
value: i,
|
|
90
90
|
children: generateMinute()
|
|
@@ -228,7 +228,7 @@ const _TimePicker = forwardRef((props, ref) => {
|
|
|
228
228
|
</TouchableWithoutFeedback>
|
|
229
229
|
</View>;
|
|
230
230
|
};
|
|
231
|
-
const strStyle = visible ? styles
|
|
231
|
+
const strStyle = visible ? styles.showModal : styles.hideModal;
|
|
232
232
|
const mheight = Math.floor(offsetTop);
|
|
233
233
|
// Animated.View
|
|
234
234
|
return (<>
|
|
@@ -1,15 +1,107 @@
|
|
|
1
|
-
import { View } from 'react-native';
|
|
2
|
-
import React, { forwardRef,
|
|
3
|
-
import
|
|
1
|
+
import { View, Animated, SafeAreaView } from 'react-native';
|
|
2
|
+
import React, { forwardRef, useState, useEffect } from 'react';
|
|
3
|
+
import { useTransformStyle, splitStyle, splitProps, wrapChildren, useLayout } from './utils';
|
|
4
4
|
import useNodesRef from './useNodesRef'; // 引入辅助函数
|
|
5
|
+
const defaultItemHeight = 36;
|
|
6
|
+
// 每个Column 都有个外层的高度, 内部的元素高度
|
|
7
|
+
// 默认的高度
|
|
5
8
|
const _PickerViewColumn = forwardRef((props, ref) => {
|
|
6
|
-
const { children } = props;
|
|
7
|
-
|
|
8
|
-
const {
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
{
|
|
12
|
-
|
|
9
|
+
const { children, selectedIndex, onColumnLayoutChange, onSelectChange, getInnerLayout, style, wrapperStyle, 'enable-var': enableVar, 'external-var-context': externalVarContext } = props;
|
|
10
|
+
// PickerViewColumn
|
|
11
|
+
const { normalStyle, hasVarDec, varContextRef, hasSelfPercent, setWidth, setHeight } = useTransformStyle(style, { enableVar, externalVarContext });
|
|
12
|
+
const { textStyle } = splitStyle(normalStyle);
|
|
13
|
+
const { textProps } = splitProps(props);
|
|
14
|
+
// const { innerStyle } = splitStyle(normalStyle)
|
|
15
|
+
// scrollView的ref
|
|
16
|
+
const { nodeRef: scrollViewRef } = useNodesRef(props, ref, {});
|
|
17
|
+
// 每个元素的高度
|
|
18
|
+
let [itemH, setItemH] = useState(0);
|
|
19
|
+
useEffect(() => {
|
|
20
|
+
if (selectedIndex && itemH) {
|
|
21
|
+
const offsetY = selectedIndex * itemH;
|
|
22
|
+
scrollViewRef.current?.scrollTo({ x: 0, y: offsetY, animated: true });
|
|
23
|
+
}
|
|
24
|
+
}, [selectedIndex, itemH]);
|
|
25
|
+
const onScrollViewLayout = () => {
|
|
26
|
+
getInnerLayout && getInnerLayout(layoutRef);
|
|
27
|
+
};
|
|
28
|
+
const {
|
|
29
|
+
// 存储layout布局信息
|
|
30
|
+
layoutRef, layoutProps } = useLayout({ props, hasSelfPercent, setWidth, setHeight, nodeRef: scrollViewRef, onLayout: onScrollViewLayout });
|
|
31
|
+
const onItemLayout = (e) => {
|
|
32
|
+
const layout = e.nativeEvent.layout;
|
|
33
|
+
if (layout.height && itemH !== layout.height) {
|
|
34
|
+
itemH = layout.height;
|
|
35
|
+
setItemH(layout.height);
|
|
36
|
+
onColumnLayoutChange && onColumnLayoutChange({ height: layout.height * 5 });
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
const onMomentumScrollEnd = (e) => {
|
|
40
|
+
if (scrollViewRef && itemH) {
|
|
41
|
+
const { y: scrollY } = e.nativeEvent.contentOffset;
|
|
42
|
+
const selIndex = Math.floor(scrollY / itemH);
|
|
43
|
+
onSelectChange(selIndex);
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
const renderInnerchild = () => {
|
|
47
|
+
// Fragment 节点
|
|
48
|
+
let realElement = [];
|
|
49
|
+
const getRealChilds = () => {
|
|
50
|
+
if (Array.isArray(children)) {
|
|
51
|
+
realElement = children;
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
const tempChild = children;
|
|
55
|
+
if (tempChild.props.children && tempChild.props.children) {
|
|
56
|
+
realElement = tempChild.props.children;
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
realElement = [children];
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return realElement;
|
|
63
|
+
};
|
|
64
|
+
const realChilds = getRealChilds();
|
|
65
|
+
const arrChild = realChilds.map((item, index) => {
|
|
66
|
+
const InnerProps = index === 0 ? { onLayout: onItemLayout } : {};
|
|
67
|
+
const strKey = 'picker' + props.prefix + '-column' + index;
|
|
68
|
+
const arrHeight = (wrapperStyle.itemHeight + '').match(/\d+/g) || [];
|
|
69
|
+
const iHeight = (arrHeight[0] || defaultItemHeight);
|
|
70
|
+
return <View key={strKey} {...InnerProps} style={[{ height: iHeight, width: '100%' }]}>
|
|
71
|
+
{wrapChildren({
|
|
72
|
+
children: item
|
|
73
|
+
}, {
|
|
74
|
+
hasVarDec,
|
|
75
|
+
varContext: varContextRef.current,
|
|
76
|
+
textStyle,
|
|
77
|
+
textProps
|
|
78
|
+
})}
|
|
79
|
+
</View>;
|
|
80
|
+
});
|
|
81
|
+
const totalHeight = itemH * 5;
|
|
82
|
+
if (wrapperStyle.height && totalHeight !== wrapperStyle.height) {
|
|
83
|
+
const fix = Math.ceil((totalHeight - wrapperStyle.height) / 2);
|
|
84
|
+
arrChild.unshift(<View key="picker-column-0" style={[{ height: itemH - fix }]}></View>);
|
|
85
|
+
arrChild.unshift(<View key="picker-column-1" style={[{ height: itemH }]}></View>);
|
|
86
|
+
arrChild.push(<View key="picker-column-2" style={[{ height: itemH }]}></View>);
|
|
87
|
+
arrChild.push(<View key="picker-column-3" style={[{ height: itemH - fix }]}></View>);
|
|
88
|
+
}
|
|
89
|
+
else {
|
|
90
|
+
arrChild.unshift(<View key="picker-column-0" style={[{ height: itemH }]}></View>);
|
|
91
|
+
arrChild.unshift(<View key="picker-column-1" style={[{ height: itemH }]}></View>);
|
|
92
|
+
arrChild.push(<View key="picker-column-2" style={[{ height: itemH }]}></View>);
|
|
93
|
+
arrChild.push(<View key="picker-column-3" style={[{ height: itemH }]}></View>);
|
|
94
|
+
}
|
|
95
|
+
return arrChild;
|
|
96
|
+
};
|
|
97
|
+
const renderScollView = () => {
|
|
98
|
+
return (<Animated.ScrollView horizontal={false} ref={scrollViewRef} bounces={false} scrollsToTop={false} removeClippedSubviews={true} showsHorizontalScrollIndicator={false} showsVerticalScrollIndicator={false} pagingEnabled={false} snapToInterval={itemH} automaticallyAdjustContentInsets={false} {...layoutProps} onMomentumScrollEnd={onMomentumScrollEnd}>
|
|
99
|
+
{renderInnerchild()}
|
|
100
|
+
</Animated.ScrollView>);
|
|
101
|
+
};
|
|
102
|
+
return (<SafeAreaView style={[{ display: 'flex', flex: 1 }]}>
|
|
103
|
+
{renderScollView()}
|
|
104
|
+
</SafeAreaView>);
|
|
13
105
|
});
|
|
14
106
|
_PickerViewColumn.displayName = 'mpx-picker-view-column';
|
|
15
107
|
export default _PickerViewColumn;
|
|
@@ -1,68 +1,162 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
4
|
-
import { getCustomEvent } from './getInnerListeners';
|
|
1
|
+
import { View } from 'react-native';
|
|
2
|
+
import { LinearGradient } from 'react-native-linear-gradient';
|
|
3
|
+
import React, { forwardRef, useState, useRef } from 'react';
|
|
4
|
+
import useInnerProps, { getCustomEvent } from './getInnerListeners';
|
|
5
5
|
import useNodesRef from './useNodesRef'; // 引入辅助函数
|
|
6
|
+
import { parseInlineStyle, useTransformStyle, splitStyle, splitProps, useLayout, wrapChildren } from './utils';
|
|
7
|
+
const styles = {
|
|
8
|
+
wrapper: {
|
|
9
|
+
display: 'flex',
|
|
10
|
+
flex: 1,
|
|
11
|
+
flexDirection: 'row',
|
|
12
|
+
justifyContent: 'space-around',
|
|
13
|
+
overflow: 'hidden',
|
|
14
|
+
alignItems: 'center'
|
|
15
|
+
},
|
|
16
|
+
maskTop: {
|
|
17
|
+
position: 'absolute',
|
|
18
|
+
width: 1000,
|
|
19
|
+
zIndex: 100
|
|
20
|
+
},
|
|
21
|
+
maskBottom: {
|
|
22
|
+
position: 'absolute',
|
|
23
|
+
width: 1000,
|
|
24
|
+
zIndex: 100
|
|
25
|
+
}
|
|
26
|
+
};
|
|
6
27
|
const _PickerView = forwardRef((props, ref) => {
|
|
7
|
-
const { children,
|
|
8
|
-
|
|
28
|
+
const { children, value = [], bindchange, style, 'enable-var': enableVar, 'external-var-context': externalVarContext } = props;
|
|
29
|
+
// indicatorStyle 需要转换为rn的style
|
|
30
|
+
// 微信设置到pick-view上上设置的normalStyle如border等需要转换成RN的style然后进行透传
|
|
31
|
+
const indicatorStyle = parseInlineStyle(props['indicator-style']);
|
|
32
|
+
const { height: indicatorH, width: indicatorW } = indicatorStyle;
|
|
9
33
|
const { nodeRef } = useNodesRef(props, ref, {});
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
34
|
+
// picker-view 设置的color等textStyle,在小程序上的表现是可以继承到最内层的text样式, 但是RN内部column是slot无法设置, 需要业务自己在column内的元素上设置
|
|
35
|
+
const { normalStyle, hasVarDec, varContextRef, hasSelfPercent, setWidth, setHeight } = useTransformStyle(style, { enableVar, externalVarContext });
|
|
36
|
+
const { textStyle } = splitStyle(normalStyle);
|
|
37
|
+
const { textProps } = splitProps(props);
|
|
38
|
+
const {
|
|
39
|
+
// 存储layout布局信息
|
|
40
|
+
layoutRef, layoutProps, layoutStyle } = useLayout({ props, hasSelfPercent, setWidth, setHeight, nodeRef: nodeRef });
|
|
41
|
+
const isSetW = indicatorW !== undefined ? 1 : 0;
|
|
42
|
+
const cloneRef = useRef(null);
|
|
43
|
+
const maskPos = {};
|
|
44
|
+
let [pickH, setPickH] = useState(0);
|
|
45
|
+
const itemH = pickH / 5;
|
|
46
|
+
if (normalStyle?.height && pickH && pickH !== normalStyle?.height) {
|
|
47
|
+
maskPos.height = itemH * 2 + Math.ceil((normalStyle.height - pickH) / 2);
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
maskPos.height = itemH * 2;
|
|
51
|
+
}
|
|
52
|
+
const onColumnLayoutChange = (layoutConfig) => {
|
|
53
|
+
pickH = layoutConfig.height;
|
|
54
|
+
setPickH(layoutConfig.height);
|
|
19
55
|
};
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
56
|
+
const onSelectChange = (columnIndex, selIndex) => {
|
|
57
|
+
const changeValue = value.slice();
|
|
58
|
+
changeValue[columnIndex] = selIndex;
|
|
59
|
+
const eventData = getCustomEvent('change', {}, { detail: { value: changeValue, source: 'change' }, layoutRef });
|
|
60
|
+
bindchange && bindchange(eventData);
|
|
25
61
|
};
|
|
26
|
-
const
|
|
27
|
-
|
|
62
|
+
const innerProps = useInnerProps(props, {
|
|
63
|
+
ref: nodeRef,
|
|
64
|
+
style: {
|
|
65
|
+
...normalStyle,
|
|
66
|
+
...layoutStyle,
|
|
67
|
+
position: 'relative',
|
|
68
|
+
overflow: 'hidden'
|
|
69
|
+
},
|
|
70
|
+
...layoutProps
|
|
71
|
+
}, [
|
|
72
|
+
'enable-offset'
|
|
73
|
+
], { layoutRef });
|
|
74
|
+
const cloneChild = (child, index) => {
|
|
75
|
+
// const extraProps = index === 0 ? { getInnerLayout: getInnerLayout, innerProps } : {}
|
|
76
|
+
const extraProps = {};
|
|
77
|
+
const childProps = {
|
|
78
|
+
...child?.props,
|
|
79
|
+
ref: cloneRef,
|
|
80
|
+
prefix: index,
|
|
81
|
+
key: 'pick-view' + index,
|
|
82
|
+
wrapperStyle: {
|
|
83
|
+
height: normalStyle?.height || 0,
|
|
84
|
+
itemHeight: indicatorH || 0
|
|
85
|
+
},
|
|
86
|
+
onColumnLayoutChange,
|
|
87
|
+
onSelectChange: onSelectChange.bind(null, index),
|
|
88
|
+
selectedIndex: value?.[index] || 0,
|
|
89
|
+
...extraProps
|
|
90
|
+
};
|
|
91
|
+
const realElement = React.cloneElement(child, childProps);
|
|
92
|
+
return wrapChildren({
|
|
93
|
+
children: realElement
|
|
94
|
+
}, {
|
|
95
|
+
hasVarDec,
|
|
96
|
+
varContext: varContextRef.current,
|
|
97
|
+
textStyle,
|
|
98
|
+
textProps
|
|
99
|
+
});
|
|
28
100
|
};
|
|
29
|
-
const
|
|
30
|
-
|
|
101
|
+
const renderTopMask = () => {
|
|
102
|
+
const linearProps = {
|
|
103
|
+
colors: ['rgba(255,255,255,0.8)', 'rgba(255,255,255,0.2)'],
|
|
104
|
+
style: [
|
|
105
|
+
styles.maskTop,
|
|
106
|
+
{
|
|
107
|
+
height: maskPos.height,
|
|
108
|
+
top: 0,
|
|
109
|
+
pointerEvents: 'none'
|
|
110
|
+
}
|
|
111
|
+
]
|
|
112
|
+
};
|
|
113
|
+
return (<LinearGradient {...linearProps}/>);
|
|
31
114
|
};
|
|
32
|
-
const
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
115
|
+
const renderBottomMask = () => {
|
|
116
|
+
const linearProps = {
|
|
117
|
+
colors: ['rgba(255,255,255,0.2)', 'rgba(255,255,255,0.8)'],
|
|
118
|
+
style: [
|
|
119
|
+
styles.maskBottom,
|
|
120
|
+
{
|
|
121
|
+
height: maskPos.height,
|
|
122
|
+
bottom: 0,
|
|
123
|
+
pointerEvents: 'none'
|
|
124
|
+
}
|
|
125
|
+
]
|
|
126
|
+
};
|
|
127
|
+
return <LinearGradient {...linearProps}></LinearGradient>;
|
|
39
128
|
};
|
|
40
|
-
const
|
|
41
|
-
return
|
|
42
|
-
|
|
43
|
-
|
|
129
|
+
const renderLine = () => {
|
|
130
|
+
return <View style={[{
|
|
131
|
+
position: 'absolute',
|
|
132
|
+
top: '50%',
|
|
133
|
+
transform: [{ translateY: -(itemH / 2) }],
|
|
134
|
+
height: itemH,
|
|
135
|
+
borderTopWidth: 1,
|
|
136
|
+
borderBottomWidth: 1,
|
|
137
|
+
borderColor: '#f0f0f0',
|
|
138
|
+
width: '100%',
|
|
139
|
+
zIndex: 101
|
|
140
|
+
}]}></View>;
|
|
44
141
|
};
|
|
45
|
-
const
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
});
|
|
51
|
-
const defaultValue = (props.value || []).map((item, index) => {
|
|
52
|
-
if (item > subChildLength[index]) {
|
|
53
|
-
return subChildLength[index] - 1;
|
|
142
|
+
const renderSubChild = () => {
|
|
143
|
+
if (Array.isArray(children)) {
|
|
144
|
+
return children.map((item, index) => {
|
|
145
|
+
return cloneChild(item, index);
|
|
146
|
+
});
|
|
54
147
|
}
|
|
55
148
|
else {
|
|
56
|
-
return
|
|
149
|
+
return cloneChild(children, 0);
|
|
57
150
|
}
|
|
58
|
-
}
|
|
59
|
-
return (<
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
151
|
+
};
|
|
152
|
+
return (<View {...innerProps}>
|
|
153
|
+
{renderTopMask()}
|
|
154
|
+
<View style={[styles.wrapper]}>
|
|
155
|
+
{renderSubChild()}
|
|
156
|
+
</View>
|
|
157
|
+
{renderBottomMask()}
|
|
158
|
+
{!isSetW && renderLine()}
|
|
159
|
+
</View>);
|
|
66
160
|
});
|
|
67
161
|
_PickerView.displayName = 'mpx-picker-view';
|
|
68
162
|
export default _PickerView;
|
|
@@ -3,13 +3,13 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import { useRef, forwardRef, useContext } from 'react';
|
|
5
5
|
import { View } from 'react-native';
|
|
6
|
+
import { warn } from '@mpxjs/utils';
|
|
6
7
|
import { FormContext, RadioGroupContext } from './context';
|
|
7
8
|
import useInnerProps, { getCustomEvent } from './getInnerListeners';
|
|
8
9
|
import useNodesRef from './useNodesRef';
|
|
9
|
-
import {
|
|
10
|
+
import { useLayout, useTransformStyle, wrapChildren } from './utils';
|
|
10
11
|
const radioGroup = forwardRef((props, ref) => {
|
|
11
|
-
const { style = {}, 'enable-
|
|
12
|
-
const layoutRef = useRef({});
|
|
12
|
+
const { style = {}, 'enable-var': enableVar, 'external-var-context': externalVarContext, 'parent-font-size': parentFontSize, 'parent-width': parentWidth, 'parent-height': parentHeight, bindchange } = props;
|
|
13
13
|
const formContext = useContext(FormContext);
|
|
14
14
|
let formValuesMap;
|
|
15
15
|
if (formContext) {
|
|
@@ -18,19 +18,17 @@ const radioGroup = forwardRef((props, ref) => {
|
|
|
18
18
|
const groupValue = useRef({}).current;
|
|
19
19
|
const defaultStyle = {
|
|
20
20
|
flexDirection: 'row',
|
|
21
|
-
flexWrap: 'wrap'
|
|
22
|
-
...style
|
|
21
|
+
flexWrap: 'wrap'
|
|
23
22
|
};
|
|
24
|
-
const
|
|
25
|
-
defaultStyle
|
|
26
|
-
|
|
27
|
-
const onLayout = () => {
|
|
28
|
-
nodeRef.current?.measure((x, y, width, height, offsetLeft, offsetTop) => {
|
|
29
|
-
layoutRef.current = { x, y, width, height, offsetLeft, offsetTop };
|
|
30
|
-
});
|
|
23
|
+
const styleObj = {
|
|
24
|
+
...defaultStyle,
|
|
25
|
+
...style
|
|
31
26
|
};
|
|
27
|
+
const { hasSelfPercent, normalStyle, hasVarDec, varContextRef, setWidth, setHeight } = useTransformStyle(styleObj, { enableVar, externalVarContext, parentFontSize, parentWidth, parentHeight });
|
|
28
|
+
const { nodeRef } = useNodesRef(props, ref, { defaultStyle });
|
|
29
|
+
const { layoutRef, layoutStyle, layoutProps } = useLayout({ props, hasSelfPercent, setWidth, setHeight, nodeRef });
|
|
32
30
|
const getSelectionValue = () => {
|
|
33
|
-
for (
|
|
31
|
+
for (const key in groupValue) {
|
|
34
32
|
if (groupValue[key].checked) {
|
|
35
33
|
return key;
|
|
36
34
|
}
|
|
@@ -47,7 +45,7 @@ const radioGroup = forwardRef((props, ref) => {
|
|
|
47
45
|
};
|
|
48
46
|
if (formValuesMap) {
|
|
49
47
|
if (!props.name) {
|
|
50
|
-
|
|
48
|
+
warn('If a form component is used, the name attribute is required.');
|
|
51
49
|
}
|
|
52
50
|
else {
|
|
53
51
|
formValuesMap.set(props.name, { getValue, resetValue });
|
|
@@ -64,14 +62,17 @@ const radioGroup = forwardRef((props, ref) => {
|
|
|
64
62
|
};
|
|
65
63
|
const innerProps = useInnerProps(props, {
|
|
66
64
|
ref: nodeRef,
|
|
67
|
-
style:
|
|
68
|
-
...
|
|
69
|
-
}, [
|
|
65
|
+
style: { ...normalStyle, ...layoutStyle },
|
|
66
|
+
...layoutProps
|
|
67
|
+
}, [], {
|
|
70
68
|
layoutRef
|
|
71
69
|
});
|
|
72
70
|
return (<View {...innerProps}>
|
|
73
71
|
<RadioGroupContext.Provider value={{ groupValue, notifyChange }}>
|
|
74
|
-
{
|
|
72
|
+
{wrapChildren(props, {
|
|
73
|
+
hasVarDec,
|
|
74
|
+
varContext: varContextRef.current
|
|
75
|
+
})}
|
|
75
76
|
</RadioGroupContext.Provider>
|
|
76
77
|
</View>);
|
|
77
78
|
});
|