react-native-datepicker icon indicating copy to clipboard operation
react-native-datepicker copied to clipboard

onPressCancel not working on Android

Open YogendraShelke opened this issue 6 years ago • 2 comments

Issue

For android onPressCancel method is not working.

Expected Behavior

On calling onPressCancel calendar pop up should be closed.

Code

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

export default class Patient extends Component {

  state = { date: "2018-08-30" }

  componentDidMount() {
    this.datePicker.onPressDate()
    setTimeout(() => {
      this.datePicker.onPressCancel()
    }, 5000)
  }

  render() {
    return (
      <View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
        <DatePicker
          style={{ width: 200 }}
          date={this.state.date}
          mode="date"
          duration={0}
          placeholder="select date"
          format="YYYY-MM-DD"
          confirmBtnText="Confirm"
          ref={ref => this.datePicker = ref}
          cancelBtnText="Cancel"
          onDateChange={(date) => { this.setState({ date: date }) }}
        />
      </View>
    );
  }
}

Environment

  1. react-native -v: 0.56.0
  2. node -v: 8.11.4
  3. npm -v: 5.6.0
  4. yarn --version: NA
  5. target platform: Android
  6. operating system: macOS High Sierra

YogendraShelke avatar Aug 30 '18 13:08 YogendraShelke

The same issue

hoanglm4 avatar Oct 11 '19 07:10 hoanglm4

This worked for me. componentDidMount() {

this.listeners = [ addListener(‘didFocus’, () => { console.log(“didFocus”) }), addListener(‘willBlur’, () => { console.log(“willBlur “) this.datePicker.onPressCancel() }), ] }

mushtaque87 avatar Apr 12 '20 12:04 mushtaque87