@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
|
@@ -11,9 +11,10 @@
|
|
|
11
11
|
* ✔ DEFAULT_SIZE
|
|
12
12
|
*/
|
|
13
13
|
import { useEffect, useMemo, useState, useRef, forwardRef } from 'react';
|
|
14
|
-
import { Image as RNImage, View, StyleSheet
|
|
14
|
+
import { Image as RNImage, View, StyleSheet } from 'react-native';
|
|
15
15
|
import useInnerProps, { getCustomEvent } from '../getInnerListeners';
|
|
16
16
|
import useNodesRef from '../useNodesRef';
|
|
17
|
+
import { useLayout, useTransformStyle } from '../utils';
|
|
17
18
|
const DEFAULT_IMAGE_WIDTH = 320;
|
|
18
19
|
const DEFAULT_IMAGE_HEIGHT = 240;
|
|
19
20
|
// const REMOTE_SVG_REGEXP = /https?:\/\/.*\.(?:svg)/i
|
|
@@ -35,7 +36,7 @@ const cropMode = [
|
|
|
35
36
|
'top left',
|
|
36
37
|
'top right',
|
|
37
38
|
'bottom left',
|
|
38
|
-
'bottom right'
|
|
39
|
+
'bottom right'
|
|
39
40
|
];
|
|
40
41
|
const ModeMap = new Map([
|
|
41
42
|
['scaleToFill', 'stretch'],
|
|
@@ -43,7 +44,7 @@ const ModeMap = new Map([
|
|
|
43
44
|
['aspectFill', 'cover'],
|
|
44
45
|
['widthFix', 'stretch'],
|
|
45
46
|
['heightFix', 'stretch'],
|
|
46
|
-
...cropMode.map(mode => [mode, 'stretch'])
|
|
47
|
+
...cropMode.map(mode => [mode, 'stretch'])
|
|
47
48
|
]);
|
|
48
49
|
const isNumber = (value) => typeof value === 'number';
|
|
49
50
|
const relativeCenteredSize = (viewSize, imageSize) => (viewSize - imageSize) / 2;
|
|
@@ -56,15 +57,26 @@ const relativeCenteredSize = (viewSize, imageSize) => (viewSize - imageSize) / 2
|
|
|
56
57
|
const Image = forwardRef((props, ref) => {
|
|
57
58
|
const { src = '', mode = 'scaleToFill',
|
|
58
59
|
// svg = false,
|
|
59
|
-
style = {}, 'enable-
|
|
60
|
-
const
|
|
60
|
+
style = {}, 'enable-var': enableVar, 'external-var-context': externalVarContext, 'parent-font-size': parentFontSize, 'parent-width': parentWidth, 'parent-height': parentHeight, bindload, binderror } = props;
|
|
61
|
+
const defaultStyle = {
|
|
62
|
+
width: DEFAULT_IMAGE_WIDTH,
|
|
63
|
+
height: DEFAULT_IMAGE_HEIGHT
|
|
64
|
+
};
|
|
65
|
+
const styleObj = {
|
|
66
|
+
...defaultStyle,
|
|
67
|
+
...style,
|
|
68
|
+
overflow: 'hidden'
|
|
69
|
+
};
|
|
61
70
|
const { nodeRef } = useNodesRef(props, ref, {
|
|
62
|
-
defaultStyle
|
|
63
|
-
width: DEFAULT_IMAGE_WIDTH,
|
|
64
|
-
height: DEFAULT_IMAGE_HEIGHT
|
|
65
|
-
}
|
|
71
|
+
defaultStyle
|
|
66
72
|
});
|
|
67
|
-
const
|
|
73
|
+
const onLayout = ({ nativeEvent: { layout: { width, height } } }) => {
|
|
74
|
+
setViewWidth(width);
|
|
75
|
+
setViewHeight(height);
|
|
76
|
+
};
|
|
77
|
+
const { normalStyle, hasSelfPercent, setWidth, setHeight } = useTransformStyle(styleObj, { enableVar, externalVarContext, parentFontSize, parentWidth, parentHeight });
|
|
78
|
+
const { layoutRef, layoutStyle, layoutProps } = useLayout({ props, hasSelfPercent, setWidth, setHeight, nodeRef, onLayout });
|
|
79
|
+
const { width, height } = normalStyle;
|
|
68
80
|
const preSrc = useRef();
|
|
69
81
|
const resizeMode = ModeMap.get(mode) || 'stretch';
|
|
70
82
|
const isWidthFixMode = mode === 'widthFix';
|
|
@@ -138,15 +150,6 @@ const Image = forwardRef((props, ref) => {
|
|
|
138
150
|
layoutRef
|
|
139
151
|
}, props));
|
|
140
152
|
};
|
|
141
|
-
const onViewLayout = ({ nativeEvent: { layout: { width, height }, }, }) => {
|
|
142
|
-
setViewWidth(width);
|
|
143
|
-
setViewHeight(height);
|
|
144
|
-
};
|
|
145
|
-
const onImageLayout = () => {
|
|
146
|
-
nodeRef.current?.measure((x, y, width, height, offsetLeft, offsetTop) => {
|
|
147
|
-
layoutRef.current = { x, y, width, height, offsetLeft, offsetTop };
|
|
148
|
-
});
|
|
149
|
-
};
|
|
150
153
|
useEffect(() => {
|
|
151
154
|
if (!isWidthFixMode && !isHeightFixMode && !isCropMode) {
|
|
152
155
|
setLoaded(true);
|
|
@@ -181,10 +184,14 @@ const Image = forwardRef((props, ref) => {
|
|
|
181
184
|
}, [isWidthFixMode, isHeightFixMode, isCropMode, src]);
|
|
182
185
|
const innerProps = useInnerProps(props, {
|
|
183
186
|
ref: nodeRef,
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
187
|
+
style: {
|
|
188
|
+
...normalStyle,
|
|
189
|
+
...layoutStyle,
|
|
190
|
+
...(isHeightFixMode && { width: fixedWidth }),
|
|
191
|
+
...(isWidthFixMode && { height: fixedHeight })
|
|
192
|
+
},
|
|
193
|
+
...layoutProps
|
|
194
|
+
}, [], {
|
|
188
195
|
layoutRef
|
|
189
196
|
});
|
|
190
197
|
// if (typeof src === 'string' && REMOTE_SVG_REGEXP.test(src)) {
|
|
@@ -205,17 +212,11 @@ const Image = forwardRef((props, ref) => {
|
|
|
205
212
|
// </Suspense>
|
|
206
213
|
// )
|
|
207
214
|
// }
|
|
208
|
-
return (<View
|
|
209
|
-
|
|
210
|
-
...style,
|
|
211
|
-
...(isHeightFixMode && { width: fixedWidth }),
|
|
212
|
-
...(isWidthFixMode && { height: fixedHeight }),
|
|
213
|
-
overflow: 'hidden',
|
|
214
|
-
}} onLayout={onViewLayout}>
|
|
215
|
-
{loaded && <RNImage {...innerProps} source={source} resizeMode={resizeMode} onLoad={onImageLoad} onError={onImageError} style={{
|
|
215
|
+
return (<View {...innerProps}>
|
|
216
|
+
{loaded && <RNImage source={source} resizeMode={resizeMode} onLoad={onImageLoad} onError={onImageError} style={{
|
|
216
217
|
...StyleSheet.absoluteFillObject,
|
|
217
|
-
width:
|
|
218
|
-
height:
|
|
218
|
+
width: isCropMode ? imageWidth : '100%',
|
|
219
|
+
height: isCropMode ? imageHeight : '100%',
|
|
219
220
|
...(isCropMode && cropModeStyle)
|
|
220
221
|
}}/>}
|
|
221
222
|
</View>);
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { SvgCssUri, WithLocalSvg } from 'react-native-svg/css';
|
|
2
2
|
const Svg = ({ local = false, src, style, width, height }) => {
|
|
3
|
-
return local
|
|
3
|
+
return local
|
|
4
|
+
? (<WithLocalSvg style={style} asset={src} width={width} height={height}/>)
|
|
5
|
+
: (<SvgCssUri style={style} uri={src} width={width} height={height}/>);
|
|
4
6
|
};
|
|
5
7
|
export default Svg;
|
|
@@ -39,7 +39,8 @@
|
|
|
39
39
|
*/
|
|
40
40
|
import { forwardRef, useMemo, useRef, useState, useContext, useEffect } from 'react';
|
|
41
41
|
import { Platform, TextInput } from 'react-native';
|
|
42
|
-
import {
|
|
42
|
+
import { warn } from '@mpxjs/utils';
|
|
43
|
+
import { parseInlineStyle, useUpdateEffect, useTransformStyle, useLayout } from './utils';
|
|
43
44
|
import useInnerProps, { getCustomEvent } from './getInnerListeners';
|
|
44
45
|
import useNodesRef from './useNodesRef';
|
|
45
46
|
import { FormContext } from './context';
|
|
@@ -49,29 +50,37 @@ const keyboardTypeMap = {
|
|
|
49
50
|
idcard: 'default',
|
|
50
51
|
digit: Platform.select({
|
|
51
52
|
ios: 'decimal-pad',
|
|
52
|
-
android: 'numeric'
|
|
53
|
-
}) || ''
|
|
53
|
+
android: 'numeric'
|
|
54
|
+
}) || ''
|
|
54
55
|
};
|
|
55
56
|
const Input = forwardRef((props, ref) => {
|
|
56
|
-
const { style = {}, type = 'text', value, password, 'placeholder-style': placeholderStyle, disabled, maxlength = 140, 'auto-focus': autoFocus, focus, 'confirm-type': confirmType = 'done', 'confirm-hold': confirmHold = false, cursor, 'cursor-color': cursorColor, 'selection-start': selectionStart = -1, 'selection-end': selectionEnd = -1, 'enable-
|
|
57
|
+
const { style = {}, type = 'text', value, password, 'placeholder-style': placeholderStyle, disabled, maxlength = 140, 'auto-focus': autoFocus, focus, 'confirm-type': confirmType = 'done', 'confirm-hold': confirmHold = false, cursor, 'cursor-color': cursorColor, 'selection-start': selectionStart = -1, 'selection-end': selectionEnd = -1, 'enable-var': enableVar, 'external-var-context': externalVarContext, 'parent-font-size': parentFontSize, 'parent-width': parentWidth, 'parent-height': parentHeight, bindinput, bindfocus, bindblur, bindconfirm, bindselectionchange,
|
|
57
58
|
// private
|
|
58
|
-
multiline, 'auto-height': autoHeight, bindlinechange
|
|
59
|
+
multiline, 'auto-height': autoHeight, bindlinechange } = props;
|
|
59
60
|
const formContext = useContext(FormContext);
|
|
60
61
|
let formValuesMap;
|
|
61
62
|
if (formContext) {
|
|
62
63
|
formValuesMap = formContext.formValuesMap;
|
|
63
64
|
}
|
|
64
|
-
const { nodeRef } = useNodesRef(props, ref);
|
|
65
65
|
const keyboardType = keyboardTypeMap[type];
|
|
66
66
|
const defaultValue = type === 'number' && value ? value + '' : value;
|
|
67
67
|
const placeholderTextColor = parseInlineStyle(placeholderStyle)?.color;
|
|
68
68
|
const textAlignVertical = multiline ? 'top' : 'auto';
|
|
69
|
-
const layoutRef = useRef({});
|
|
70
69
|
const tmpValue = useRef();
|
|
71
70
|
const cursorIndex = useRef(0);
|
|
72
71
|
const lineCount = useRef(0);
|
|
73
72
|
const [inputValue, setInputValue] = useState(defaultValue);
|
|
74
73
|
const [contentHeight, setContentHeight] = useState(0);
|
|
74
|
+
const styleObj = {
|
|
75
|
+
padding: 0,
|
|
76
|
+
...style,
|
|
77
|
+
...multiline && autoHeight && {
|
|
78
|
+
height: Math.max(style?.minHeight || 35, contentHeight)
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
const { hasSelfPercent, normalStyle, setWidth, setHeight } = useTransformStyle(styleObj, { enableVar, externalVarContext, parentFontSize, parentWidth, parentHeight });
|
|
82
|
+
const { nodeRef } = useNodesRef(props, ref);
|
|
83
|
+
const { layoutRef, layoutStyle, layoutProps } = useLayout({ props, hasSelfPercent, setWidth, setHeight, nodeRef });
|
|
75
84
|
useEffect(() => {
|
|
76
85
|
if (inputValue !== value) {
|
|
77
86
|
setInputValue(value);
|
|
@@ -88,7 +97,7 @@ const Input = forwardRef((props, ref) => {
|
|
|
88
97
|
const onTextInput = ({ nativeEvent }) => {
|
|
89
98
|
if (!bindinput && !bindblur)
|
|
90
99
|
return;
|
|
91
|
-
const { range: { start, end }, text
|
|
100
|
+
const { range: { start, end }, text } = nativeEvent;
|
|
92
101
|
cursorIndex.current = start < end ? start : start + text.length;
|
|
93
102
|
};
|
|
94
103
|
const onChange = (evt) => {
|
|
@@ -98,7 +107,7 @@ const Input = forwardRef((props, ref) => {
|
|
|
98
107
|
const result = bindinput(getCustomEvent('input', evt, {
|
|
99
108
|
detail: {
|
|
100
109
|
value: evt.nativeEvent.text,
|
|
101
|
-
cursor: cursorIndex.current
|
|
110
|
+
cursor: cursorIndex.current
|
|
102
111
|
},
|
|
103
112
|
layoutRef
|
|
104
113
|
}, props));
|
|
@@ -114,7 +123,7 @@ const Input = forwardRef((props, ref) => {
|
|
|
114
123
|
bindfocus &&
|
|
115
124
|
bindfocus(getCustomEvent('focus', evt, {
|
|
116
125
|
detail: {
|
|
117
|
-
value: tmpValue.current || ''
|
|
126
|
+
value: tmpValue.current || ''
|
|
118
127
|
},
|
|
119
128
|
layoutRef
|
|
120
129
|
}, props));
|
|
@@ -124,7 +133,7 @@ const Input = forwardRef((props, ref) => {
|
|
|
124
133
|
bindblur(getCustomEvent('blur', evt, {
|
|
125
134
|
detail: {
|
|
126
135
|
value: tmpValue.current || '',
|
|
127
|
-
cursor: cursorIndex.current
|
|
136
|
+
cursor: cursorIndex.current
|
|
128
137
|
},
|
|
129
138
|
layoutRef
|
|
130
139
|
}, props));
|
|
@@ -134,7 +143,7 @@ const Input = forwardRef((props, ref) => {
|
|
|
134
143
|
evt.nativeEvent.key === 'Enter' &&
|
|
135
144
|
bindconfirm(getCustomEvent('confirm', evt, {
|
|
136
145
|
detail: {
|
|
137
|
-
value: tmpValue.current || ''
|
|
146
|
+
value: tmpValue.current || ''
|
|
138
147
|
},
|
|
139
148
|
layoutRef
|
|
140
149
|
}, props));
|
|
@@ -144,7 +153,7 @@ const Input = forwardRef((props, ref) => {
|
|
|
144
153
|
multiline &&
|
|
145
154
|
bindconfirm(getCustomEvent('confirm', evt, {
|
|
146
155
|
detail: {
|
|
147
|
-
value: tmpValue.current || ''
|
|
156
|
+
value: tmpValue.current || ''
|
|
148
157
|
},
|
|
149
158
|
layoutRef
|
|
150
159
|
}, props));
|
|
@@ -161,7 +170,7 @@ const Input = forwardRef((props, ref) => {
|
|
|
161
170
|
detail: {
|
|
162
171
|
height,
|
|
163
172
|
lineHeight,
|
|
164
|
-
lineCount: lineCount.current
|
|
173
|
+
lineCount: lineCount.current
|
|
165
174
|
},
|
|
166
175
|
layoutRef
|
|
167
176
|
}, props));
|
|
@@ -173,16 +182,11 @@ const Input = forwardRef((props, ref) => {
|
|
|
173
182
|
bindselectionchange(getCustomEvent('selectionchange', evt, {
|
|
174
183
|
detail: {
|
|
175
184
|
selectionStart: evt.nativeEvent.selection.start,
|
|
176
|
-
selectionEnd: evt.nativeEvent.selection.end
|
|
185
|
+
selectionEnd: evt.nativeEvent.selection.end
|
|
177
186
|
},
|
|
178
187
|
layoutRef
|
|
179
188
|
}, props));
|
|
180
189
|
};
|
|
181
|
-
const onLayout = () => {
|
|
182
|
-
nodeRef.current?.measure((x, y, width, height, offsetLeft, offsetTop) => {
|
|
183
|
-
layoutRef.current = { x, y, width, height, offsetLeft, offsetTop };
|
|
184
|
-
});
|
|
185
|
-
};
|
|
186
190
|
const resetValue = () => {
|
|
187
191
|
setInputValue('');
|
|
188
192
|
};
|
|
@@ -191,7 +195,7 @@ const Input = forwardRef((props, ref) => {
|
|
|
191
195
|
};
|
|
192
196
|
if (formValuesMap) {
|
|
193
197
|
if (!props.name) {
|
|
194
|
-
|
|
198
|
+
warn('If a form component is used, the name attribute is required.');
|
|
195
199
|
}
|
|
196
200
|
else {
|
|
197
201
|
formValuesMap.set(props.name, { getValue, resetValue });
|
|
@@ -205,21 +209,21 @@ const Input = forwardRef((props, ref) => {
|
|
|
205
209
|
? nodeRef.current?.focus()
|
|
206
210
|
: nodeRef.current?.blur();
|
|
207
211
|
}, [focus]);
|
|
212
|
+
const composeStyle = { ...normalStyle, ...layoutStyle };
|
|
208
213
|
const innerProps = useInnerProps(props, {
|
|
209
214
|
ref: nodeRef,
|
|
210
|
-
|
|
211
|
-
}, [
|
|
212
|
-
'enable-offset'
|
|
213
|
-
], {
|
|
214
|
-
layoutRef
|
|
215
|
-
});
|
|
216
|
-
return (<TextInput {...innerProps} keyboardType={keyboardType} secureTextEntry={!!password} defaultValue={defaultValue} value={inputValue} maxLength={maxlength === -1 ? undefined : maxlength} editable={!disabled} autoFocus={!!autoFocus || !!focus} returnKeyType={confirmType} selection={selection} selectionColor={cursorColor} blurOnSubmit={!multiline && !confirmHold} underlineColorAndroid="rgba(0,0,0,0)" textAlignVertical={textAlignVertical} placeholderTextColor={placeholderTextColor} multiline={!!multiline} onTextInput={onTextInput} onChange={onChange} onFocus={onInputFocus} onBlur={onInputBlur} onKeyPress={onKeyPress} onSubmitEditing={onSubmitEditing} onContentSizeChange={onContentSizeChange} onSelectionChange={onSelectionChange} style={{
|
|
215
|
+
style: {
|
|
217
216
|
padding: 0,
|
|
218
|
-
...
|
|
217
|
+
...composeStyle,
|
|
219
218
|
...multiline && autoHeight && {
|
|
220
|
-
height: Math.max(
|
|
219
|
+
height: Math.max(composeStyle?.minHeight || 35, contentHeight)
|
|
221
220
|
}
|
|
222
|
-
}
|
|
221
|
+
},
|
|
222
|
+
...layoutProps
|
|
223
|
+
}, [], {
|
|
224
|
+
layoutRef
|
|
225
|
+
});
|
|
226
|
+
return (<TextInput {...innerProps} keyboardType={keyboardType} secureTextEntry={!!password} defaultValue={defaultValue} value={inputValue} maxLength={maxlength === -1 ? undefined : maxlength} editable={!disabled} autoFocus={!!autoFocus || !!focus} returnKeyType={confirmType} selection={selection} selectionColor={cursorColor} blurOnSubmit={!multiline && !confirmHold} underlineColorAndroid="rgba(0,0,0,0)" textAlignVertical={textAlignVertical} placeholderTextColor={placeholderTextColor} multiline={!!multiline} onTextInput={onTextInput} onChange={onChange} onFocus={onInputFocus} onBlur={onInputBlur} onKeyPress={onKeyPress} onSubmitEditing={onSubmitEditing} onContentSizeChange={onContentSizeChange} onSelectionChange={onSelectionChange}/>);
|
|
223
227
|
});
|
|
224
228
|
Input.displayName = 'mpx-input';
|
|
225
229
|
export default Input;
|
|
@@ -2,60 +2,52 @@
|
|
|
2
2
|
* ✘ for
|
|
3
3
|
*/
|
|
4
4
|
import { useRef, forwardRef } from 'react';
|
|
5
|
-
import { View
|
|
5
|
+
import { View } from 'react-native';
|
|
6
|
+
import { noop, warn } from '@mpxjs/utils';
|
|
6
7
|
import useInnerProps, { getCustomEvent } from './getInnerListeners';
|
|
7
8
|
import useNodesRef from './useNodesRef';
|
|
8
|
-
import {
|
|
9
|
+
import { splitProps, splitStyle, useLayout, useTransformStyle, wrapChildren } from './utils';
|
|
9
10
|
import { LabelContext } from './context';
|
|
10
|
-
const Label = forwardRef((
|
|
11
|
-
const {
|
|
12
|
-
const {
|
|
13
|
-
if (imageStyle) {
|
|
14
|
-
throwReactWarning('[Mpx runtime warn]: Label does not support background image-related styles!');
|
|
15
|
-
}
|
|
11
|
+
const Label = forwardRef((labelProps, ref) => {
|
|
12
|
+
const { textProps, innerProps: props = {} } = splitProps(labelProps);
|
|
13
|
+
const { style = {}, 'enable-var': enableVar, 'external-var-context': externalVarContext, 'parent-font-size': parentFontSize, 'parent-width': parentWidth, 'parent-height': parentHeight, bindtap } = props;
|
|
16
14
|
const defaultStyle = {
|
|
17
|
-
flexDirection: 'row'
|
|
15
|
+
flexDirection: 'row'
|
|
16
|
+
};
|
|
17
|
+
const styleObj = {
|
|
18
|
+
...defaultStyle,
|
|
19
|
+
...style
|
|
18
20
|
};
|
|
21
|
+
const { hasSelfPercent, normalStyle, hasVarDec, varContextRef, setWidth, setHeight } = useTransformStyle(styleObj, { enableVar, externalVarContext, parentFontSize, parentWidth, parentHeight });
|
|
22
|
+
const { nodeRef } = useNodesRef(props, ref, { defaultStyle });
|
|
23
|
+
const { layoutRef, layoutStyle, layoutProps } = useLayout({ props, hasSelfPercent, setWidth, setHeight, nodeRef });
|
|
24
|
+
const { textStyle, backgroundStyle, innerStyle } = splitStyle(normalStyle);
|
|
25
|
+
if (backgroundStyle) {
|
|
26
|
+
warn('Label does not support background image-related styles!');
|
|
27
|
+
}
|
|
19
28
|
const contextRef = useRef({
|
|
20
|
-
triggerChange:
|
|
29
|
+
triggerChange: noop
|
|
21
30
|
});
|
|
22
|
-
const layoutRef = useRef({});
|
|
23
|
-
const { nodeRef } = useNodesRef(props, ref, {
|
|
24
|
-
defaultStyle
|
|
25
|
-
});
|
|
26
|
-
const onLayout = () => {
|
|
27
|
-
nodeRef.current?.measure((x, y, width, height, offsetLeft, offsetTop) => {
|
|
28
|
-
layoutRef.current = { x, y, width, height, offsetLeft, offsetTop };
|
|
29
|
-
});
|
|
30
|
-
};
|
|
31
31
|
const onTap = (evt) => {
|
|
32
32
|
bindtap && bindtap(getCustomEvent('tap', evt, { layoutRef }, props));
|
|
33
33
|
contextRef.current.triggerChange?.(evt);
|
|
34
34
|
};
|
|
35
|
-
const wrapChildren = (children, textStyle) => {
|
|
36
|
-
const { textProps } = splitProps(props);
|
|
37
|
-
if (every(children, (child) => isText(child))) {
|
|
38
|
-
if (textStyle || textProps) {
|
|
39
|
-
children = <Text key='labelTextWrap' style={textStyle || {}} {...(textProps || {})}>{children}</Text>;
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
else {
|
|
43
|
-
if (textStyle)
|
|
44
|
-
throwReactWarning('[Mpx runtime warn]: Text style will be ignored unless every child of the Label is Text node!');
|
|
45
|
-
}
|
|
46
|
-
return children;
|
|
47
|
-
};
|
|
48
35
|
const innerProps = useInnerProps(props, {
|
|
49
36
|
ref: nodeRef,
|
|
50
|
-
style: { ...
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
}, [
|
|
37
|
+
style: { ...innerStyle, ...layoutStyle },
|
|
38
|
+
...layoutProps,
|
|
39
|
+
bindtap: onTap
|
|
40
|
+
}, [], {
|
|
54
41
|
layoutRef
|
|
55
42
|
});
|
|
56
43
|
return <View {...innerProps}>
|
|
57
44
|
<LabelContext.Provider value={contextRef}>
|
|
58
|
-
{wrapChildren(
|
|
45
|
+
{wrapChildren(props, {
|
|
46
|
+
hasVarDec,
|
|
47
|
+
varContext: varContextRef.current,
|
|
48
|
+
textStyle,
|
|
49
|
+
textProps
|
|
50
|
+
})}
|
|
59
51
|
</LabelContext.Provider>
|
|
60
52
|
</View>;
|
|
61
53
|
});
|
|
@@ -2,43 +2,38 @@
|
|
|
2
2
|
* ✘ scale-area
|
|
3
3
|
*/
|
|
4
4
|
import { View } from 'react-native';
|
|
5
|
-
import { useState, useEffect,
|
|
5
|
+
import { useState, useEffect, forwardRef } from 'react';
|
|
6
6
|
import useNodesRef from './useNodesRef';
|
|
7
7
|
import useInnerProps from './getInnerListeners';
|
|
8
8
|
import { MovableAreaContext } from './context';
|
|
9
|
+
import { useTransformStyle, wrapChildren, useLayout } from './utils';
|
|
9
10
|
const _MovableArea = forwardRef((props, ref) => {
|
|
10
|
-
const {
|
|
11
|
+
const { style = {}, width = 10, height = 10, 'enable-var': enableVar, 'external-var-context': externalVarContext, 'parent-font-size': parentFontSize, 'parent-width': parentWidth, 'parent-height': parentHeight } = props;
|
|
11
12
|
const [areaWidth, setAreaWidth] = useState(0);
|
|
12
13
|
const [areaHeight, setAreaHeight] = useState(0);
|
|
13
|
-
const layoutRef = useRef({});
|
|
14
14
|
useEffect(() => {
|
|
15
15
|
setAreaWidth(width);
|
|
16
16
|
setAreaHeight(height);
|
|
17
17
|
}, [width, height]);
|
|
18
|
+
const { hasSelfPercent, normalStyle, hasVarDec, varContextRef, setWidth, setHeight } = useTransformStyle(style, { enableVar, externalVarContext, parentFontSize, parentWidth, parentHeight });
|
|
18
19
|
const { nodeRef: movableViewRef } = useNodesRef(props, ref);
|
|
19
20
|
const onLayout = (e) => {
|
|
20
21
|
const { width = 10, height = 10 } = e.nativeEvent.layout;
|
|
21
22
|
setAreaWidth(width);
|
|
22
23
|
setAreaHeight(height);
|
|
23
|
-
movableViewRef.current?.measure((x, y, width, height, offsetLeft, offsetTop) => {
|
|
24
|
-
layoutRef.current = { x, y, width, height, offsetLeft, offsetTop };
|
|
25
|
-
});
|
|
26
24
|
};
|
|
25
|
+
const { layoutRef, layoutStyle, layoutProps } = useLayout({ props, hasSelfPercent, setWidth, setHeight, nodeRef: movableViewRef, onLayout });
|
|
27
26
|
const innerProps = useInnerProps(props, {
|
|
27
|
+
style: { height: areaHeight, width: areaWidth, overflow: 'hidden', ...normalStyle, ...layoutStyle },
|
|
28
28
|
ref: movableViewRef,
|
|
29
|
-
|
|
30
|
-
}, [
|
|
31
|
-
'children',
|
|
32
|
-
'style',
|
|
33
|
-
], { layoutRef });
|
|
29
|
+
...layoutProps
|
|
30
|
+
}, [], { layoutRef });
|
|
34
31
|
return (<MovableAreaContext.Provider value={{ height: areaHeight, width: areaWidth }}>
|
|
35
|
-
<View {...innerProps}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
}}>
|
|
41
|
-
{children}
|
|
32
|
+
<View {...innerProps}>
|
|
33
|
+
{wrapChildren(props, {
|
|
34
|
+
hasVarDec,
|
|
35
|
+
varContext: varContextRef.current
|
|
36
|
+
})}
|
|
42
37
|
</View>
|
|
43
38
|
</MovableAreaContext.Provider>);
|
|
44
39
|
});
|
|
@@ -27,7 +27,7 @@ const styles = StyleSheet.create({
|
|
|
27
27
|
position: 'absolute',
|
|
28
28
|
left: 0,
|
|
29
29
|
top: 0
|
|
30
|
-
}
|
|
30
|
+
}
|
|
31
31
|
});
|
|
32
32
|
const _MovableView = forwardRef((props, ref) => {
|
|
33
33
|
const { children, friction = 7, scale = false, direction = 'none', x = 0, y = 0, style = {}, 'scale-min': scaleMin = 0.1, 'scale-max': scaleMax = 10, 'scale-value': originScaleValue = 1, bindscale, bindchange } = props;
|
|
@@ -45,9 +45,9 @@ const _MovableView = forwardRef((props, ref) => {
|
|
|
45
45
|
defaultStyle: styles.container
|
|
46
46
|
});
|
|
47
47
|
let panResponder = {};
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
48
|
+
const isFirstTouch = useRef(true);
|
|
49
|
+
const touchEvent = useRef('');
|
|
50
|
+
const initialDistance = useRef(0);
|
|
51
51
|
propsRef.current = props;
|
|
52
52
|
useEffect(() => {
|
|
53
53
|
if (scale && (scaleValue.current._value !== originScaleValue)) {
|
|
@@ -55,7 +55,7 @@ const _MovableView = forwardRef((props, ref) => {
|
|
|
55
55
|
Animated.spring(scaleValue.current, {
|
|
56
56
|
toValue: clampedScale,
|
|
57
57
|
friction,
|
|
58
|
-
useNativeDriver: false
|
|
58
|
+
useNativeDriver: false
|
|
59
59
|
}).start(() => {
|
|
60
60
|
bindscale && bindscale(getCustomEvent('scale', {}, {
|
|
61
61
|
detail: {
|
|
@@ -186,7 +186,7 @@ const _MovableView = forwardRef((props, ref) => {
|
|
|
186
186
|
null,
|
|
187
187
|
{
|
|
188
188
|
dx: direction === 'all' || direction === 'horizontal' ? pan.current.x : new Animated.Value(0),
|
|
189
|
-
dy: direction === 'all' || direction === 'vertical' ? pan.current.y : new Animated.Value(0)
|
|
189
|
+
dy: direction === 'all' || direction === 'vertical' ? pan.current.y : new Animated.Value(0)
|
|
190
190
|
}
|
|
191
191
|
], {
|
|
192
192
|
useNativeDriver: false
|
|
@@ -316,8 +316,8 @@ const _MovableView = forwardRef((props, ref) => {
|
|
|
316
316
|
ref: nodeRef,
|
|
317
317
|
...panResponder.panHandlers,
|
|
318
318
|
onLayout,
|
|
319
|
-
...(hasTouchmove() ? {
|
|
320
|
-
...(hasCatchTouchmove() ? {
|
|
319
|
+
...(hasTouchmove() ? { bindtouchmove: onTouchMove } : {}),
|
|
320
|
+
...(hasCatchTouchmove() ? { catchtouchmove: onCatchTouchMove } : {})
|
|
321
321
|
}, [
|
|
322
322
|
'children',
|
|
323
323
|
'style',
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { View } from 'react-native';
|
|
2
2
|
import React, { forwardRef, useRef, useContext, useState } from 'react';
|
|
3
|
+
import { warn } from '@mpxjs/utils';
|
|
3
4
|
import useInnerProps, { getCustomEvent } from '../getInnerListeners';
|
|
4
5
|
import useNodesRef from '../useNodesRef'; // 引入辅助函数
|
|
5
6
|
import Selector from './selector';
|
|
@@ -8,7 +9,6 @@ import DateSelector from './date';
|
|
|
8
9
|
import MultiSelector from './multiSelector';
|
|
9
10
|
import RegionSelector from './region';
|
|
10
11
|
import { FormContext } from '../context';
|
|
11
|
-
import { throwReactWarning } from '../utils';
|
|
12
12
|
/**
|
|
13
13
|
* ✔ mode
|
|
14
14
|
* ✔ disabled
|
|
@@ -29,7 +29,7 @@ import { throwReactWarning } from '../utils';
|
|
|
29
29
|
*/
|
|
30
30
|
const _Picker = forwardRef((props, ref) => {
|
|
31
31
|
const { mode = 'selector', value, bindcancel, bindchange, children, bindcolumnchange } = props;
|
|
32
|
-
|
|
32
|
+
const innerLayout = useRef({});
|
|
33
33
|
const { nodeRef } = useNodesRef(props, ref, {});
|
|
34
34
|
const innerProps = useInnerProps(props, {
|
|
35
35
|
ref: nodeRef
|
|
@@ -57,7 +57,7 @@ const _Picker = forwardRef((props, ref) => {
|
|
|
57
57
|
};
|
|
58
58
|
if (formValuesMap) {
|
|
59
59
|
if (!props.name) {
|
|
60
|
-
|
|
60
|
+
warn('If a form component is used, the name attribute is required.');
|
|
61
61
|
}
|
|
62
62
|
else {
|
|
63
63
|
formValuesMap.set(props.name, { getValue, resetValue });
|
|
@@ -88,26 +88,26 @@ const _Picker = forwardRef((props, ref) => {
|
|
|
88
88
|
const selectorProps = {
|
|
89
89
|
...commonProps,
|
|
90
90
|
value: pickerValue,
|
|
91
|
-
range: props
|
|
91
|
+
range: props.range,
|
|
92
92
|
'range-key': props['range-key']
|
|
93
93
|
};
|
|
94
94
|
const multiProps = {
|
|
95
95
|
...commonProps,
|
|
96
96
|
value: pickerValue,
|
|
97
|
-
range: props
|
|
97
|
+
range: props.range,
|
|
98
98
|
'range-key': props['range-key']
|
|
99
99
|
};
|
|
100
100
|
const timeProps = {
|
|
101
101
|
...commonProps,
|
|
102
102
|
value: pickerValue,
|
|
103
|
-
start: props
|
|
104
|
-
end: props
|
|
103
|
+
start: props.start,
|
|
104
|
+
end: props.end
|
|
105
105
|
};
|
|
106
106
|
const dateProps = {
|
|
107
107
|
...commonProps,
|
|
108
108
|
value: pickerValue,
|
|
109
|
-
start: props
|
|
110
|
-
end: props
|
|
109
|
+
start: props.start,
|
|
110
|
+
end: props.end,
|
|
111
111
|
fileds: props.fields || 'day'
|
|
112
112
|
};
|
|
113
113
|
const regionProps = {
|
|
@@ -17,7 +17,7 @@ function formatRangeFun(range = [], rangeKey) {
|
|
|
17
17
|
});
|
|
18
18
|
let tmp = result;
|
|
19
19
|
for (let i = 1; i < range.length; i++) {
|
|
20
|
-
|
|
20
|
+
const child = Array.isArray(range[i]) ? range[i] : [];
|
|
21
21
|
const nextColData = child.map(item => {
|
|
22
22
|
return convertToObj(item, rangeKey);
|
|
23
23
|
});
|
|
@@ -44,7 +44,7 @@ function getIndexByValues(range = [], value = []) {
|
|
|
44
44
|
function getInnerValueByIndex(range = [], value = []) {
|
|
45
45
|
let tmp = range;
|
|
46
46
|
return value.map(v => {
|
|
47
|
-
|
|
47
|
+
const current = tmp[v].value;
|
|
48
48
|
tmp = tmp[v].children;
|
|
49
49
|
return current;
|
|
50
50
|
});
|
|
@@ -60,6 +60,7 @@ function getColumnIndexByValue(range = [], column, value = []) {
|
|
|
60
60
|
if (ritem.value === item) {
|
|
61
61
|
changeIndex = rindex;
|
|
62
62
|
}
|
|
63
|
+
return ritem;
|
|
63
64
|
});
|
|
64
65
|
}
|
|
65
66
|
else {
|
|
@@ -67,16 +68,18 @@ function getColumnIndexByValue(range = [], column, value = []) {
|
|
|
67
68
|
if (citem.value === item) {
|
|
68
69
|
tmpRange = citem.children;
|
|
69
70
|
}
|
|
71
|
+
return citem;
|
|
70
72
|
});
|
|
71
73
|
curRange = tmpRange;
|
|
72
74
|
}
|
|
75
|
+
return item;
|
|
73
76
|
});
|
|
74
77
|
return changeIndex;
|
|
75
78
|
}
|
|
76
79
|
const _MultiSelectorPicker = forwardRef((props, ref) => {
|
|
77
80
|
const { range, value, disabled, bindchange, bindcancel, children, bindcolumnchange } = props;
|
|
78
|
-
|
|
79
|
-
|
|
81
|
+
const formatRange = formatRangeFun(range, props['range-key']);
|
|
82
|
+
const initValue = getInnerValueByIndex(formatRange, value);
|
|
80
83
|
// 选中的索引值
|
|
81
84
|
const [selected, setSelected] = useState(initValue);
|
|
82
85
|
// range数据源
|