朋友,当用户单击组件(视图)必须隐藏并再次单击应该显示的按钮时,我在运行时遇到隐藏和显示问题。
我的代码:
constructor(props) {
super(props);
this.state = {
isModalVisible : false,
};
}
callFunc(){
if(this.isModalVisible){
this.setState({isModalVisible:false});
}else{
this.setState({isModalVisible:true});
}
}
render() {
return (
<View style = {styles.companyScroll}>
<Button
onPress={this.callFunc}
title="Learn More"
color="#841584"
accessibilityLabel="Learn more about this purple button"
/>
{this.state.isModalVisible && <Picker style ={{backgroundColor : 'white'}}
selectedValue={this.state.language}
onValueChange={(itemValue, itemIndex) => this.setState({language: itemValue})}>
<Picker.Item label="Java" value="java" />
<Picker.Item label="JavaScript" value="js" />
</Picker>
</View>
)
}
我想喜欢下面的图片。