如何使用React Navigation在React Native中显示标题标题

问题描述 投票:1回答:1

我是新手使用React Native,我有一个问题,使用React Navigation显示/显示标题标题,我试图寻找但失败了所有。

这是我的完整脚本:

Loginscreen.js

class LoginScreen  extends Component {
  static navigationOptions = {
    title: 'Login',
  };
  render() {
    return (
      <View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
        <Text>Login Screen</Text>
        <Button title="Login To" onPress={() => this.props.navigation.navigate('Tabs')} />
        <Button title="Go To Register" onPress={() => this.props.navigation.navigate('Register')} />
      </View>
    );
  }
}

RegisterScreen.js

class RegisterScreen  extends Component {
  static navigationOptions = {
    title: 'Register',
  };
  render() {
    return (
      <View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
        <Text>Register Screen</Text>
        <Button title="Go to Login" onPress={() => this.props.navigation.navigate('Login')} />
      </View>
    );
  }
}

HomeScreen.js

class HomeScreen  extends Component {
  static navigationOptions = {
    title: 'Home',
  };
  render() {
    return (
      <View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
        <Text>Home Screen</Text>
        <Button title="Go to Login" onPress={() => this.props.navigation.navigate('Login')} />
      </View>
    );
  }
}

ProfileScreen.js

class ProfileScreen  extends Component {
  static navigationOptions = {
    title: 'Profile',
  };
  render() {
    return (
      <View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
        <Text>Profile Screen</Text>
        <Button title="Go to Login" onPress={() => this.props.navigation.navigate('Login')} />
      </View>
    );
  }
}

App.js enter image description here

我得到这样的结果:enter image description here

请任何人帮我显示/显示标题标题(红色圆圈),组件登录屏幕和注册中的标题标题很好,但在组件HomeScreen和ProfileScreen中丢失。请帮我显示/显示它。

谢谢。

javascript reactjs react-native react-navigation
1个回答
0
投票

在stacknavigator中定义headerMode: 'screen',

即你的rootStack

const rootStack = createStackNavigator(
{ 

},{
    headerMode: 'screen'
})
© www.soinside.com 2019 - 2024. All rights reserved.