2015-03-09 23:18:15 +00:00
|
|
|
/**
|
2017-05-06 03:50:47 +00:00
|
|
|
* Copyright (c) 2015-present, Facebook, Inc.
|
2016-07-12 12:51:57 +00:00
|
|
|
*
|
2018-02-17 02:24:55 +00:00
|
|
|
* This source code is licensed under the MIT license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree.
|
2016-07-12 12:51:57 +00:00
|
|
|
*
|
2018-05-11 20:32:37 +00:00
|
|
|
* @format
|
2015-03-23 17:06:16 +00:00
|
|
|
* @flow
|
2015-03-09 23:18:15 +00:00
|
|
|
*/
|
2018-05-11 20:32:37 +00:00
|
|
|
|
2015-03-09 23:18:15 +00:00
|
|
|
'use strict';
|
|
|
|
|
2016-04-09 03:36:40 +00:00
|
|
|
var React = require('react');
|
|
|
|
var ReactNative = require('react-native');
|
2018-05-11 20:32:37 +00:00
|
|
|
var {DatePickerIOS, StyleSheet, Text, TextInput, View} = ReactNative;
|
2015-03-09 23:18:15 +00:00
|
|
|
|
2018-05-11 20:32:37 +00:00
|
|
|
class DatePickerExample extends React.Component<
|
|
|
|
$FlowFixMeProps,
|
|
|
|
$FlowFixMeState,
|
|
|
|
> {
|
2016-07-26 08:00:02 +00:00
|
|
|
static defaultProps = {
|
|
|
|
date: new Date(),
|
2018-06-06 12:20:40 +00:00
|
|
|
timeZoneOffsetInHours: (-1 * new Date().getTimezoneOffset()) / 60,
|
2016-07-26 08:00:02 +00:00
|
|
|
};
|
2015-03-09 23:18:15 +00:00
|
|
|
|
2016-07-26 08:00:02 +00:00
|
|
|
state = {
|
|
|
|
date: this.props.date,
|
|
|
|
timeZoneOffsetInHours: this.props.timeZoneOffsetInHours,
|
|
|
|
};
|
2015-03-09 23:18:15 +00:00
|
|
|
|
2018-05-11 20:32:37 +00:00
|
|
|
onDateChange = date => {
|
2015-03-09 23:18:15 +00:00
|
|
|
this.setState({date: date});
|
2016-07-26 08:00:02 +00:00
|
|
|
};
|
2015-03-09 23:18:15 +00:00
|
|
|
|
2018-05-11 20:32:37 +00:00
|
|
|
onTimezoneChange = event => {
|
2015-03-09 23:18:15 +00:00
|
|
|
var offset = parseInt(event.nativeEvent.text, 10);
|
|
|
|
if (isNaN(offset)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
this.setState({timeZoneOffsetInHours: offset});
|
2016-07-26 08:00:02 +00:00
|
|
|
};
|
2015-03-09 23:18:15 +00:00
|
|
|
|
2016-07-26 08:00:02 +00:00
|
|
|
render() {
|
2015-03-09 23:18:15 +00:00
|
|
|
// Ideally, the timezone input would be a picker rather than a
|
|
|
|
// text input, but we don't have any pickers yet :(
|
|
|
|
return (
|
|
|
|
<View>
|
|
|
|
<WithLabel label="Value:">
|
2018-05-11 20:32:37 +00:00
|
|
|
<Text>
|
|
|
|
{this.state.date.toLocaleDateString() +
|
|
|
|
' ' +
|
|
|
|
this.state.date.toLocaleTimeString()}
|
|
|
|
</Text>
|
2015-03-09 23:18:15 +00:00
|
|
|
</WithLabel>
|
|
|
|
<WithLabel label="Timezone:">
|
|
|
|
<TextInput
|
|
|
|
onChange={this.onTimezoneChange}
|
|
|
|
style={styles.textinput}
|
|
|
|
value={this.state.timeZoneOffsetInHours.toString()}
|
|
|
|
/>
|
|
|
|
<Text> hours from UTC</Text>
|
|
|
|
</WithLabel>
|
|
|
|
<Heading label="Date + time picker" />
|
|
|
|
<DatePickerIOS
|
|
|
|
date={this.state.date}
|
|
|
|
mode="datetime"
|
|
|
|
timeZoneOffsetInMinutes={this.state.timeZoneOffsetInHours * 60}
|
|
|
|
onDateChange={this.onDateChange}
|
|
|
|
/>
|
|
|
|
<Heading label="Date picker" />
|
|
|
|
<DatePickerIOS
|
|
|
|
date={this.state.date}
|
|
|
|
mode="date"
|
|
|
|
timeZoneOffsetInMinutes={this.state.timeZoneOffsetInHours * 60}
|
|
|
|
onDateChange={this.onDateChange}
|
|
|
|
/>
|
|
|
|
<Heading label="Time picker, 10-minute interval" />
|
|
|
|
<DatePickerIOS
|
|
|
|
date={this.state.date}
|
|
|
|
mode="time"
|
|
|
|
timeZoneOffsetInMinutes={this.state.timeZoneOffsetInHours * 60}
|
|
|
|
onDateChange={this.onDateChange}
|
|
|
|
minuteInterval={10}
|
|
|
|
/>
|
|
|
|
</View>
|
|
|
|
);
|
2016-07-26 08:00:02 +00:00
|
|
|
}
|
|
|
|
}
|
2015-03-09 23:18:15 +00:00
|
|
|
|
2017-08-18 01:36:54 +00:00
|
|
|
class WithLabel extends React.Component<$FlowFixMeProps> {
|
2016-07-26 08:00:02 +00:00
|
|
|
render() {
|
2015-03-09 23:18:15 +00:00
|
|
|
return (
|
|
|
|
<View style={styles.labelContainer}>
|
|
|
|
<View style={styles.labelView}>
|
2018-05-11 20:32:37 +00:00
|
|
|
<Text style={styles.label}>{this.props.label}</Text>
|
2015-03-09 23:18:15 +00:00
|
|
|
</View>
|
|
|
|
{this.props.children}
|
|
|
|
</View>
|
|
|
|
);
|
|
|
|
}
|
2016-07-26 08:00:02 +00:00
|
|
|
}
|
2015-03-09 23:18:15 +00:00
|
|
|
|
2017-08-18 01:36:54 +00:00
|
|
|
class Heading extends React.Component<$FlowFixMeProps> {
|
2016-07-26 08:00:02 +00:00
|
|
|
render() {
|
2015-03-09 23:18:15 +00:00
|
|
|
return (
|
|
|
|
<View style={styles.headingContainer}>
|
2018-05-11 20:32:37 +00:00
|
|
|
<Text style={styles.heading}>{this.props.label}</Text>
|
2015-03-09 23:18:15 +00:00
|
|
|
</View>
|
|
|
|
);
|
|
|
|
}
|
2016-07-26 08:00:02 +00:00
|
|
|
}
|
2015-03-09 23:18:15 +00:00
|
|
|
|
2015-06-22 16:43:30 +00:00
|
|
|
exports.displayName = (undefined: ?string);
|
2015-03-09 23:18:15 +00:00
|
|
|
exports.title = '<DatePickerIOS>';
|
|
|
|
exports.description = 'Select dates and times using the native UIDatePicker.';
|
|
|
|
exports.examples = [
|
2018-05-11 20:32:37 +00:00
|
|
|
{
|
|
|
|
title: '<DatePickerIOS>',
|
|
|
|
render: function(): React.Element<any> {
|
|
|
|
return <DatePickerExample />;
|
|
|
|
},
|
2015-03-09 23:18:15 +00:00
|
|
|
},
|
2018-05-11 20:32:37 +00:00
|
|
|
];
|
2015-03-09 23:18:15 +00:00
|
|
|
|
|
|
|
var styles = StyleSheet.create({
|
|
|
|
textinput: {
|
|
|
|
height: 26,
|
|
|
|
width: 50,
|
|
|
|
borderWidth: 0.5,
|
|
|
|
borderColor: '#0f0f0f',
|
|
|
|
padding: 4,
|
|
|
|
fontSize: 13,
|
|
|
|
},
|
|
|
|
labelContainer: {
|
|
|
|
flexDirection: 'row',
|
|
|
|
alignItems: 'center',
|
|
|
|
marginVertical: 2,
|
|
|
|
},
|
|
|
|
labelView: {
|
|
|
|
marginRight: 10,
|
|
|
|
paddingVertical: 2,
|
|
|
|
},
|
|
|
|
label: {
|
2015-03-26 01:19:28 +00:00
|
|
|
fontWeight: '500',
|
2015-03-09 23:18:15 +00:00
|
|
|
},
|
|
|
|
headingContainer: {
|
|
|
|
padding: 4,
|
|
|
|
backgroundColor: '#f6f7f8',
|
|
|
|
},
|
|
|
|
heading: {
|
2015-03-26 01:19:28 +00:00
|
|
|
fontWeight: '500',
|
2015-03-09 23:18:15 +00:00
|
|
|
fontSize: 14,
|
|
|
|
},
|
|
|
|
});
|