@shoutem/ui 4.6.5 → 4.6.6-rc.0
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/components/DateTimePicker.js +76 -10
- package/package.json +1 -1
- package/theme.js +2 -0
|
@@ -13,15 +13,39 @@ import { View } from './View';
|
|
|
13
13
|
|
|
14
14
|
const isIos = Platform.OS === 'ios';
|
|
15
15
|
|
|
16
|
+
export const DATEPICKER_MODES = {
|
|
17
|
+
DATE: 'date',
|
|
18
|
+
DATETIME: 'datetime',
|
|
19
|
+
TIME: 'time',
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
const DISPLAY_MODES = {
|
|
23
|
+
[DATEPICKER_MODES.DATE]: 'inline',
|
|
24
|
+
[DATEPICKER_MODES.DATETIME]: 'inline',
|
|
25
|
+
[DATEPICKER_MODES.TIME]: 'spinner',
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
function getDisplayMode(mode) {
|
|
29
|
+
if (!isIos || !Object.keys(DISPLAY_MODES).includes(mode)) {
|
|
30
|
+
return 'default';
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return DISPLAY_MODES[mode];
|
|
34
|
+
}
|
|
35
|
+
|
|
16
36
|
class DateTimePicker extends PureComponent {
|
|
17
37
|
constructor(props) {
|
|
18
38
|
super(props);
|
|
19
39
|
|
|
20
40
|
autoBindReact(this);
|
|
21
41
|
|
|
42
|
+
const { mode, value } = props;
|
|
43
|
+
|
|
22
44
|
this.state = {
|
|
45
|
+
display: getDisplayMode(mode),
|
|
23
46
|
showPicker: false,
|
|
24
|
-
|
|
47
|
+
showTimePicker: false,
|
|
48
|
+
value,
|
|
25
49
|
};
|
|
26
50
|
}
|
|
27
51
|
|
|
@@ -42,10 +66,33 @@ class DateTimePicker extends PureComponent {
|
|
|
42
66
|
return this.handleHidePicker();
|
|
43
67
|
}
|
|
44
68
|
|
|
69
|
+
const { mode, onValueChanged } = this.props;
|
|
70
|
+
|
|
71
|
+
const showTimePicker = mode === DATEPICKER_MODES.DATETIME;
|
|
72
|
+
|
|
73
|
+
this.setState({ value, showPicker: false, showTimePicker });
|
|
74
|
+
return !showTimePicker && onValueChanged(value);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
handleTimeValueChanged(event, selectedValue) {
|
|
78
|
+
if (event.type === 'dismissed') {
|
|
79
|
+
return this.handleHidePicker();
|
|
80
|
+
}
|
|
81
|
+
|
|
45
82
|
const { onValueChanged } = this.props;
|
|
83
|
+
const { value } = this.state;
|
|
46
84
|
|
|
47
|
-
|
|
48
|
-
|
|
85
|
+
// Time picker value will override preselected date
|
|
86
|
+
// Use current date from state and only set hours & minutes
|
|
87
|
+
const currentDate = new Date(value);
|
|
88
|
+
const selectedDate = new Date(selectedValue);
|
|
89
|
+
const hour = selectedDate.getHours();
|
|
90
|
+
const minutes = selectedDate.getMinutes();
|
|
91
|
+
|
|
92
|
+
currentDate.setHours(hour, minutes, 0);
|
|
93
|
+
|
|
94
|
+
this.setState({ value: currentDate, showTimePicker: false });
|
|
95
|
+
return onValueChanged(currentDate);
|
|
49
96
|
}
|
|
50
97
|
|
|
51
98
|
handleShowPicker() {
|
|
@@ -66,6 +113,7 @@ class DateTimePicker extends PureComponent {
|
|
|
66
113
|
|
|
67
114
|
render() {
|
|
68
115
|
const {
|
|
116
|
+
cancelButtonText,
|
|
69
117
|
confirmButtonText,
|
|
70
118
|
is24Hour,
|
|
71
119
|
mode,
|
|
@@ -73,7 +121,7 @@ class DateTimePicker extends PureComponent {
|
|
|
73
121
|
style,
|
|
74
122
|
...otherProps
|
|
75
123
|
} = this.props;
|
|
76
|
-
const { showPicker, value } = this.state;
|
|
124
|
+
const { display, showPicker, showTimePicker, value } = this.state;
|
|
77
125
|
|
|
78
126
|
return (
|
|
79
127
|
<View styleName="horizontal">
|
|
@@ -82,7 +130,7 @@ class DateTimePicker extends PureComponent {
|
|
|
82
130
|
style={style.textContainer}
|
|
83
131
|
onPress={this.handleShowPicker}
|
|
84
132
|
>
|
|
85
|
-
<Text>
|
|
133
|
+
<Text>{textValue}</Text>
|
|
86
134
|
</TouchableOpacity>
|
|
87
135
|
<TouchableOpacity
|
|
88
136
|
onPress={this.handleShowPicker}
|
|
@@ -91,7 +139,7 @@ class DateTimePicker extends PureComponent {
|
|
|
91
139
|
>
|
|
92
140
|
<Icon name="drop-down" style={style.icon} />
|
|
93
141
|
</TouchableOpacity>
|
|
94
|
-
{isIos && (
|
|
142
|
+
{isIos && showPicker && (
|
|
95
143
|
<Modal
|
|
96
144
|
backdropOpacity={0.5}
|
|
97
145
|
isVisible={showPicker}
|
|
@@ -103,7 +151,7 @@ class DateTimePicker extends PureComponent {
|
|
|
103
151
|
>
|
|
104
152
|
<View styleName="md-gutter" style={style.modalContainer}>
|
|
105
153
|
<RNCDateTimePicker
|
|
106
|
-
display=
|
|
154
|
+
display={display}
|
|
107
155
|
is24Hour={is24Hour}
|
|
108
156
|
mode={mode}
|
|
109
157
|
onChange={this.handleValueChanged}
|
|
@@ -114,8 +162,14 @@ class DateTimePicker extends PureComponent {
|
|
|
114
162
|
/>
|
|
115
163
|
<View
|
|
116
164
|
style={style.modalButtonContainer}
|
|
117
|
-
styleName="md-gutter-top"
|
|
165
|
+
styleName="horizontal md-gutter-top"
|
|
118
166
|
>
|
|
167
|
+
<Button
|
|
168
|
+
style={style.modalButton}
|
|
169
|
+
onPress={this.handleHidePicker}
|
|
170
|
+
>
|
|
171
|
+
<Text>{cancelButtonText}</Text>
|
|
172
|
+
</Button>
|
|
119
173
|
<Button
|
|
120
174
|
style={style.modalButton}
|
|
121
175
|
onPress={this.handleConfirmPress}
|
|
@@ -128,7 +182,7 @@ class DateTimePicker extends PureComponent {
|
|
|
128
182
|
)}
|
|
129
183
|
{!isIos && showPicker && (
|
|
130
184
|
<RNCDateTimePicker
|
|
131
|
-
display=
|
|
185
|
+
display={display}
|
|
132
186
|
is24Hour={is24Hour}
|
|
133
187
|
mode={mode}
|
|
134
188
|
onChange={this.handleValueChanged}
|
|
@@ -136,21 +190,33 @@ class DateTimePicker extends PureComponent {
|
|
|
136
190
|
{...otherProps}
|
|
137
191
|
/>
|
|
138
192
|
)}
|
|
193
|
+
{!isIos && !showPicker && showTimePicker && (
|
|
194
|
+
<RNCDateTimePicker
|
|
195
|
+
display={display}
|
|
196
|
+
is24Hour={is24Hour}
|
|
197
|
+
mode="time"
|
|
198
|
+
onChange={this.handleTimeValueChanged}
|
|
199
|
+
value={value}
|
|
200
|
+
{...otherProps}
|
|
201
|
+
/>
|
|
202
|
+
)}
|
|
139
203
|
</View>
|
|
140
204
|
);
|
|
141
205
|
}
|
|
142
206
|
}
|
|
143
207
|
|
|
144
208
|
DateTimePicker.propTypes = {
|
|
209
|
+
cancelButtonText: PropTypes.string,
|
|
145
210
|
confirmButtonText: PropTypes.string,
|
|
146
211
|
is24Hour: PropTypes.bool,
|
|
147
|
-
mode: PropTypes.
|
|
212
|
+
mode: PropTypes.oneOf(Object.values(DATEPICKER_MODES)),
|
|
148
213
|
onValueChanged: PropTypes.func,
|
|
149
214
|
textValue: PropTypes.string,
|
|
150
215
|
value: PropTypes.oneOfType([PropTypes.string, PropTypes.instanceOf(Date)]),
|
|
151
216
|
};
|
|
152
217
|
|
|
153
218
|
DateTimePicker.defaultProps = {
|
|
219
|
+
cancelButtonText: 'Cancel',
|
|
154
220
|
confirmButtonText: 'Confirm',
|
|
155
221
|
is24Hour: false,
|
|
156
222
|
mode: 'datetime',
|
package/package.json
CHANGED
package/theme.js
CHANGED