react-native-modal-datetime-picker showing only current date

1.8k Views Asked by At

I'm using react-native-modal-datetime-picker in my React Native app on iOS, and when the modal pops up, instead of having a range of dates to scroll through, it shows only the current date:

enter image description here

<DateTimePickerModal
    datePickerModeAndroid={'spinner'}
    mode={'date'}
    is24Hour={false}
    isVisible={this.state.isDatePickerVisible}
    onConfirm={() => {}}
    onCancel={() => {}}/>

[email protected] [email protected]

Does anyone know how to approach solving this?

2

There are 2 best solutions below

0
On
  1. add display = 'spinner'

    and inside ios->myappname->AppDelegate.m add these lines inside didfinishlaunch options;

    
    if (@available(iOS 14, *)) {
        UIDatePicker *picker = [UIDatePicker appearance];
        picker.preferredDatePickerStyle = UIDatePickerStyleWheels;  }

0
On

Just add display={"spinner"}

Your device/simulator use default display style which is calendar and in calendar case above UI will be render.

Example Code:

<DateTimePickerModal
    date={this.props.currentDate || undefined}
    maximumDate={this.props.maximumDate}
    minimumDate={this.props.minimumDate}
    mode="date"
    onCancel={this.onCancel}
    onConfirm={this.onConfirm}
    isVisible={this.state.modalOpened}
    display={this.props.display}
/>