我一直在寻找这个问题的解决方案已经有一段时间了,现在找不到任何解决它的方法。
这是我想完成的事情。我正在创建一个带有登录屏幕的应用程序。登录屏幕不能有导航栏,但必须在登录后导航到一个导航栏,该导航栏带有从登录组件传递的自定义标题(用户名)。
当应用加载时,app组件将被标准的react Navigator组件加载,该组件依次呈现Login组件。当Login组件呈现时,它将检查以前的会话,并将用NavigatorIOS组件呈现主应用程序(Wrapper组件),该组件依次呈现另一个组件(List组件,未在下面的代码中显示)。
这可能吗?如果有,如何:)
我有以下代码:
// The first main component,
// this will be loaded from the AppRegistry
var App = React.createClass({
render() {
return (
<Navigator
initialRoute={{
component: Login
}}
renderScene={(route, navigator) => {
return React.createElement(route.component, { navigator });
}} />
)
}
});
// The login component that
// renders and handles all login processes.
var Login = React.createClass({
componentDidMount() {
// ... login logic ...
this.props.navigator.replace({
component: Wrapper,
// I want to pass a title here
});
},
render() {
return (
<Text>Login page</Text>
)
}
});
// When logged in, the NavigatorIOS component will be
// shown, here is where I want to title previously passed
// from the login component.
var Wrapper = React.createClass({
render() {
return (
<NavigatorIOS
initialRoute={{
component: List
title: // I want to fetch the title here
}} />
)
}
});
var Login = React.createClass({
componentDidMount() {
// ... login logic ...
this.props.navigator.replace({
component: Wrapper,
componentConfig : {
title : "My New Title"
}
// I want to pass a title here
});
},
render() {
return (
<Text>Login page</Text>
)
}
});
// When logged in, the NavigatorIOS component will be
// shown, here is where I want to title previously passed
// from the login component.
var Wrapper = React.createClass({
render() {
return (
<NavigatorIOS
initialRoute={{
component: List
title: this.props.title
}} />
)
}
});