我已经检查过堆栈溢出或gihub上类似的现有问题,例如: NavigationCard will only re-render when the route changes,Help: renderScene is executed just once and does not refresh updated props等。但我的情况有所不同。
网页列表
过渡逻辑:
我的实施
我创建了一个名为App的顶级组件,代码如下所示:
// app.js
class App extends Component {
componentWillMount() {
const {doNavigateReplaceAtIndex} = this.props;
let {isSignedIn} = this.props;
doNavigateReplaceAtIndex(isSignedIn? 'home': 'sign-in');
}
render() {
const {globalNavigationState} = this.props;
return (
<NavigationCardStack
navigationState={globalNavigationState}
style={styles.container}
onNavigate={()=>{}}
renderScene={this._renderScene}
/>
);
}
_renderScene({scene}) {
const { route } = scene;
switch(route.key) {
case 'home':
return <Home />
case 'sign-in':
return <SignIn />
}
}
}
export default connect (
state =>({
isSignedIn: !! state.auth.token,
token: state.auth.token,
globalNavigationState: state.globalNavigation
}),
dispatch => ({
doNavigateReplaceAtIndex: (key) => dispatch(navigateReplaceAtIndex(0, key))
})
)(App);
// sign in page
// after signin, it will doNavigateReplaceAtIndex(0, 'home');
// home page
// after clicking "sign out", it will doNavigateReplaceAtIndex(0, 'sign-in');
// doNavigateReplaceAtIndex basically is just call NavigationStateUtils.replaceAtIndex
症状 一开始,它显示登录页面,登录后,它转到主页,这是好的。在主页中,单击“注销”按钮时,它不会移动到任何位置,但在刷新时,它会显示登录页面。
到目前为止我得到了什么
欢迎任何帮助,谢谢。
我的环境
原生反应:0.29.1 反应原生cli:1.0.0 节点:5.6.0 操作系统:ios 9.3