@mpxjs/webpack-plugin 2.10.3-beta.4 → 2.10.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +433 -0
- package/lib/index.js +1 -1
- package/lib/platform/template/wx/component-config/input.js +1 -1
- package/lib/platform/template/wx/component-config/text.js +18 -3
- package/lib/platform/template/wx/component-config/view.js +0 -2
- package/lib/platform/template/wx/index.js +41 -93
- package/lib/react/processScript.js +1 -18
- package/lib/runtime/components/react/dist/event.config.js +1 -0
- package/lib/runtime/components/react/dist/getInnerListeners.js +18 -7
- package/lib/runtime/components/react/dist/mpx-canvas/index.jsx +1 -1
- package/lib/runtime/components/react/dist/mpx-inline-text.jsx +11 -0
- package/lib/runtime/components/react/dist/mpx-input.jsx +3 -6
- package/lib/runtime/components/react/dist/mpx-keyboard-avoiding-view.jsx +2 -2
- package/lib/runtime/components/react/dist/mpx-picker/date.jsx +194 -68
- package/lib/runtime/components/react/dist/mpx-picker/dateData.js +17 -0
- package/lib/runtime/components/react/dist/mpx-picker/index.jsx +178 -96
- package/lib/runtime/components/react/dist/mpx-picker/multiSelector.jsx +79 -139
- package/lib/runtime/components/react/dist/mpx-picker/region.jsx +190 -90
- package/lib/runtime/components/react/dist/mpx-picker/selector.jsx +60 -75
- package/lib/runtime/components/react/dist/mpx-picker/time.jsx +100 -228
- package/lib/runtime/components/react/dist/{mpx-picker-view.jsx → mpx-picker-view/index.jsx} +3 -3
- package/lib/runtime/components/react/dist/{mpx-picker-view-column.jsx → mpx-picker-view-column/index.jsx} +64 -16
- package/lib/runtime/components/react/dist/{mpx-picker-view-column-item.jsx → mpx-picker-view-column/pickerViewColumnItem.jsx} +8 -5
- package/lib/runtime/components/react/dist/{pickerFaces.js → mpx-picker-view-column/pickerViewFaces.js} +6 -0
- package/lib/runtime/components/react/dist/mpx-popup/index.jsx +61 -0
- package/lib/runtime/components/react/dist/mpx-popup/popupBase.jsx +92 -0
- package/lib/runtime/components/react/dist/mpx-scroll-view.jsx +192 -25
- package/lib/runtime/components/react/dist/mpx-simple-text.jsx +8 -7
- package/lib/runtime/components/react/dist/mpx-simple-view.jsx +11 -15
- package/lib/runtime/components/react/dist/mpx-swiper.jsx +2 -2
- package/lib/runtime/components/react/dist/mpx-video.jsx +3 -3
- package/lib/runtime/components/react/dist/mpx-web-view.jsx +4 -4
- package/lib/runtime/components/react/dist/utils.jsx +1 -1
- package/lib/runtime/components/react/event.config.ts +2 -0
- package/lib/runtime/components/react/getInnerListeners.ts +28 -25
- package/lib/runtime/components/react/mpx-canvas/index.tsx +2 -2
- package/lib/runtime/components/react/mpx-inline-text.tsx +18 -0
- package/lib/runtime/components/react/mpx-input.tsx +2 -6
- package/lib/runtime/components/react/mpx-keyboard-avoiding-view.tsx +1 -1
- package/lib/runtime/components/react/mpx-picker/date.tsx +226 -69
- package/lib/runtime/components/react/mpx-picker/dateData.ts +22 -0
- package/lib/runtime/components/react/mpx-picker/index.tsx +239 -118
- package/lib/runtime/components/react/mpx-picker/multiSelector.tsx +96 -139
- package/lib/runtime/components/react/mpx-picker/region.tsx +217 -89
- package/lib/runtime/components/react/mpx-picker/selector.tsx +75 -80
- package/lib/runtime/components/react/mpx-picker/time.tsx +119 -236
- package/lib/runtime/components/react/mpx-picker/type.ts +85 -71
- package/lib/runtime/components/react/{mpx-picker-view.tsx → mpx-picker-view/index.tsx} +7 -7
- package/lib/runtime/components/react/{mpx-picker-view-column.tsx → mpx-picker-view-column/index.tsx} +70 -19
- package/lib/runtime/components/react/{mpx-picker-view-column-item.tsx → mpx-picker-view-column/pickerViewColumnItem.tsx} +8 -5
- package/lib/runtime/components/react/{pickerFaces.ts → mpx-picker-view-column/pickerViewFaces.ts} +7 -0
- package/lib/runtime/components/react/mpx-popup/index.tsx +86 -0
- package/lib/runtime/components/react/mpx-popup/popupBase.tsx +130 -0
- package/lib/runtime/components/react/mpx-scroll-view.tsx +249 -43
- package/lib/runtime/components/react/mpx-simple-text.tsx +10 -8
- package/lib/runtime/components/react/mpx-simple-view.tsx +11 -16
- package/lib/runtime/components/react/mpx-swiper.tsx +2 -4
- package/lib/runtime/components/react/mpx-video.tsx +2 -2
- package/lib/runtime/components/react/mpx-web-view.tsx +4 -4
- package/lib/runtime/components/react/types/getInnerListeners.d.ts +5 -1
- package/lib/runtime/components/react/utils.tsx +1 -1
- package/lib/runtime/components/web/mpx-input.vue +1 -1
- package/lib/runtime/stringify.wxs +2 -2
- package/lib/template-compiler/compiler.js +7 -7
- package/package.json +4 -5
- /package/lib/runtime/components/react/dist/{pickerVIewContext.js → mpx-picker-view/pickerVIewContext.js} +0 -0
- /package/lib/runtime/components/react/dist/{pickerViewIndicator.jsx → mpx-picker-view-column/pickerViewIndicator.jsx} +0 -0
- /package/lib/runtime/components/react/dist/{pickerViewMask.jsx → mpx-picker-view-column/pickerViewMask.jsx} +0 -0
- /package/lib/runtime/components/react/{pickerVIewContext.ts → mpx-picker-view/pickerVIewContext.ts} +0 -0
- /package/lib/runtime/components/react/{pickerViewIndicator.tsx → mpx-picker-view-column/pickerViewIndicator.tsx} +0 -0
- /package/lib/runtime/components/react/{pickerViewMask.tsx → mpx-picker-view-column/pickerViewMask.tsx} +0 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { useRef, useMemo } from 'react';
|
|
2
2
|
import { hasOwn, collectDataset } from '@mpxjs/utils';
|
|
3
3
|
import { omit, extendObject, useNavigation } from './utils';
|
|
4
|
-
import eventConfigMap, { TAP_EVENTS } from './event.config';
|
|
4
|
+
import eventConfigMap, { TAP_EVENTS, LONGPRESS_EVENTS } from './event.config';
|
|
5
5
|
const globalEventState = {
|
|
6
6
|
needPress: true
|
|
7
7
|
};
|
|
@@ -74,8 +74,23 @@ function handleEmitEvent(events, type, oe, propsRef, config, navigation) {
|
|
|
74
74
|
events.forEach((event) => {
|
|
75
75
|
if (propsRef.current[event]) {
|
|
76
76
|
const match = /^(catch|capture-catch):?(.*?)(?:\.(.*))?$/.exec(event);
|
|
77
|
+
// 检查是否已经被上层的 catch 阻止
|
|
78
|
+
if ((type === 'tap' || type === 'longpress') && oe._stoppedEventTypes?.has(type)) {
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
77
81
|
if (match) {
|
|
78
|
-
|
|
82
|
+
const eventBase = match[2] || '';
|
|
83
|
+
if (eventBase === 'tap' || eventBase === 'longpress') {
|
|
84
|
+
// 为 tap、longpress 添加标记,影响后续的冒泡
|
|
85
|
+
if (!oe._stoppedEventTypes) {
|
|
86
|
+
oe._stoppedEventTypes = new Set();
|
|
87
|
+
}
|
|
88
|
+
oe._stoppedEventTypes.add(eventBase);
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
// 原生 touch 事件使用 stopPropagation
|
|
92
|
+
oe.stopPropagation();
|
|
93
|
+
}
|
|
79
94
|
}
|
|
80
95
|
propsRef.current[event](getTouchEvent(type, oe, propsRef.current, config, navigation));
|
|
81
96
|
}
|
|
@@ -116,11 +131,7 @@ function handleTouchstart(e, type, ref, propsRef, config, navigation) {
|
|
|
116
131
|
const currentTouchEvent = type === 'bubble' ? bubbleTouchEvent : captureTouchEvent;
|
|
117
132
|
const currentPressEvent = type === 'bubble' ? bubblePressEvent : capturePressEvent;
|
|
118
133
|
handleEmitEvent(currentTouchEvent, 'touchstart', e, propsRef, config, navigation);
|
|
119
|
-
|
|
120
|
-
if (catchlongpress ||
|
|
121
|
-
bindlongpress ||
|
|
122
|
-
captureCatchlongpress ||
|
|
123
|
-
captureBindlongpress) {
|
|
134
|
+
if (LONGPRESS_EVENTS.some(eventName => propsRef.current[eventName])) {
|
|
124
135
|
ref.current.startTimer[type] = setTimeout(() => {
|
|
125
136
|
// 只要触发过longpress, 全局就不再触发tap
|
|
126
137
|
globalEventState.needPress = false;
|
|
@@ -193,7 +193,7 @@ const _Canvas = forwardRef((props = {}, ref) => {
|
|
|
193
193
|
node: canvasRef.current,
|
|
194
194
|
context: context2D
|
|
195
195
|
});
|
|
196
|
-
if (
|
|
196
|
+
if (__mpx_mode__ !== 'ios') {
|
|
197
197
|
const isAndroid9 = Platform.Version >= 28;
|
|
198
198
|
return createElement(View, innerProps, createElement(WebView, {
|
|
199
199
|
ref: (element) => {
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Text } from 'react-native';
|
|
2
|
+
import { createElement } from 'react';
|
|
3
|
+
import { extendObject } from './utils';
|
|
4
|
+
const InlineText = (props) => {
|
|
5
|
+
const { allowFontScaling = false } = props;
|
|
6
|
+
return createElement(Text, extendObject({}, props, {
|
|
7
|
+
allowFontScaling
|
|
8
|
+
}));
|
|
9
|
+
};
|
|
10
|
+
InlineText.displayName = 'MpxInlineText';
|
|
11
|
+
export default InlineText;
|
|
@@ -38,9 +38,9 @@
|
|
|
38
38
|
* ✘ bind:onkeyboardheightchange
|
|
39
39
|
*/
|
|
40
40
|
import { forwardRef, useRef, useState, useContext, useEffect, createElement } from 'react';
|
|
41
|
-
import {
|
|
41
|
+
import { TextInput } from 'react-native';
|
|
42
42
|
import { warn } from '@mpxjs/utils';
|
|
43
|
-
import { useUpdateEffect, useTransformStyle, useLayout, extendObject } from './utils';
|
|
43
|
+
import { useUpdateEffect, useTransformStyle, useLayout, extendObject, isIOS } from './utils';
|
|
44
44
|
import useInnerProps, { getCustomEvent } from './getInnerListeners';
|
|
45
45
|
import useNodesRef from './useNodesRef';
|
|
46
46
|
import { FormContext, KeyboardAvoidContext } from './context';
|
|
@@ -48,10 +48,7 @@ const keyboardTypeMap = {
|
|
|
48
48
|
text: 'default',
|
|
49
49
|
number: 'numeric',
|
|
50
50
|
idcard: 'default',
|
|
51
|
-
digit:
|
|
52
|
-
ios: 'decimal-pad',
|
|
53
|
-
android: 'numeric'
|
|
54
|
-
}) || ''
|
|
51
|
+
digit: isIOS ? 'decimal-pad' : 'numeric'
|
|
55
52
|
};
|
|
56
53
|
const Input = forwardRef((props, ref) => {
|
|
57
54
|
const { style = {}, allowFontScaling = false, type = 'text', value, password, 'placeholder-style': placeholderStyle = {}, disabled, maxlength = 140, 'cursor-spacing': cursorSpacing = 0, '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, 'adjust-position': adjustPosition = true, bindinput, bindfocus, bindblur, bindconfirm, bindselectionchange,
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import React, { useContext, useEffect, useMemo } from 'react';
|
|
2
|
-
import { Keyboard,
|
|
2
|
+
import { Keyboard, View } from 'react-native';
|
|
3
3
|
import Animated, { useSharedValue, useAnimatedStyle, withTiming, Easing } from 'react-native-reanimated';
|
|
4
4
|
import { GestureDetector, Gesture } from 'react-native-gesture-handler';
|
|
5
5
|
import { KeyboardAvoidContext } from './context';
|
|
6
|
+
import { isIOS } from './utils';
|
|
6
7
|
const KeyboardAvoidingView = ({ children, style, contentContainerStyle }) => {
|
|
7
|
-
const isIOS = Platform.OS === 'ios';
|
|
8
8
|
const duration = isIOS ? 250 : 300;
|
|
9
9
|
const easing = isIOS ? Easing.inOut(Easing.ease) : Easing.out(Easing.quad);
|
|
10
10
|
const offset = useSharedValue(0);
|
|
@@ -1,74 +1,200 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
1
|
+
import React, { forwardRef, useCallback, useMemo, useRef, useState, useEffect, useImperativeHandle } from 'react';
|
|
2
|
+
import { StyleSheet, Text } from 'react-native';
|
|
3
|
+
import MpxPickerView from '../mpx-picker-view';
|
|
4
|
+
import MpxPickerViewColumn from '../mpx-picker-view-column';
|
|
5
|
+
import { useUpdateEffect } from '../utils';
|
|
6
|
+
import { years, months, daysInMonth, wrapDate, daysInMonthLength, START_YEAR, END_YEAR } from './dateData';
|
|
7
|
+
const START_DATE = `${START_YEAR}-01-01`;
|
|
8
|
+
const END_DATE = `${END_YEAR}-12-31`;
|
|
9
|
+
const START_DATE_ARR = [START_YEAR, 1, 1];
|
|
10
|
+
const END_DATE_ARR = [END_YEAR, 12, 31];
|
|
11
|
+
const styles = StyleSheet.create({
|
|
12
|
+
pickerContainer: {
|
|
13
|
+
height: 240,
|
|
14
|
+
paddingHorizontal: 10,
|
|
15
|
+
borderTopLeftRadius: 10,
|
|
16
|
+
borderTopRightRadius: 10
|
|
17
|
+
},
|
|
18
|
+
pickerIndicator: {
|
|
19
|
+
height: 45
|
|
20
|
+
},
|
|
21
|
+
pickerItem: {
|
|
22
|
+
fontSize: 16,
|
|
23
|
+
lineHeight: 45,
|
|
24
|
+
textAlign: 'center'
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
const getColumnLength = (fields = 'day') => {
|
|
28
|
+
return fields === 'year' ? 1 : fields === 'month' ? 2 : 3;
|
|
29
|
+
};
|
|
30
|
+
const compareDateStr = (date1, date2) => {
|
|
31
|
+
const [y1 = START_YEAR, m1 = 0, d1 = 0] = typeof date1 === 'string' ? date1.split('-').map(Number) : date1;
|
|
32
|
+
const [y2 = START_YEAR, m2 = 0, d2 = 0] = typeof date2 === 'string' ? date2.split('-').map(Number) : date2;
|
|
33
|
+
const num1 = y1 * 10000 + m1 * 100 + d1;
|
|
34
|
+
const num2 = y2 * 10000 + m2 * 100 + d2;
|
|
35
|
+
if (num1 === num2) {
|
|
36
|
+
return 0;
|
|
37
|
+
}
|
|
38
|
+
return num1 > num2 ? 1 : -1;
|
|
39
|
+
};
|
|
40
|
+
const getDateArr = (date) => {
|
|
41
|
+
const [y, m, d] = typeof date === 'string' ? date.split('-').map(Number) : date;
|
|
42
|
+
return [y || 0, m || 0, d || 0];
|
|
43
|
+
};
|
|
44
|
+
const calibrateDate = (date, start, end) => {
|
|
45
|
+
let startArr = getDateArr(start);
|
|
46
|
+
let endArr = getDateArr(end);
|
|
47
|
+
let dateArr = getDateArr(date);
|
|
48
|
+
if (compareDateStr(startArr, endArr) > 0) {
|
|
49
|
+
startArr = START_DATE_ARR;
|
|
50
|
+
}
|
|
51
|
+
if (compareDateStr(endArr, startArr) < 0) {
|
|
52
|
+
endArr = END_DATE_ARR;
|
|
53
|
+
}
|
|
54
|
+
if (compareDateStr(start, end) > 0) {
|
|
55
|
+
startArr = START_DATE_ARR;
|
|
56
|
+
endArr = END_DATE_ARR;
|
|
57
|
+
}
|
|
58
|
+
if (compareDateStr(dateArr, endArr) > 0) {
|
|
59
|
+
dateArr = endArr;
|
|
60
|
+
}
|
|
61
|
+
if (compareDateStr(dateArr, startArr) < 0) {
|
|
62
|
+
dateArr = startArr;
|
|
63
|
+
}
|
|
64
|
+
return dateArr;
|
|
65
|
+
};
|
|
66
|
+
const initDateStr2Arr = (dateStr, start, end) => {
|
|
67
|
+
if (!dateStr) {
|
|
68
|
+
const today = new Date();
|
|
69
|
+
const todayYear = today.getFullYear();
|
|
70
|
+
const todayMonth = today.getMonth() + 1;
|
|
71
|
+
const todayDay = today.getDate();
|
|
72
|
+
dateStr = [todayYear, todayMonth, todayDay];
|
|
73
|
+
}
|
|
74
|
+
const [y, m, d] = getDateArr(dateStr);
|
|
75
|
+
const year = Math.min(Math.max(START_YEAR, y), END_YEAR);
|
|
76
|
+
const month = Math.min(Math.max(1, m), 12);
|
|
77
|
+
const day = Math.min(Math.max(1, d), daysInMonthLength(year, month));
|
|
78
|
+
const res = [year, month, day];
|
|
79
|
+
return calibrateDate(res, start, end);
|
|
80
|
+
};
|
|
81
|
+
const valueStr2Obj = (_value = '', // eg: 2025-2-12
|
|
82
|
+
limit, start, end) => {
|
|
83
|
+
const [y, m, d] = initDateStr2Arr(_value, start, end);
|
|
84
|
+
const ans = {
|
|
85
|
+
indexArr: [y - START_YEAR],
|
|
86
|
+
rangeArr: [years]
|
|
87
|
+
};
|
|
88
|
+
if (limit === 2) {
|
|
89
|
+
ans.indexArr.push(m - 1);
|
|
90
|
+
ans.rangeArr.push(months);
|
|
91
|
+
}
|
|
92
|
+
else if (limit === 3) {
|
|
93
|
+
const days = daysInMonth(y, m);
|
|
94
|
+
ans.indexArr.push(m - 1, d - 1);
|
|
95
|
+
ans.rangeArr.push(months, days);
|
|
96
|
+
}
|
|
97
|
+
return ans;
|
|
98
|
+
};
|
|
99
|
+
const valueChanged2Obj = (currentObj, value, limit = 3) => {
|
|
100
|
+
const currentValue = currentObj.indexArr;
|
|
101
|
+
const rangeArr = currentObj.rangeArr;
|
|
102
|
+
if (limit === 3 && (currentValue[0] !== value[0] || currentValue[1] !== value[1])) {
|
|
103
|
+
const days = daysInMonth(value[0], value[1] + 1);
|
|
104
|
+
rangeArr[2] = days;
|
|
105
|
+
const maxIndex = days.length - 1;
|
|
106
|
+
if (value[2] > maxIndex) {
|
|
107
|
+
value[2] = maxIndex;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
return {
|
|
111
|
+
indexArr: value,
|
|
112
|
+
rangeArr
|
|
113
|
+
};
|
|
114
|
+
};
|
|
115
|
+
const valueChanged2Obj2 = (value, limit = 3, start, end) => {
|
|
116
|
+
const y = value[0] + START_YEAR;
|
|
117
|
+
const m = value[1] + 1;
|
|
118
|
+
const d = value[2] + 1;
|
|
119
|
+
return valueStr2Obj([y, m, d], limit, start, end);
|
|
120
|
+
};
|
|
121
|
+
const valueNum2String = (value) => {
|
|
122
|
+
return value.map((item, index) => {
|
|
123
|
+
if (index === 0) {
|
|
124
|
+
return item + START_YEAR;
|
|
125
|
+
}
|
|
126
|
+
else {
|
|
127
|
+
return wrapDate()(item + 1);
|
|
128
|
+
}
|
|
129
|
+
}).join('-');
|
|
130
|
+
};
|
|
131
|
+
const hasDiff = (currentValue, value, limit = 3) => {
|
|
132
|
+
for (let i = 0; i < limit; i++) {
|
|
133
|
+
if (currentValue[i] !== value[i]) {
|
|
134
|
+
return true;
|
|
21
135
|
}
|
|
22
136
|
}
|
|
23
|
-
return
|
|
24
|
-
}
|
|
25
|
-
const
|
|
26
|
-
const {
|
|
27
|
-
const [datevalue, setDateValue] = useState(value);
|
|
28
|
-
// 存储layout布局信息
|
|
29
|
-
const layoutRef = useRef({});
|
|
30
|
-
const viewRef = useRef(null);
|
|
137
|
+
return false;
|
|
138
|
+
};
|
|
139
|
+
const PickerDate = forwardRef((props, ref) => {
|
|
140
|
+
const { value = '', start = START_DATE, end = END_DATE, fields, bindchange } = props;
|
|
31
141
|
const nodeRef = useRef(null);
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
142
|
+
const columnLength = useMemo(() => getColumnLength(fields), [fields]);
|
|
143
|
+
const [formatObj, setFormatObj] = useState(valueStr2Obj(value, columnLength, start, end));
|
|
144
|
+
const timerRef = useRef(null);
|
|
35
145
|
useEffect(() => {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
};
|
|
44
|
-
const
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
146
|
+
return () => {
|
|
147
|
+
timerRef.current && clearTimeout(timerRef.current);
|
|
148
|
+
};
|
|
149
|
+
}, []);
|
|
150
|
+
useUpdateEffect(() => {
|
|
151
|
+
const calibratedValue = valueStr2Obj(value, columnLength, start, end);
|
|
152
|
+
setFormatObj(calibratedValue);
|
|
153
|
+
}, [value, columnLength, start, end]);
|
|
154
|
+
const updateValue = useCallback((value = '') => {
|
|
155
|
+
const calibratedValue = valueStr2Obj(value, columnLength, start, end);
|
|
156
|
+
setFormatObj(calibratedValue);
|
|
157
|
+
}, [columnLength, start, end]);
|
|
158
|
+
const _props = useRef(props);
|
|
159
|
+
_props.current = props;
|
|
160
|
+
useImperativeHandle(ref, () => ({
|
|
161
|
+
updateValue,
|
|
162
|
+
getNodeInstance: () => ({
|
|
163
|
+
props: _props,
|
|
164
|
+
nodeRef,
|
|
165
|
+
instance: {
|
|
166
|
+
style: {}
|
|
167
|
+
}
|
|
168
|
+
})
|
|
169
|
+
}));
|
|
170
|
+
const onChange = useCallback((e) => {
|
|
171
|
+
const { value } = e.detail;
|
|
172
|
+
const currentValue = formatObj.indexArr;
|
|
173
|
+
const newObj = valueChanged2Obj(formatObj, value, columnLength);
|
|
174
|
+
if (hasDiff(currentValue, value, columnLength)) {
|
|
175
|
+
setFormatObj(newObj);
|
|
176
|
+
const newObj2 = valueChanged2Obj2(value, columnLength, start, end);
|
|
177
|
+
if (hasDiff(newObj.indexArr, newObj2.indexArr, columnLength)) {
|
|
178
|
+
timerRef.current && clearTimeout(timerRef.current);
|
|
179
|
+
timerRef.current = setTimeout(() => setFormatObj(newObj2));
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
bindchange?.({ detail: { value: valueNum2String(newObj.indexArr) } });
|
|
183
|
+
}, [formatObj, columnLength, bindchange, start, end]);
|
|
184
|
+
const renderColumn = () => {
|
|
185
|
+
return formatObj.rangeArr?.map((item, index) => (
|
|
186
|
+
// @ts-expect-error ignore
|
|
187
|
+
<MpxPickerViewColumn key={index}>
|
|
188
|
+
{item.map((item, index) => {
|
|
189
|
+
return <Text key={index} style={styles.pickerItem}>
|
|
190
|
+
{item}
|
|
191
|
+
</Text>;
|
|
192
|
+
})}
|
|
193
|
+
</MpxPickerViewColumn>));
|
|
66
194
|
};
|
|
67
|
-
return (<
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
</TouchableWithoutFeedback>
|
|
71
|
-
</DatePicker>);
|
|
195
|
+
return (<MpxPickerView style={styles.pickerContainer} indicator-style={styles.pickerIndicator} value={formatObj.indexArr} bindchange={onChange}>
|
|
196
|
+
{renderColumn()}
|
|
197
|
+
</MpxPickerView>);
|
|
72
198
|
});
|
|
73
|
-
|
|
74
|
-
export default
|
|
199
|
+
PickerDate.displayName = 'MpxPickerDate';
|
|
200
|
+
export default PickerDate;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export const wrapDate = (union = '') => (num) => String(num).padStart(2, '0') + union;
|
|
2
|
+
export const START_YEAR = 1900;
|
|
3
|
+
export const END_YEAR = 2099;
|
|
4
|
+
export const years = Array.from({ length: 200 }, (_, index) => index + START_YEAR + '年');
|
|
5
|
+
export const months = Array.from({ length: 12 }, (_, index) => index + 1).map(wrapDate('月'));
|
|
6
|
+
export const daysInMonthLength = (year, month) => {
|
|
7
|
+
return month === 2
|
|
8
|
+
? year % 4 === 0 && (year % 100 !== 0 || year % 400 === 0)
|
|
9
|
+
? 29
|
|
10
|
+
: 28
|
|
11
|
+
: [4, 6, 9, 11].includes(month)
|
|
12
|
+
? 30
|
|
13
|
+
: 31;
|
|
14
|
+
};
|
|
15
|
+
export const daysInMonth = (year, month) => {
|
|
16
|
+
return Array.from({ length: daysInMonthLength(year, month) }, (_, index) => index + 1).map(wrapDate('日'));
|
|
17
|
+
};
|