简体   繁体   English

不为所有组件React-Native设置标头

[英]Set no header for all components React-Native

I have 4 components which all have static navigationOptions = {header: null} defined. 我有4个组件都定义了static navigationOptions = {header: null} But that it's very time-consuming when you define that in each component. 但是,在每个组件中定义它时非常耗时。 So I define {header: null} in createStackNavigator but the header still appears at the top of the component. 所以我在createStackNavigator中定义{header: null} ,但标题仍然出现在组件的顶部。

Can you guys help ? 你们能帮忙吗?

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;

my evironment 我的环境

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

Probably this code should works for you (based on Stack navigator docs ) 可能这段代码应该适合你(基于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',
},
);

You should pass the object with routes as a first parameter and common options as second. 您应该将带有路由的对象作为第一个参数传递,将常用选项作为第二个参数传

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM