Skip to content

Commit 3438477

Browse files
committed
fix(Form): 集成DatePicker组件
1 parent 156fdd3 commit 3438477

File tree

7 files changed

+60
-5
lines changed

7 files changed

+60
-5
lines changed

example/examples/src/routes/DatePicker/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import React from 'react';
2-
import {Text, View} from 'react-native';
32
import {DatePicker, Button} from '@uiw/react-native';
43
import {ComProps} from '../../routes';
54
import Layout, {Container} from '../../Layout';
@@ -28,6 +27,7 @@ export default class BadgeView extends React.Component<BadgeViewProps> {
2827
</Button>
2928
<DatePicker
3029
visible={this.state.visible}
30+
onOk={() => this.setState({visible: false})}
3131
onClosed={() => this.setState({visible: false})}
3232
precision="second"
3333
max="2021-11-30 23:50:50"

example/examples/src/routes/Form/index.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,12 @@ const FormDemo = () => {
6464
showClear: true,
6565
},
6666
},
67+
{
68+
type: 'datePicker',
69+
field: 'datePicker',
70+
name: '时间',
71+
attr: {},
72+
},
6773
];
6874
const initialValues = {name: '王滴滴', age: '31'};
6975

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import React, { useState } from 'react';
2+
import { SafeAreaView, Pressable, View, Text, StyleSheet } from 'react-native';
3+
import DatePicker, { DatePickerProps } from '../../DatePicker';
4+
import Icon from '../../Icon';
5+
6+
const FormDatePicker = ({ value, ok, ...attr }: DatePickerProps & { ok?: (value: string) => void }) => {
7+
const [visible, setVisible] = useState(false);
8+
return (
9+
<SafeAreaView>
10+
<Pressable onPress={() => setVisible(true)}>
11+
<View style={[styles.content]}>
12+
<Text style={styles.contentTitle}>{value ? value : ''}</Text>
13+
<Icon name="right" size={18} color="#A19EA0" />
14+
</View>
15+
</Pressable>
16+
<DatePicker
17+
value={value}
18+
visible={visible}
19+
onClosed={() => setVisible(false)}
20+
onOk={(value) => {
21+
setVisible(false);
22+
ok?.(value);
23+
}}
24+
{...attr}
25+
/>
26+
</SafeAreaView>
27+
);
28+
};
29+
30+
export default FormDatePicker;
31+
32+
const styles = StyleSheet.create({
33+
contentTitle: {
34+
fontSize: 16,
35+
color: 'black',
36+
},
37+
content: {
38+
flexDirection: 'row',
39+
height: 35,
40+
alignItems: 'center',
41+
justifyContent: 'space-between',
42+
paddingRight: 5,
43+
backgroundColor: '#fff',
44+
},
45+
});

packages/core/src/Form/formItems.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import CheckBox from '../CheckBox';
66
import Rating from '../Rating';
77
import Switch from '../Switch';
88
import SearchBar from '../SearchBar';
9+
import FormDatePicker from './comps/datePicker';
910
import { View, Text, SafeAreaView, StyleSheet, TextInput } from 'react-native';
1011

1112
const FormItems: FC<any> = ({ formDatas = [] }) => {
@@ -64,6 +65,7 @@ const FormItems: FC<any> = ({ formDatas = [] }) => {
6465
}
6566
change(v.field, data);
6667
}}
68+
onBlur={() => validate()}
6769
{...v.attr}
6870
>
6971
{item.label}
@@ -82,11 +84,15 @@ const FormItems: FC<any> = ({ formDatas = [] }) => {
8284
<SearchBar
8385
options={options}
8486
onChange={(val) => change(v.field, val)}
87+
onBlur={() => validate()}
8588
contentStyle={{ paddingHorizontal: 0 }}
8689
{...v.attr}
8790
/>
8891
);
8992
}
93+
if (v.type === 'datePicker') {
94+
return <FormDatePicker value={store[v.field]} ok={(value) => change(v.field, value)} {...v.attr} />;
95+
}
9096
return null;
9197
};
9298

packages/core/src/Form/hooks/context.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const reducer = (state: Partial<InitialState>, action: Partial<InitialState>) =>
2121
};
2222
};
2323

24-
const Provider: FC<PropsWithChildren<any>> = ({ contextProps, children }) => {
24+
const Provider: FC<PropsWithChildren<Partial<Record<string, any>>>> = ({ contextProps, children }) => {
2525
const [state, dispatch] = useReducer(reducer, initialState);
2626
return <Context.Provider value={{ ...contextProps, state, dispatch }}>{children}</Context.Provider>;
2727
};

packages/core/src/Form/hooks/useForm.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export default function useForm<
2323
initValues: { initialValues: state.initialValues },
2424
});
2525

26-
const updateStore = (datas: Partial<any>) => {
26+
const updateStore = (datas: Partial<State>) => {
2727
setState({
2828
...state,
2929
...datas,

packages/core/src/Form/utils/index.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import cloneDeepWith from 'lodash/cloneDeepWith';
2-
import lodashSet from 'lodash/set';
32
import { isObject, isArray } from './is';
4-
import { PropertyPath } from 'lodash';
53

64
export function cloneDeep(value: any) {
75
// 只有对象才执行拷贝,否则直接返回。 如果是 File,MouseEvent对象,都可以直接返回

0 commit comments

Comments
 (0)