gpt4 book ai didi

javascript - 为所有组件 React-Native 设置不 header

转载 作者:行者123 更新时间:2023-11-30 11:17:31 26 4
gpt4 key购买 nike

我有 4 个组件,它们都定义了 static navigationOptions = {header: null}。但是当你在每个组件中定义它时,它非常耗时。所以我在 createStackNavigator 中定义了 {header: null} 但 header 仍然出现在组件的顶部。

你们能帮忙吗?

import { createStackNavigator } from 'react-navigation';
import Home from './Components/Home';
import Main from './Components/Main';
import SubjectDetail from './Components/AnimalSubject';
import Lesson from "./Components/Lesson";

const App = createStackNavigator({
First: { screen: Home },
Second: { screen: Main },
Third: { screen: SubjectDetail },
Four: {screen: Lesson},
//Route name with specified component
},
{
transitionConfig: () => ({ screenInterpolator: () => null }),
//remove transition config
},
{
initialRouteName: 'First',
//the component name 'Home' will be initiated first
},
{
header: null
//defined header: nul
}
);

export default App;

我的环境

"react": "16.3.1",
"react-native": "~0.55.2",
"react-navigation": "^2.2.5",
"node": "v8.11.2"
"npm": "v6.1.0"

最佳答案

可能这段代码适合你(基于 Stack navigator docs )

const App = createStackNavigator({
First: { screen: Home },
Second: { screen: Main },
Third: { screen: SubjectDetail },
Four: {screen: Lesson},
},
{
headerMode: 'none',
transitionConfig: () => ({ screenInterpolator: () => null }),
initialRouteName: 'First',
},
);

您应该将带有路由的对象作为第一个参数传递,将通用选项作为第二个参数传递。

关于javascript - 为所有组件 React-Native 设置不 header ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51017316/

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