javascript - React-Native 将标题从 Navigator 传递到 NavigatorIOS

标签 javascript title react-native navigator

我已经寻找这个问题的解决方案很长一段时间了,但找不到任何解决它的方法。

这就是我想要完成的事情。 我正在创建一个带有登录屏幕的应用程序。登录屏幕不能有导航栏,但必须在登录后导航到带有导航栏的组件,该导航栏具有从登录组件传递的自定义标题(用户名)。

当应用程序加载时,App组件将加载标准的react Navigator组件,该组件又渲染Login组件。当 Login 组件呈现时,它将检查以前的 session ,并使用 NavigatorIOS 组件呈现主应用程序(Wrapper 组件),而 NavigatorIOS 组件又呈现另一个组件(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
                }} />
        )
    }
});

关于javascript - React-Native 将标题从 Navigator 传递到 NavigatorIOS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32906643/

相关文章:

javascript - 错误消息 : document. 在 JSFiddle 中不允许写入

iphone - MKAnnotation:iOS 5.0 中的标题

C++:有 unicode 控制台标题..?

react-native - 为 react-navigation DrawerNavigator 设置滑动区域宽度

reactjs - 类型 'TaskListProps[]' 不可分配给类型 TaskListProps

javascript - 如何从 Firebase 数据快照中检索数据

javascript - 在循环中调用时 splice 不会删除元素

javascript - 将具有动态变量数的参数对象转换为多个参数

javascript - 如何编辑 javascript 计时器显示样式

ios - UIWebView 中的警告框标题来自哪里