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
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This source code is licensed under the BSD-style license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree. An additional grant
|
|
|
|
* of patent rights can be found in the PATENTS file in the same directory.
|
|
|
|
*
|
2015-03-23 17:06:16 +00:00
|
|
|
* @flow
|
2017-02-25 11:05:32 +00:00
|
|
|
* @providesModule DatePickerIOSExample
|
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');
|
2015-03-09 23:18:15 +00:00
|
|
|
var {
|
|
|
|
DatePickerIOS,
|
|
|
|
StyleSheet,
|
|
|
|
Text,
|
|
|
|
TextInput,
|
|
|
|
View,
|
2016-04-09 03:36:40 +00:00
|
|
|
} = ReactNative;
|
2015-03-09 23:18:15 +00:00
|
|
|
|
2016-07-26 08:00:02 +00:00
|
|
|
class DatePickerExample extends React.Component {
|
|
|
|
static defaultProps = {
|
|
|
|
date: new Date(),
|
|
|
|
timeZoneOffsetInHours: (-1) * (new Date()).getTimezoneOffset() / 60,
|
|
|
|
};
|
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
|
|
|
|
2016-07-26 08:00:02 +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
|
|
|
|
2016-07-26 08:00:02 +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:">
|
|
|
|
<Text>{
|
|
|
|
this.state.date.toLocaleDateString() +
|
|
|
|
' ' +
|
|
|
|
this.state.date.toLocaleTimeString()
|
|
|
|
}</Text>
|
|
|
|
</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
|
|
|
|
2016-07-26 08:00:02 +00:00
|
|
|
class WithLabel extends React.Component {
|
|
|
|
render() {
|
2015-03-09 23:18:15 +00:00
|
|
|
return (
|
|
|
|
<View style={styles.labelContainer}>
|
|
|
|
<View style={styles.labelView}>
|
|
|
|
<Text style={styles.label}>
|
|
|
|
{this.props.label}
|
|
|
|
</Text>
|
|
|
|
</View>
|
|
|
|
{this.props.children}
|
|
|
|
</View>
|
|
|
|
);
|
|
|
|
}
|
2016-07-26 08:00:02 +00:00
|
|
|
}
|
2015-03-09 23:18:15 +00:00
|
|
|
|
2016-07-26 08:00:02 +00:00
|
|
|
class Heading extends React.Component {
|
|
|
|
render() {
|
2015-03-09 23:18:15 +00:00
|
|
|
return (
|
|
|
|
<View style={styles.headingContainer}>
|
|
|
|
<Text style={styles.heading}>
|
|
|
|
{this.props.label}
|
|
|
|
</Text>
|
|
|
|
</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 = [
|
|
|
|
{
|
|
|
|
title: '<DatePickerIOS>',
|
2016-10-16 11:11:59 +00:00
|
|
|
render: function(): React.Element<any> {
|
2015-03-09 23:18:15 +00:00
|
|
|
return <DatePickerExample />;
|
|
|
|
},
|
|
|
|
}];
|
|
|
|
|
|
|
|
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,
|
|
|
|
},
|
|
|
|
});
|