导航器的标题不存在

时间:2018-06-16 23:56:27

标签: javascript reactjs react-native react-native-ios expo

我有以下问题: 我在App.js中创建了新的StackNavigator,在navigationOptions的Login.js中添加了新标题,但是当我通过Expo在我的iPhone上运行应用程序时,我没有看到标题。 我已经尝试更新npm,更新expo,重新安装node_modules,而不是AppRegistry我试图使用Expo.registerRootComponent,但没有任何效果 - 我仍然没有标题。 我该如何解决?

App.js

import React, { Component } from 'react';
import { AppRegistry } from 'react-native';
import { createStackNavigator } from 'react-navigation';
import Login from './src/screens/Login';
import Secured from './src/screens/Secured';
import Register from './src/screens/Register';

export default class ReactNativeStormpath extends Component {

state = {
    isLoggedIn: false
}

render() {
    if (this.state.isLoggedIn)
        return <Secured onLogoutPress={() => this.setState({isLoggedIn: false})} />;
    else
        return <Login onLoginPress={() => this.setState({isLoggedIn: true})} />;
    }
} 

const LifeStorm = createStackNavigator({
    Login: { screen: Login },
    Register: { screen: Register },
    Secured: { screen: Secured },
});

AppRegistry.registerComponent('LifeStorm', () => LifeStorm);

Login.js

import Expo from 'expo';
import React, { Component } from "react";
import { AppRegistry, StyleSheet, Text, TextInput, View, Button } from     "react-native";
import { navigation } from 'react-navigation';

const styles = StyleSheet.create({
    container: {
        flex: 1,
        justifyContent: "center",
        alignItems: "center",
        backgroundColor: "#F5FCFF",
    },
});

export default class Login extends Component {
static navigationOptions = {
    header: { visible:true },
    title: "Log In",
};
render() {
    return (
        <View style={styles.container}>
            <TextInput placeholder="Username" />
            <TextInput placeholder="Password" />
            <Button onPress={this.props.onLoginPress} title="Submit" />
            <Button onPress={this.props.onLoginPress} title = "Register" />
        </View>
    );
 }
 }

 AppRegistry.registerComponent('Login', () => LifeStorm);

0 个答案:

没有答案