react-native-date-picker

repository·master·Indexed 25 days ago

https://github.com/henninghall/react-native-date-picker

A datetime picker for React Native supporting iOS, Android, and Expo. It provides three modes (date, time, and datetime) and can be displayed either as a built-in modal or inlined within a view. Version 5.0.13.

Tokens
3.9K
Snippets
12
Records
26
Agent score
82%

What's inside react-native-date-picker

  1. Use different picker modes: date, time, and datetime

    master

    The component supports three distinct modes to handle different user input requirements:

    • React Native Timepicker: Specifically for selecting time.
    • React Native Datepicker: Specifically for selecting a date.
    • React Native Datetimepicker: For selecting both date and time simultaneously.
  2. Choose between Modal and Inlined picker modes

    master

    The react-native-date-picker component offers two primary ways to display the picker UI:

    1. Modal: Uses the built-in modal provided by the library. This is the standard way to present a picker that overlays the current screen.
    2. Inlined: The picker is rendered directly within a view or a custom-made modal. This is useful when you want to embed the picker as part of a larger form or a specific section of your UI.
  3. Change date order and 12/24h format using locale

    master

    The locale prop is the primary way to control the visual formatting of the picker:

    • Date Order: The order of year, month, and day (e.g., YYYY-MM-DD vs DD-MM-YYYY) is determined by the locale. For example, locale='fr' sets the French preference.
    • 12/24h Format (iOS): Determined by the locale prop.
    • 12/24h Format (Android): By default, Android uses the device setting. To force the picker to follow the locale setting instead of the device setting, add the is24hourSource="locale" prop.

    Note: Changing the locale only affects the date/time formatting; it does not change the language of the title, confirm button, or cancel button texts.

  4. Link react-native-date-picker in your project

    master

    The package supports automatic linking. For most setups, you only need to install the package and its cocoapods dependencies, then rebuild the project using react-native run-ios or react-native run-android.

    If you are using a React Native version below 0.60 or encounter issues with automatic linking, you can manually link the package by running:

    npx react-native link react-native-date-picker

    npx react-native link react-native-date-picker
  5. Change the font size on Android

    master

    To change the font size of the date picker on Android, you must modify your project's styles.xml file. Add the following style block immediately above the closing </resources> tag.

    Note: Changing the font size on iOS is not supported out of the box.

    <style name="DatePickerTheme" parent="DatePickerBaseTheme">
        <item name="android:textSize">25sp</item>
    </style>
  6. Run the React Native example project

    master

    To run the provided React Native example (Rn073), you must first ensure your environment is set up according to the React Native Environment Setup guide. The process involves starting the Metro bundler and then launching the application on an emulator or simulator.

    1. Start the Metro Server

    Run this from the root of the project to start the JavaScript bundler:

    npm start
    # OR
    yarn start

    2. Start the Application

    Open a new terminal and run the command corresponding to your target platform:

    For Android:

    npm run android
    # OR
    yarn android

    For iOS:

    npm run ios
    # OR
    yarn ios
    npm start
    
    # In a new terminal
    npm run android
  7. Reload the application to see changes

    master

    After modifying your code (e.g., in App.tsx), use the following methods to reload the app and apply changes:

    • Android: Press the <kbd>R</kbd> key twice or open the Developer Menu (<kbd>Ctrl</kbd> + <kbd>M</kbd> on Windows/Linux or <kbd>Cmd ⌘</kbd> + <kbd>M</kbd> on macOS) and select "Reload".
    • iOS: Press <kbd>Cmd ⌘</kbd> + <kbd>R</kbd> within the iOS Simulator.
  8. Configure iOS pods and rebuild the project

    master

    For non-Expo projects, you must install the CocoaPods after downloading the package and then rebuild the application. If you are using an Expo project, skip the pod install step and use the Expo run commands to rebuild.

    # Install pods (skip for expo projects)
    cd ios && pod install
    
    # Rebuild for expo projects
    npx expo run:android
    npx expo run:ios
    
    # Rebuild for non-expo projects
    npx react-native run-android
    npx react-native run-ios