React native 组件微调器不工作

React native 组件微调器不工作,react-native,progress-bar,components,React Native,Progress Bar,Components,我创建了一个组件调用微调器,以便: //spinner.js import React,{Component}来自'React'; 进口{ 形象 样式表, 看法 文本 键盘避免了gView, 触控高光, 情态动词 按钮 活动指示器, }从“反应本机”; 导出默认类微调器扩展组件{ 建造师(道具){ 超级(道具); 这个州={ 可见:this.props.visible }; this.\u show=this.\u show.bind(this); this.\u hide=this.\u hi

我创建了一个组件调用微调器,以便:

//spinner.js

import React,{Component}来自'React';
进口{
形象
样式表,
看法
文本
键盘避免了gView,
触控高光,
情态动词
按钮
活动指示器,
}从“反应本机”;
导出默认类微调器扩展组件{
建造师(道具){
超级(道具);
这个州={
可见:this.props.visible
};
this.\u show=this.\u show.bind(this);
this.\u hide=this.\u hide.bind(this);
}
render(){
返回(
);
}
_show(){
this.setState({visible:true});
}
_隐藏(){
this.setState({visible:false});
}
}
在本例中,创建方法_show()和_hide()

但当从其他类调用时不工作,我从类Login.js调用

类登录扩展组件{
建造师(道具){
超级(道具)
this.state={visible:false};
}
_onLoginPress(){
这个.Spinner.\u show()
)
}  
_重定向(){
这个.Spinner.\u hide()
}
render(){
返回(
看得见的
看不见
)
}
当在构造函数中设置为true时,它将显示,但当在构造函数中设置为false时,它不会显示,当按下按钮时,它会显示,当按下按钮时,它不会显示重定向()。

要正确使用
引用,必须

this.Spinner=ref}visible={this.state.visible}/>

然后你的
this.Spinner.\u show()
this.Spinner.\u hide()
应该可以工作。

为什么不直接将“可见”属性传递给微调器组件中的模式,并在登录组件中更新可见状态,而不是调用显示和隐藏?如果可以,通常最好避免使用refs,而使用state和peops。