beefe / react-native-actionsheet

An elegant ActionSheet component for React Native.
MIT License
1.35k stars 343 forks source link

get selectedValue not only the index #100

Open aasalshehhi opened 4 years ago

aasalshehhi commented 4 years ago

Hi, I am using react-native-actionsheet to show dropdown in iOS, I was able to get the selected index, however, I don't know what is the syntax to get the selected value also.

showActionSheet = () => {
  this.ActionSheet.show()
}

handlePress = (buttonIndex,  option) => {
  this.setState({ selected: buttonIndex, Region: options})
}

     <Text style={styles.inputfields} onPress={this.showActionSheet}>Region</Text>
        <ActionSheet
      ref={o => this.ActionSheet = o}
      title={'Region'}
      options={['east', 'west', 'north', 'south', 'Cancel']}
      cancelButtonIndex={5}
      selectedValue={this.state.Region}
      value={this.state.Region}
      onPress={this.handlePress}
    />
pistou commented 4 years ago

Store your options in a variable then you can access it with the selected index:

const options = ['east', 'west', 'north', 'south', 'Cancel'];
const handlePress = (index) => {
    console.log(index, options[index]);
};

<ActionSheet
    options={options}
    onPress={handlePress}
    ...
    />