React Native Modal Datetime Picker

18.0.0 · active · verified Sun Apr 19

react-native-modal-datetime-picker is a declarative, cross-platform library that provides a unified user and developer experience for showing native date and time pickers within a modal in React Native applications. It is currently at stable version 18.0.0 and actively maintained, with frequent releases addressing bug fixes, new features, and breaking changes. This library acts as a wrapper around the `@react-native-community/datetimepicker` package, leveraging the underlying native module for iOS and Android while abstracting it into a convenient modal component. Its key differentiator is providing a modal overlay for the native pickers, which can be useful for applications requiring a clear, focused date/time selection interface, integrating seamlessly with both non-Expo and Expo projects.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates how to integrate `DateTimePickerModal` to pick a date, manage its visibility with state, and handle confirmation or cancellation. Includes basic styling and platform-specific display options.

import React, { useState } from "react";
import { Button, View, Text, Platform } from "react-native";
import DateTimePickerModal from "react-native-modal-datetime-picker";

const DatePickerExample = () => {
  const [isDatePickerVisible, setDatePickerVisibility] = useState(false);
  const [selectedDate, setSelectedDate] = useState(new Date());

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

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

  const handleConfirm = (date) => {
    console.log("A date has been picked: ", date.toISOString());
    setSelectedDate(date);
    hideDatePicker();
  };

  return (
    <View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
      <Text style={{ marginBottom: 20 }}>Selected Date: {selectedDate.toDateString()}</Text>
      <Button title="Show Date Picker" onPress={showDatePicker} />
      <DateTimePickerModal
        isVisible={isDatePickerVisible}
        mode="date"
        date={selectedDate} // Set initial date
        onConfirm={handleConfirm}
        onCancel={hideDatePicker}
        headerTextIOS="Pick a Date"
        cancelTextIOS="Cancel"
        confirmTextIOS="Confirm"
        pickerContainerStyleIOS={{ backgroundColor: 'white' }} // Example iOS styling
        textColor="#000" // Example Android styling
        display={Platform.OS === 'ios' ? 'spinner' : 'default'} // Control picker display style
      />
    </View>
  );
};

export default DatePickerExample;

view raw JSON →