[英]How to remove Header in functional component React Native
I'm setting up a navigation in react-native using only functional component.我正在仅使用功能组件在 react-native 中设置导航。 How do i remove the header on the Screen?
如何删除屏幕上的标题?
const AppScreen = ({ navigation }) => {
//Desc => removing header
AppScreen.navigationOptions = {
header: null
};
return (
<>
<Text>LoGinScreen</Text>
</>
);
};
No error message is shown but the app renders with a header.未显示错误消息,但应用程序呈现标题。
It is common to want to configure the headers
in a similar way on multiple screens.在多个屏幕上以类似的方式配置
headers
是很常见的。
class AppScreen extends React.Component {
static navigationOptions = {
header: null,
/* No more header config here! */
};
/* render function, etc */
}
/* other code... */
You can move the configuration to the stack navigator under Properties defaultNavigationOptions
.您可以将配置移至 Properties
defaultNavigationOptions
下的堆栈导航器。
headerMode Specifies how the header should be rendered: headerMode指定应如何呈现标题:
const RootStack = createStackNavigator(
{
Apps: AppScreen,
Details: DetailsScreen,
},
{
initialRouteName: 'Apps',
headerMode: 'none'
/* if use header The header config from Apps is now here */
}
);
You can remove header from functional component您可以从功能组件中删除标题
const AppScreen = ({ navigation }) => {
return (
<Text>LoginScreen</Text>
);
};
by using this out side of your functional component.通过在功能组件之外使用它。
AppScreen.navigationOptions = {
header: null
};
To remove the header on the screen for functional components, in the routes config do the following:要删除功能组件屏幕上的标题,请在路由配置中执行以下操作:
const AuthStack = createStackNavigator(
{
Login: AuthScreen
},
{
headerMode: 'none' //this will remove the header from the screen of AuthScreen
})
Set the defaultNavigationOptions in your routes configs:在你的路由配置中设置 defaultNavigationOptions:
createStackNavigator({
screenName:
{ screen: screenName },
},
{defaultStackNavigationOptions:{
header: () => null //this in the screen where you want to hide the header
}
}
)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.