React Native Modal Date Picker - why am I getting an extra window?

Viewed 2739

My React Native app (iOS) is using the React Native Modal Datetime Picker package. I have a button which, when clicked, should open the calendar so that I can pick a date.

However, when I click the button, I get the following modal window:

Extra modal window

If I then click on the date in that window, I see the calendar:

Calendar window

I want the calendar to appear when I click the button initially.

Here's the relevant code:

  const [isDatePickerVisible, setIsDatePickerVisibility] = useState(false);

  const showDatePicker = () => {
    setIsDatePickerVisibility(true);
  };

  const hideDatePicker = () => {
    setIsDatePickerVisibility(false);
  };

  return (
    <View>
      <Text style={styles.inputTitle}>DATE OF BIRTH</Text>
      <View style={styles.dateInput}>
        <TextInput
           editable={false}
           style={styles.input}
           value={dateOfBirth}
        />
        <Button transparent onPress={showDatePicker}>
          <Icon
            type="FontAwesome5"
            name={'calendar-alt'}
          />
        </Button>
        <DateTimePickerModal
          isVisible={isDatePickerVisible}
          mode="date"
          onConfirm={handleDateSelection}
          onCancel={hideDatePicker}
        />
      </View>
    </View>
  )

Has anyone else seen this behaviour? Or can anyone suggest what I can do about it?

1 Answers

UIDatePicker now has a property called datePickerStyle. You can choose between .compact and .inline - both new to iOS 14 - or .wheel, which is the old style we have known for over a decade.

link

you are viewing the default .compact style

react-native-modal-datetime-picker library have fixed this issue

check your library version and update library version >9.0.0

Fix support of iOS 14 by defaulting the community datetimepicker display to "display" (you can still manually override it if needed).

https://github.com/mmazzarolo/react-native-modal-datetime-picker/releases/tag/v9.0.0

Note : You need at least @react-native-community/datetimepicker@3.0.0 for this version to work correctly.

shortcut solution without update . Add in AppDelegate.m (but it has alignment issue)

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