GithubHelp home page GithubHelp logo

sjaq / react-native-modal-datetime-picker Goto Github PK

View Code? Open in Web Editor NEW

This project forked from mmazzarolo/react-native-modal-datetime-picker

0.0 1.0 0.0 756 KB

A React-Native datetime-picker for Android and iOS

License: MIT License

Python 9.55% Java 7.17% JavaScript 57.69% Objective-C 25.60%

react-native-modal-datetime-picker's Introduction

react-native-modal-datetime-picker

A react-native datetime-picker that works on both Android and iOS.

Description

This library exposes a cross-platform interface for showing the native date and time pickers inside a modal.
You will have an unified user experience, you won't have to worry anymore about testing the device platform and you won't have to programmatically call the Android TimePicker/DatePicker APIs.

Setup

This library is available on npm, install it with: npm install --save react-native-modal-datetime-picker.

GIFs!

Usage

import React, { Component } from 'react';
import { Text, TouchableOpacity, View } from 'react-native';
import DateTimePicker from 'react-native-modal-datetime-picker';

export default class DateTimePickerTester extends Component {
  state = {
    isDateTimePickerVisible: false,
  };

  _showDateTimePicker = () => this.setState({ isDateTimePickerVisible: true });

  _hideDateTimePicker = () => this.setState({ isDateTimePickerVisible: false });

  _handleDatePicked = (date) => {
    console.log('A date has been picked: ', date);
    this._hideDateTimePicker();
  };

  render () {
    return (
      <View style={{ flex: 1 }}>
        <TouchableOpacity onPress={this._showDateTimePicker}>
          <Text>Show TimePicker</Text>
        </TouchableOpacity>
        <DateTimePicker
          isVisible={this.state.isDateTimePickerVisible}
          onConfirm={this._handleDatePicked}
          onCancel={this._hideDateTimePicker}
        />
      </View>
    );
  }

}

Available props

Name Type Default Description
cancelTextIOS string 'Cancel' The text on the cancel button on iOS
confirmTextIOS string 'Confirm' The text on the confirm button on iOS
customCancelButtonIOS node A custom component for the cancel button on iOS
customConfirmButtonIOS node A custom component for the confirm button on iOS
customTitleContainerIOS node A custom component for the title container on iOS
datePickerContainerStyleIOS style The style of the container on iOS
date obj new Date() Initial selected date/time
isVisible bool false Show the datetime picker?
mode string 'date' Datepicker? 'date' Timepicker? 'time' Both? 'datetime'
datePickerModeAndroid string 'calendar' Display as 'spinner' or 'calendar'
onConfirm func REQUIRED Function called on date picked
onCancel func REQUIRED Function called on dismiss
titleIOS string 'Pick a date' The title text on iOS
minimumDate Date undefined Min Date
maximumDate Date undefined Max Date
is24Hour bool true If false, the picker shows an AM/PM chooser on Android

All the DatePickerIOS props are also supported!

Notes

Just remember to always set the isVisible prop to false in both onConfirm and onCancel (like in the example above).

Under the hood this library is using react-native-animated-modal for the iOS modal implementation.

Pull requests and suggestions are welcome!

react-native-modal-datetime-picker's People

Contributors

corymsmith avatar geekvijay avatar kapilratnani avatar mj0826 avatar mmazzarolo avatar nikolaiwarner avatar sjaq avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.