Datetime Picker is not opening i'm using react-native with react-hooks, in Android works fine . but its not opening in IOS and not showing any error.
i just created local component for datepicker so i can use it for both android and ios. for android its going fine IOS is the issue, its not responding
i done pod clean and install also no luck
const DatePicker =({}) =>{
const [state, setState] = useState({
date: new Date(),
mode: 'date',
show: false
});
const showPicker = mode => {
setState(prevState => ({
...prevState,
show: Platform.OS === 'ios',
mode
}));
};
const datePicker = () => {
showPicker('datetime');
};
return(
<>
<View>
<View style={styles.createBorder}>
<TouchableHighlight
underlayColor={disable ? 'transperant' : ''}
onPress={!disable && timePicker}
>
<View style={styles.datePickerBox}>
<Text
style={[styles.datePickerText, { width: width - 60 }]}
>
{state.date}
</Text>
</View>
</TouchableHighlight>
</View>
{state.show && Platform.OS === 'ios' && (
<DateTimePicker
style={[styles.inputBackground, {width: '100%' }]}
value={state.date}
mode="datetime"
is24Hour={false}
display="default"
onChange={setDate}
/>
)}
</View>
</>
);
}
export default DatePicker;
I had the same problem as of June 26, 2020, with this version: "@react-native-community/datetimepicker": "2.2.2".
I just added style with width and the datetimepicker displayed in iOS:
style={{width: 320, backgroundColor: "white"}}
I also added backgroundColor so that it becomes opaque white.
Here is my code:
<DateTimePicker
value={user.birthdate ? new Date(user.birthdate) : new Date()}
mode='date'
display="default"
onChange={(event, date) => {
//...some code here
setBirthdateTouched(true);
setModalVisible(!modalVisible);
}}
style={{width: 320, backgroundColor: "white"}} //add this
/>
Enjoy coding!
I just move to react-native-modal-datetime-picker its working fine now
<DatePicker
iOSDatePickerComponent={(props) => (
<RNDatePicker
{...props}
display={
Platform.OS === "ios" ? "spinner" : "default"
}
/>
)} ..../>
just add this in your datePicker component will work fine ;)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With