# react-native-dateandtime

> A date and time picker for react-native support for android and ios

Latest version **0.1.6** (published 2018-06-14) · ISC license · 0 weekly downloads

## Install

```sh
npm install react-native-dateandtime
pnpm add react-native-dateandtime
yarn add react-native-dateandtime
bun add react-native-dateandtime
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.6 |
| Published | 2018-06-14 |
| First published | 2018-06-13 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 23.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | wrp |
| Maintainers | wrp |
| Keywords | react-native, android, ios, datetime, datepicker, date |

## Links

- npm: https://www.npmjs.com/package/react-native-dateandtime
- npm.io page: https://npm.io/package/react-native-dateandtime

## Alternatives

- [@js-joda/timezone](https://npm.io/package/@js-joda/timezone.md) — 383.4K weekly downloads
- [chartjs-adapter-moment](https://npm.io/package/chartjs-adapter-moment.md) — 210.8K weekly downloads
- [strftime](https://npm.io/package/strftime.md) — 171.2K weekly downloads
- [vue-flatpickr-component](https://npm.io/package/vue-flatpickr-component.md) — 115.8K weekly downloads
- [timepicker](https://npm.io/package/timepicker.md) — 51.0K weekly downloads

## Recent versions

- 0.1.6 (latest) — 2018-06-14
- 0.1.5 — 2018-06-14
- 0.1.4 — 2018-06-14
- 0.1.3 — 2018-06-14
- 0.1.2 — 2018-06-14
- 0.1.0 — 2018-06-13
- 0.0.1 — 2018-06-13

## README

# React Native DateTime
A datetime-picker for react-native support for android and ios(base on @remobile/react-native-datetime-picker)

## Installation
```sh
npm install react-native-dateandtime --save
```

### Installation (iOS)
* not need install, on ios use js write

### Installation (Android)
* In `android/settings.gradle`
```gradle
...
include ':react-native-dateandtime'
project(':react-native-dateandtime').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-dateandtime/android')
```

* In `android/app/build.gradle`

```gradle
...
dependencies {
    ...
    compile project(':react-native-dateandtime')
}
```

* register module

import com.wrp.datetime.*;  // <--- import

public class MainActivity extends ReactActivity {
  ......

  /**
   * A list of packages used by the app. If the app uses additional views
   * or modules besides the default ones, add more packages here.
   */
    @Override
    protected List<ReactPackage> getPackages() {
      return Arrays.<ReactPackage>asList(
        new DateTimePickerPackage(), // <------ add here
        new MainReactPackage());
    }
}
```



## Usage
use as follows:
```js
<DateTimePicker ref={(picker)=>{this.picker=picker}}/>
...
this.picker.showDatePicker(...)
this.picker.showTimePicker(...)
this.picker.showDateTimePicker(...)
```
* on ios, make sure <DateTimePicker> must on topest view


###Example
```js
import React, { Component } from 'react';
import {
  Platform,
  StyleSheet,
  Text,
  View,
  Button
} from 'react-native';
import DateTimePicker from 'react-native-dateandtime'
const instructions = Platform.select({
  ios: 'Press Cmd+R to reload,\n' +
    'Cmd+D or shake for dev menu',
  android: 'Double tap R on your keyboard to reload,\n' +
    'Shake or press menu button for dev menu',
});

type Props = {};
export default class App extends Component<Props> {
  onButtonPress(){
    alert("点击了")
  }
  showTimePicker(){
    var startDate = new Date();
    this.picker1.showTimePicker(startDate, (d)=>{//d=>Date

    });
  }
  showDatePicker(){
    var startDate = new Date();
    this.picker2.showDatePicker(startDate, (d)=>{

    });
  }

  render() {
    return (
      <View style={styles.container}>
        <Text title="Press Me" style={styles.instructions}>
        </Text>
        <Button  title='button1' onPress={(data)=>{this.showTimePicker()}}/>
        <DateTimePicker
          theme="1"
          ref={(picker)=>{this.picker1=picker}}/>
        <Button  title="button2" onPress={(data)=>{this.showDatePicker()}}/>
        <DateTimePicker
          theme="3"
          ref={(picker)=>{this.picker2=picker}}/>
      </View>
    );
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: '#F5FCFF',

  },
  welcome: {
    fontSize: 20,

    margin: 10,
  },
  instructions: {
    textAlign: 'center',
    color: '#333333',
    marginBottom: 5,
  },
});
```

### Methods

* showDatePicker(date, callback(date))
* showTimePicker(date, callback(date))
* showDateTimePicker(date, callback(date))

---
_Source: https://npm.io/package/react-native-dateandtime · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
