xgfe / react-native-datepicker

react native datePicker component for both Android and IOS, useing DatePikcerAndroid, TimePickerAndroid and DatePickerIOS
MIT License
2.12k stars 725 forks source link

Add props for setModalVisible #229

Open Alver23 opened 6 years ago

Alver23 commented 6 years ago

Issue

it is possible that the calendar can be automatically after calling the component

Expected Behavior

Code

Environment

  1. react-native -v: 0.49.5
  2. node -v: 8.9.1
  3. npm -v: 5.6.0
  4. yarn --version: 1.3.2
  5. target platform: Android | iOS
  6. operating system: Window 10 64 bits
349989153 commented 6 years ago

automatically what?

Alver23 commented 6 years ago

the calendar should receive a prop so that it opens automatically without having to press on the icon or the text box and be able to position the icon on the left or right side

349989153 commented 6 years ago

it opens automatically without having to press on the icon or the text box

I think there is a workaround, by using the ref api of a React Component:

<DatePicker
  date={this.state.birthday}
  mode="date"
  placeholder=" "
  format="YYYY-MM-DD"
  onDateChange={birthday => {
    this.changeBirthday(birthday);
  }}
  ref={datePicker => this.datePicker = datePicker}
/>

and when I call it's onPressDate function in the componentDidMount hook method, it "automatically" show up without pressing anything:

componentDidMount() {
  if (this.datePicker) {
    this.datePicker.onPressDate();
  }
}

and be able to position the icon on the left or right side

What I try to do here is to shut the icon down, an render a icon myself:

<View style={styles.row}>
  <Icon /> /* just style this icon wherever you want */
  <DatePicker
    date={this.state.birthday}
    mode="date"
    placeholder=" "
    onDateChange={birthday => {
      this.changeBirthday(birthday);
    }}
    showIcon={false}
  />
</View>
Alver23 commented 6 years ago

thank you very much, I will try the solution provided