[英]How can I use react-native-actionsheet alongside react-native-gifted-chat in the same view?
[英]react-native-actionsheet get selected value
我正在使用 react-native-actionsheet 在 iOS 中顯示下拉列表,我能夠獲取所選索引,但是,我也不知道獲取所選值的語法是什么。
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={['North', 'South', 'East', 'West', 'Cancel']}
cancelButtonIndex={5}
selectedValue={this.state.Region}
value={this.state.Region}
onPress={this.handlePress}
/>
使用您的選項數組創建一個變量
const options = ['AUH', 'DXB', 'NE', 'WR', 'AAN', 'Cancel']
將該變量傳遞給ActionSheet
組件
<ActionSheet
ref={o => (this.ActionSheet = o)}
title={"Region"}
options={options}
cancelButtonIndex={5}
selectedValue={this.state.Region}
value={this.state.Region}
onPress={this.handlePress}
/>;
現在在您的handlePress
您可以訪問您選擇的值,如下所示
handlePress = buttonIndex => {
this.setState({
selected: buttonIndex,
Region: options[buttonIndex]
});
};
希望這對你有幫助。 如有疑問,請放心。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.