Javascript 反应本机-更新头
我使用本机基址进行UI,使用react本机路由器流量进行导航 我将家庭场景定义为:Javascript 反应本机-更新头,javascript,android,ios,react-native,header,Javascript,Android,Ios,React Native,Header,我使用本机基址进行UI,使用react本机路由器流量进行导航 我将家庭场景定义为: <Scene key="root" > <Scene key="drawer" component={NavigationDrawer} open={false} type={ActionConst.RESET} hideNavBar={true} > <Scene key="home" component={Search} initial
<Scene key="root" >
<Scene key="drawer" component={NavigationDrawer} open={false} type={ActionConst.RESET} hideNavBar={true} >
<Scene key="home" component={Search} initial={true} hideNavBar={true} />
</Scene>
</Scene>
当用户单击搜索图标时,我更新状态
const newState=update(this.state,{
searchActive: {$set: true}
})
this.setState(newState);
然后在render method中,我根据当前状态渲染标头,因此:
render(){
const { searchActive} = this.state;
let header=null;
if (searchActive) {
header=<SearchHeader onBack={this.onMenuShow} />
} else {
header=<MenuHeader onSearch={this.onSearchShow} />;
}
return (
<Container>
{header}
<Content >
</Content>
</Container>
);
}
render(){
const{searchActive}=this.state;
让header=null;
如果(搜索活动){
标题=
}否则{
标题=;
}
返回(
{header}
);
}
问题是状态被更新了,但随后有东西再次调用构造函数并挂载新的主场景,因此标头永远不会更改。我怀疑react native router flux正在调用construtor,但我不明白为什么???如果再次调用构造函数,可能是因为父级的状态已更改,并且正在重新呈现其子级。如果再次调用构造函数,这可能是因为父对象的状态已更改,并且正在重新呈现其子对象。
render(){
const { searchActive} = this.state;
let header=null;
if (searchActive) {
header=<SearchHeader onBack={this.onMenuShow} />
} else {
header=<MenuHeader onSearch={this.onSearchShow} />;
}
return (
<Container>
{header}
<Content >
</Content>
</Container>
);
}