1.0.1 • Published 4 years ago

react-native-datetimepicker-modal v1.0.1

Weekly downloads
9
License
MIT
Repository
github
Last release
4 years ago

react-native-datetimepicker-modal

package version package downloads package license make a pull request GitHub issues GitHub forks GitHub stars

React Native DateTimePicker Modal Component for iOS/Android

Table of Contents

Dependency

React Native Community Date/Time Picker (https://github.com/react-native-community/datetimepicker)

Install

$ npm i react-native-datetimepicker-modal
$ # OR
$ yarn add react-native-datetimepicker-modal

Usage

import React, { useState } from 'react';
import moment from 'moment';
import { StyleSheet, Text } from 'react-native';
import DateTimePickerModal from 'react-native-datetimepicker-modal';

const Example = () => {
  const [birthDate, setBirthDate] = useState(new Date());
  const [show, showModal] = useState(false);
  const toggle = () => showModal(!show);
  return (
    <DateTimePickerModal
      value={birthDate}
      onChange={(event, date) => setBirthDate(date)}
      show={show}
      toggle={toggle}
    >
      <Text>Birth Day</Text>
      <Text>
        {birthDate ? moment(birthDate).format('MMMM DD, YYYY') : '-'}
      </Text>
    </DateTimePickerModal>
  );
}

Properties

Component accepts the following properties. Please see propTypes for more detail.

Also, please refer to React Native Community - DateTimePicker's documentation for more details.

children

Component you want to render.

value

Start date for DateTimePicker.

modalButtonText

Text string for the iOS modal button (default: "Done")

Styling

Styling for different sub-components can also be configured, this is only applicable in iOS:

NameDescription
touchableStyleStyles for the container of children
modalButtonStyleStyles for the modal button on iOS
modalBtnContainerStyleStyles for the modal button container on iOS
modalStyleStyles for the modal on iOS
modalOverlayStyleStyles for the modal overlay on iOS

Contribute

  1. Fork it and create your feature branch: git checkout -b my-new-feature
  2. Commit your changes: git commit -am 'Add some feature'
  3. Push to the branch: git push origin my-new-feature
  4. Submit a pull request

License

MIT

Credits

Thanks to @Tiaan for the original idea. I just forked the project to apply the more recent version of RN and DateTimePicker.