React Native Date Picker With Custom Modal

It’s common to see the date picker on a page form in the mobile app containing one or more date fields. Whether it’s a person’s date of birth, flight time, a certificate’s expiration date, or the scheduled date of a meeting, you want to ensure the user is providing a valid date.

In addition, a date picker is a useful addition to a form that displays a calendar along with a date entry field, making it easier for app users to schedule events or fill out registration forms.

Most major packages downgrade the date input type for the user to a text input, causing problems in both UI rendering and data formatting. As a result, when a user enters text, formatting problems with the data can occur.

For example, the lack of user information with different date formats worldwide can lead to difficulties in data processing, leading to an error message in the applications.

Choosing The Right Library For A React Native Date Picker

When operating with React Native, applying an external, middle library is frequently vital, so it’s vital to be considerate in selecting the perfect one. When deciding whether to include a third-party library in an app you’re working on, consider the following four criteria: GitHub stars, Activity, Main maintainer, and README file.

Why Use React Native Date Picker ?

In recent days react-native upgrading its latest version of 0.69, but according to this version, all the packages are not upgrading. Some of the libraries are deprecated when searching for a date picker library. Some of the packages are not maintainable as per the recent react-native version, so due to this problem, we have to use a custom date picker to find a different date picker and a good date picker.

Both work on android as well as iOS. During the implementation of the react-native-date picker library, it shows an error that android DatePickerAndroid has been removed from React Native. We found that solution removed and merged with DatePickerIos so that it works only on iOS, not android.

Using @react-native-community/datetimepicker also does not work with the native base because the native base uses a lower version of the @react-native-community/datetimepicker package. Due to these problems, I used a library that was updated nearly that was react-native-date-picker and created a custom modal for UI for iOS and android.

Installation

1. Packages can be downloaded using npm or yarn.

npm install react-native-date-picker

yarn add react-native-date-picker

2. Set up pods.

cd ios && pod install

3. Recreate the project.

npm react-native run-android

npm react-native run-ios

Let’s start with the implementation by Importing necessary packages and parameters, etc.

React Native Date Picker Installation

On import, we have to import Date Picker from the react-native-date-picker package.

Custom Date Picker Component

React Native Date Picker :Custom Date Picker ComponentOn react-native-date-picker, we have to set the mode for getting date view inside our custom  date picker, and date props always the recent date and when we select a new date that was replaced with the selected date.

Custom Modal Component

On UI Prospective we have used modal to show the same UI inside our android and iOS app. and that modal was not provided by that library.

React Native Date Picker: Custom Modal Component

Full Component Of Custom Date-Picker

React Native Date Picker: Full Component Of Custom Date-Picker

 Styles Component

 React Native Date Picker: Styles Component

For a better UI experience we have used here custom styles.

Here are Some Screenshots:

Props For Using Custom Component

  • No need to use everywhere inside the project.
  • Gives better understanding.
  • Make UI user-friendly.
coma

Conclusion

In this blog, we saw and implemented the custom date picker and how to use our projects and props and cons of using a custom date picker.

 

Satyabrata D

Software Engineer

Satyabrata is a React Native Developer with around 2.8+ years of experience in developing mobile applications. Skills like developing clean and reusable code, Creating responsive Mobile pages, API integration etc. 

Keep Reading

Keep Reading

Struggling with EHR integration? Learn about next-gen solutions in our upcoming webinar on Mar 6, at 11 AM EST.

Register Now

Let's create something together!