FaridSafi / react-native-gifted-form

📝 « One React-Native form component to rule them all »
MIT License
1.44k stars 214 forks source link

Add generic "RowValueWidget" that just displays the given value #100

Closed frmdstryr closed 7 years ago

frmdstryr commented 7 years ago

Useful for implementing widgets with custom handlers using onPress. For example, a DatePickerAndroid implementation can be done via:


<GiftedForm.RowValueWidget
  title='Date of birth'
  name='dateOfBirth' // mandatory
  displayValue='dateOfBirth'
  image={<Icon name={tk+'-calendar'} size={iconSize} style={styles.icon} />}
  value={this.state.dateOfBirth}
  onPress={() => {
    DatePickerAndroid.open({
      date: (this.state.dateOfBirth)? Date.parse(this.state.dateOfBirth): new Date(),
      maxDate: new Date(),
      mode: 'spinner',
    }).then((r)=>{
      if (r.action !== DatePickerAndroid.dismissedAction) {
                      // Selected year, month (0-11), day
      this.setState({dateOfBirth:`${r.month}/${r.day}/${r.year}`});
    }
    }).catch((code,message)=>console.warn('Cannot open date picker', message));
}}
/>

With this widget.

frmdstryr commented 7 years ago

output