所以我在React Native Project中跨多个屏幕设置全局标题样式时遇到麻烦。
我已经遵循https://reactnavigation.org/docs/en/headers.html中概述的步骤,但是每次尝试运行它时都会遇到语法错误。
我只是在设置标题背景颜色以及按钮和标题的色调。
我在下面附加了我的代码。...如果有人可以指出我的意思,我做错了,将不胜感激。
[import React, { Component } from 'react';
import { createStackNavigator, createDrawerNavigator } from 'react-navigation';
import {View,Text,StyleSheet,Platform,TouchableOpacity,Image,StatusBar} from 'react-native';
import LoginScreen from '../screens/LoginScreen';
import HomeScreen from '../screens/HomeScreen';
import ProfileScreen from '../screens/ProfileScreen';
import CharityScreen from '../screens/CharityScreen';
import RunScreen from '../screens/RunScreen';
const DrawerNavigator = createDrawerNavigator({
Home: {
screen: HomeScreen
},
Profile: {
screen: ProfileScreen
},
Charity: {
screen: CharityScreen
},
Run: {
screen: RunScreen
}
});
const StackNav = createStackNavigator({
Login: {
screen: LoginScreen
},
DrawerNav: {
screen: DrawerNavigator
},
{
navigationOptions: {
headerStyle: {
backgroundColor: '#2b3991',
},
headerTintColor: '#fff'
},
},
});
export default StackNav;][1]
错误消息:
错误:捆绑失败:C:\ Users \ Michal \ apps \ run \ src \ nav \ rootnav.js:SyntaxError:C:/Users/Michal/apps/run/src/nav/rootnav.js:意外令牌(35:4) 33 | DrawerNav:{ 34 |屏幕:DrawerNavigator,
35 | { | ^ 36 | navigationOptions:{ 37 | headerStyle:{ 38 | backgroundColor:“#2b3991”,
答案 0 :(得分:0)
请尝试使用此代码,因为代码中的NavigationOptions处存在文本错误
const StackNav = createStackNavigator({
Login: {
screen: LoginScreen
},
DrawerNav: {
screen: DrawerNavigator
},
},
{
navigationOptions: {
headerStyle: {
backgroundColor: '#2b3991',
},
headerTintColor: '#fff'
},
},
);
答案 1 :(得分:0)
Try designing the navigator like below:-
const StackNav = createStackNavigator(
{
Login: LoginScreen,
DrawerNav: DrawerNavigator,
},
{
navigationOptions: {
headerStyle: {
backgroundColor: '#2b3991',
},
headerTintColor: '#fff'
}
}
);