gpt4 book ai didi

reactjs - react native : header styles in navigationOptions not working

转载 作者:行者123 更新时间:2023-12-03 13:18:23 25 4
gpt4 key购买 nike

我对 react 原生还很陌生。我正在尝试为我的应用程序设置一些全局标题样式,但它不起作用

route.js

import React, { Component } from 'react';
import { View } from 'react-native';
import { createStackNavigator, createAppContainer } from "react-navigation";
import SplashScreen from '../screens/SplashScreen';
import CalendarScreeen from '../screens/CalendarScreen';

const NavStack = createStackNavigator(
{
Splash: {
screen: SplashScreen,
navigationOptions: {
header: null
},
},
Calendar: {
screen: CalendarScreeen,
navigationOptions: {
title: 'Calendar',
},
},
},
{
initialRouteName: 'Calendar',
navigationOptions: {
headerStyle: {
backgroundColor: '#28F1A6',
elevation: 0,
shadowOpacity: 0
},
headerTintColor: '#333333',
headerTitleStyle: {
fontWeight: 'bold',
color: '#ffffff'
}
}

}

);

const Routes = createAppContainer(NavStack);
export default Routes;

现在,我知道我可以在我的类组件中执行类似的操作

static navigationOptions = {
title: 'Chat',
headerStyle: { backgroundColor: 'red' },
headerTitleStyle: { color: 'green' },
}

正如这里提到的possible alternative

但我想从我的 route.js 实现同样的目标

我还尝试了 defaultNavigationOptions 就像 docs 中提到的那样

但运气不好!!

最佳答案

我认为您正在使用React导航版本3。如果是这样,navigationOptions将更改为defaultNavigationOptions

{
initialRouteName: 'Calendar',
defaultNavigationOptions: {
headerStyle: {
backgroundColor: '#28F1A6',
elevation: 0,
shadowOpacity: 0
},
headerTintColor: '#333333',
headerTitleStyle: {
fontWeight: 'bold',
color: '#ffffff'
}
}

}

它应该可以工作。 https://snack.expo.io/ByGrHdAC7

关于reactjs - react native : header styles in navigationOptions not working,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53553520/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com