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

get selectedValue not only the index

Open aasalshehhi opened this issue 5 years ago • 1 comments

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}
    />

aasalshehhi avatar Jan 19 '20 18:01 aasalshehhi

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}
    ...
    />

pistou avatar Apr 09 '20 08:04 pistou