forked from GeekyAnts/NativeBase
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDatePicker.js
More file actions
114 lines (104 loc) · 3.08 KB
/
DatePicker.js
File metadata and controls
114 lines (104 loc) · 3.08 KB
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
import React from 'react';
import { Modal, View } from 'react-native';
import DateTimePicker from '@react-native-community/datetimepicker';
import variable from '../theme/variables/platform';
import { Text } from './Text';
export class DatePicker extends React.Component {
static defaultProps = {
disabled: false
};
constructor(props) {
super(props);
this.state = {
modalVisible: false,
defaultDate: props.defaultDate ? props.defaultDate : new Date(),
chosenDate:
!props.placeHolderText && props.defaultDate
? props.defaultDate
: undefined
};
}
setDate(date) {
this.setState({ chosenDate: new Date(date) });
if (this.props.onDateChange) {
this.props.onDateChange(date);
}
}
showDatePicker = () => {
this.setState({ modalVisible: true });
};
formatChosenDate(date) {
if (this.props.formatChosenDate) {
return this.props.formatChosenDate(date);
}
return [date.getDate(), date.getMonth() + 1, date.getFullYear()].join('/');
}
render() {
const {
animationType,
disabled,
locale,
maximumDate,
minimumDate,
modalTransparent,
placeHolderText,
placeHolderTextStyle,
textStyle,
timeZoneOffsetInMinutes
} = this.props;
const variables = this.context.theme
? this.context.theme['@@shoutem.theme/themeStyle'].variables
: variable;
return (
<View>
<View>
<Text
onPress={() => (!disabled ? this.showDatePicker() : undefined)}
style={[
{
padding: variables.datePickerPadding,
color: variables.datePickerTextColor
},
this.state.chosenDate ? textStyle : placeHolderTextStyle
]}
>
{this.state.chosenDate
? this.formatChosenDate(this.state.chosenDate)
: placeHolderText || 'Select Date'}
</Text>
<View>
<Modal
supportedOrientations={['portrait', 'landscape']}
animationType={animationType}
transparent={modalTransparent} // from api
visible={this.state.modalVisible}
onRequestClose={() => {}}
>
<Text
onPress={() => this.setState({ modalVisible: false })}
style={{
backgroundColor: variables.datePickerBg,
flex: variables.datePickerFlex
}}
/>
<DateTimePicker
date={
this.state.chosenDate
? this.state.chosenDate
: this.state.defaultDate
}
onDateChange={date => this.setDate(date)}
minimumDate={minimumDate}
maximumDate={maximumDate}
mode="date"
locale={locale}
timeZoneOffsetInMinutes={timeZoneOffsetInMinutes}
{...this.props}
/>
</Modal>
</View>
</View>
</View>
);
}
}