how to open DatePicker on Button Click in React Native

react native date picker
react-native datepicker dark mode
open picker on button click react native
react native year picker
react-native datepicker disable date
react-native datepicker only year
custom date picker in react native
unable to resolve module react-native-datepicker

I wanted to know how we can display datepicker on button click in react native. I have tried various solutions still no success,Any help would be helpful. thank you.

Below is what i tried

import React, { Component } from 'react';
import {
Platform,
StyleSheet,
View,DatePicker
} from 'react-native';

This is my render method

render(){
    return(
        <TouchableOpacity
        onPress={() => this.datePicker.onPressDate()}>
        <Text>
         Hello Date
        </Text>
    </TouchableOpacity>

  <DatePicker
    style={{width: 200}}
    ref={(picker) => { this.datePicker = picker; }}
    date={this.state.date}
    mode="date"
    placeholder="Select date"
    format="YYYY-MM-DD"
   minDate="2016-05-01"
   maxDate="2020-12-12"
   confirmBtnText="OK"
   cancelBtnText="Cancel"
   onDateChange={(date) => {this.setState({date: date})}}

    />     
    );
}

whenever i run i get below error enter image description here

I Suggest to use react-native-datepicker library for Date Picker. It will give you more customizing options and is compatible with both platforms i.e Android and iOS.

Below is the sample code that i have used in one of my application:-

<View style={{ backgroundColor: 'transparent', margin: 5 }}>
            <DatePicker date={this.state.date} showIcon={false} placeholder="Birthday" mode="date" format="DD-MM-YYYY"
              customStyles={{
                dateInput: {
                  borderWidth: 0,
                  height: 50,
                  width: 170,
                  right: 30,
                },
                dateText: {
                  marginTop: 5,
                  color: 'white',
                  fontSize: 18,
                },
                placeholderText: {
                  marginTop: 5,
                  right: 10,
                  color: 'white',
                  fontSize: 18,
                }
              }
              }
              onDateChange={(date) => { this.setState({ date: date }) }} placeholderTextColor="white" underlineColorAndroid={'rgba(0,0,0,0)'} style={{ height: 50, width: 170, paddingLeft: 15, borderRadius: 4, backgroundColor: 'rgba(0,0,0,0.4)' }}></DatePicker>
          </View>

You can find the library HERE

how to open DatePicker on Button Click in React Native, I Suggest to use react-native-datepicker library for Date Picker. It will give you more customizing options and is compatible with both platforms  Issue Hi, I am unable to open date picker manually. Please provide solution for this problem. I am sharing code snippet below. Code openDatePicker(date, mode, format, index) { this.setState({ datePickerDate: date, datePickerMode: mode, d

You can simply have flag whether render picker component or not and switch it on Press. Something like this

render() {
  return (
    <View>
      <TouchableOpacity
        onPress={() => this.setState({ picker: !this.state.picker })}>
        <Text>Hello Date</Text>
      </TouchableOpacity>
      {this.renderPicker()}
    </View>
  );
}

renderPicker() {
  if (this.state.picker) {
    return (
      <DatePicker
        style={{ width: 200 }}
        ref={picker => {
          this.datePicker = picker;
        }}
        date={this.state.date}
        mode="date"
        placeholder="Select date"
        format="YYYY-MM-DD"
        minDate="2016-05-01"
        maxDate="2020-12-12"
        confirmBtnText="OK"
        cancelBtnText="Cancel"
        onDateChange={date => {
          this.setState({ date: date });
        }}
      />
    );
  }
}

How to open date picker manually · Issue #196 · xgfe/react-native , Issue Hi, I am unable to open date picker manually. and I am calling this method (openDatePicker) on row click. Environment. react-native -v : 0.47.1; node -v :6.2.1; npm -v :4.2.0; target platform : Android; operating system : windows 10 64 bit I'd like to display the date picker from my custom button. npm install react-native-datepicker --save. This command will copy all the dependencies into your node_module directory. –save is optional, It updates the react-native-datepicker dependency in your package.json file. Code for React Native Date Picker. Now Open App.js in any code editor and replace the code with the following code. App.js

Give a look at this package react-native-modal-datetime-picker it's work for the cross platform and has a perfect design and highly customizable.

https://github.com/mmazzarolo/react-native-modal-datetime-picker

DatePickerDialog – how to open Material-UI's DatePicker with a , You have to click that input field to open the DatePicker, and the input field will display to open the DatePicker with a regular button click, or by focusing the button and import * as Dom from 'react-dom'; import * as React from 'react'; import  Contents in this project React Native Common DatePicker for Android and iOS tutorial : 1. Start a fresh React Native project. If you don’t know how then read my this tutorial. 2. Add react-native-datepicker-dialog library inside your project : Open Your project in command prompt and execute below command inside your project’s folder.

DatePickerAndroid · React Native, Opens the standard Android date picker dialog. Example. try { const { action, year​, month, day } = await DatePickerAndroid.open({ // Use `new Date()` for current  Contents in this project Open Navigate to Another Activity on Button Click in React Native App : 1. Start a fresh React Native project. If you don’t know how then read my this tutorial. 2. Read our Previous tutorial to Add New Activity in Existing React Native Project. 3. Import react-navigation library in your project using using NPM server.

react-native-datepicker-dialog, react-native-datepicker-dialog. This library provides the cross-platform components for to open the date picker dialogs in an effective way. The Modal component is a basic way to present content above an enclosing view. Note: If you need more control over how to present modals over the rest of your app, then consider using a top-level Navigator. The visible prop determines whether your modal is visible. The supportedOrientations prop allows the modal to be rotated to any of the

React Native Date Picker, –save is optional, It updates the react-native-datepicker dependency in your package.json file. Code for React Native Date Picker. Now Open App.js in any code  Hi, Can I only show DatePicker Icon? and hide the input box ?