2015-03-09 23:18:15 +00:00
|
|
|
/**
|
2015-03-26 18:24:15 +00:00
|
|
|
* The examples provided by Facebook are for non-commercial testing and
|
|
|
|
* evaluation purposes only.
|
2015-03-23 22:07:33 +00:00
|
|
|
*
|
2015-03-26 18:24:15 +00:00
|
|
|
* Facebook reserves all rights not expressly granted.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
|
|
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NON INFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
* FACEBOOK BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
|
|
|
|
* AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
|
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
2015-03-23 22:07:33 +00:00
|
|
|
*
|
2015-03-23 17:06:16 +00:00
|
|
|
* @flow
|
2015-03-09 23:18:15 +00:00
|
|
|
*/
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
var React = require('react-native');
|
|
|
|
var {
|
|
|
|
DatePickerIOS,
|
|
|
|
StyleSheet,
|
|
|
|
Text,
|
|
|
|
TextInput,
|
|
|
|
View,
|
|
|
|
} = React;
|
|
|
|
|
|
|
|
var DatePickerExample = React.createClass({
|
|
|
|
getDefaultProps: function () {
|
|
|
|
return {
|
|
|
|
date: new Date(),
|
|
|
|
timeZoneOffsetInHours: (-1) * (new Date()).getTimezoneOffset() / 60,
|
|
|
|
};
|
|
|
|
},
|
|
|
|
|
|
|
|
getInitialState: function() {
|
|
|
|
return {
|
|
|
|
date: this.props.date,
|
|
|
|
timeZoneOffsetInHours: this.props.timeZoneOffsetInHours,
|
|
|
|
};
|
|
|
|
},
|
|
|
|
|
|
|
|
onDateChange: function(date) {
|
|
|
|
this.setState({date: date});
|
|
|
|
},
|
|
|
|
|
|
|
|
onTimezoneChange: function(event) {
|
|
|
|
var offset = parseInt(event.nativeEvent.text, 10);
|
|
|
|
if (isNaN(offset)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
this.setState({timeZoneOffsetInHours: offset});
|
|
|
|
},
|
|
|
|
|
|
|
|
render: function() {
|
|
|
|
// 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>
|
|
|
|
);
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
var WithLabel = React.createClass({
|
|
|
|
render: function() {
|
|
|
|
return (
|
|
|
|
<View style={styles.labelContainer}>
|
|
|
|
<View style={styles.labelView}>
|
|
|
|
<Text style={styles.label}>
|
|
|
|
{this.props.label}
|
|
|
|
</Text>
|
|
|
|
</View>
|
|
|
|
{this.props.children}
|
|
|
|
</View>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
var Heading = React.createClass({
|
|
|
|
render: function() {
|
|
|
|
return (
|
|
|
|
<View style={styles.headingContainer}>
|
|
|
|
<Text style={styles.heading}>
|
|
|
|
{this.props.label}
|
|
|
|
</Text>
|
|
|
|
</View>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
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>',
|
2015-03-23 17:06:16 +00:00
|
|
|
render: function(): ReactElement {
|
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,
|
|
|
|
},
|
|
|
|
});
|