1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
|
import moment from 'moment';
import React, {useState} from 'react';
import {
Modal,
StyleSheet,
Text,
TextInputProps,
TouchableWithoutFeedback,
View,
} from 'react-native';
import {Button} from 'react-native-elements';
import {TouchableOpacity} from 'react-native-gesture-handler';
import {TaggDatePicker} from '../common';
interface BirthDatePickerProps extends TextInputProps {
handleBDUpdate: (_: Date) => void;
width?: number | string;
}
const BirthDatePicker = React.forwardRef(
(props: BirthDatePickerProps, ref: any) => {
const getMaxDate = () => {
const maxDate = moment().subtract(13, 'y').subtract(1, 'd');
return maxDate.toDate();
};
const [date, setDate] = useState(new Date(0));
const [hidden, setHidden] = useState(true);
const [updated, setUpdated] = useState(false);
const textColor = updated ? 'white' : '#ddd';
const updateDate = (newDate: Date) => {
props.handleBDUpdate(newDate);
setDate(newDate);
setUpdated(true);
};
return (
<View style={styles.container}>
<TouchableOpacity
onPress={() => {
setHidden(false);
}}>
<Text
style={[styles.input, {width: props.width}, {color: textColor}]}
ref={ref}
{...props}>
{updated ? moment(date).format('YYYY-MM-DD') : 'Date of Birth'}
</Text>
</TouchableOpacity>
<Modal visible={!hidden} transparent={true} animationType="fade">
<TouchableWithoutFeedback
onPress={() => {
setHidden(true);
}}>
<View style={styles.bottomView}>
<TouchableWithoutFeedback>
<View style={styles.modalView}>
<View style={styles.buttonView}>
<Button
title="Done"
titleStyle={styles.doneButtonTitle}
buttonStyle={styles.doneButton}
onPress={() => {
setHidden(true);
}}
/>
</View>
<TaggDatePicker
handleDateUpdate={updateDate}
maxDate={getMaxDate()}
textColor={'black'}
/>
</View>
</TouchableWithoutFeedback>
</View>
</TouchableWithoutFeedback>
</Modal>
</View>
);
},
);
const styles = StyleSheet.create({
container: {
width: '100%',
alignItems: 'center',
marginVertical: 11,
},
input: {
height: 40,
fontSize: 16,
paddingTop: '2%',
fontWeight: '600',
borderColor: '#fffdfd',
borderWidth: 2,
borderRadius: 20,
paddingLeft: 13,
},
modalView: {
backgroundColor: 'rgb(202, 206, 212)',
height: '29%',
alignItems: 'center',
justifyContent: 'space-between',
},
bottomView: {
flex: 1,
justifyContent: 'flex-end',
},
buttonView: {
backgroundColor: 'rgb(247, 247, 247)',
width: '100%',
paddingRight: '2.5%',
alignItems: 'flex-end',
flexDirection: 'row',
justifyContent: 'flex-end',
},
doneButtonTitle: {
fontWeight: '600',
fontSize: 17,
color: 'rgb(19, 125, 250)',
},
doneButton: {
backgroundColor: 'transparent',
},
});
export default BirthDatePicker;
|