I'm using a DatePickerIOS
inside a Modal
to return the selected date to the main page.
DateTimeController Component
var DateTimeController = React.createClass({
show: function () {
this.setState({modalVisible: true});
},
getInitialState: function () {
return {
timeZoneOffsetInHours: this.props.timeZoneOffsetInHours,
date: this.props.date,
color: this.props.color || '#007AFF',
minimumDate: this.props.minimumDate,
modalVisible: false
};
},
onDateChange: function (date) {
this.setState({date: date});
},
cancelButtonPressed: function() {
this.setState({modalVisible: false});
},
confirmButtonPressed: function() {
if(this.props.onSubmit) this.props.onSubmit(this.state.date);
this.setState({modalVisible: false});
},
render: function () {
return (
<Modal
animated={true}
transparent={true}
visible={this.state.modalVisible}>
<View style={styles.basicContainer}>
<View style={styles.modalContainer}>
<View style={styles.buttonView}>
<Button onPress={this.cancelButtonPressed} style={styles.timeSectionButtons}></Button>
<Button onPress={this.confirmButtonPressed} style={styles.timeSectionButtons}></Button>
</View>
<View style={styles.mainBox}>
<DatePickerIOS
date={this.state.date}
mode="datetime"
timeZoneOffsetInMinutes={this.state.timeZoneOffsetInHours}
onDateChange={this.onDateChange}
minimumDate={this.state.minimumDate}
/>
</View>
</View>
</View>
</Modal>
);
}
});
Implementation of the Component
getInitialState: function () {
return {
date: new Date(),
timeZoneOffsetInHours: (-1) * (new Date()).getTimezoneOffset() / 60,
};
},
onDateChange: function (date) {
this.setState({date: date});
},
return (
<View style={styles.mainContainer}>
<Text
style={styles.secondaryText}
onPress={()=>{
this.refs.picker.show();
}}>
{
this.state.date.toLocaleDateString() +
' ' +
this.state.date.toLocaleTimeString()
}
</Text>
<DateTimeController ref={'picker'} timeZoneOffsetInHours={this.state.timeZoneOffsetInHours * 60}
date={this.state.date} minimumDate={new Date()}
onSubmit={(date)=>{
this.setState({date: date})
}}
/>
<View>
);
I'm getting the following YellowBox Warnings when the Modal opens render the DatePickerIOS
.
Warning: Failed propType: Invalid prop
date
of typeNumber
supplied toRCTDatePicker
, expected instance ofDate
. Check the render method ofDatePickerIOS
.Warning: Failed propType: Required prop
onDateChange
was not specified inRCTDatePicker
. Check the render method ofDatePickerIOS
.Warning: Failed propType: Invalid prop
minimumDate
of typeNumber
supplied toRCTDatePicker
, expected instance ofDate
. Check the render method ofDatePickerIOS
.
How to avert these warnings and fix this?