[英]How to remove Header in functional component React Native
我正在仅使用功能组件在 react-native 中设置导航。 如何删除屏幕上的标题?
const AppScreen = ({ navigation }) => {
//Desc => removing header
AppScreen.navigationOptions = {
header: null
};
return (
<>
<Text>LoGinScreen</Text>
</>
);
};
未显示错误消息,但应用程序呈现标题。
在多个屏幕上以类似的方式配置headers
是很常见的。
class AppScreen extends React.Component {
static navigationOptions = {
header: null,
/* No more header config here! */
};
/* render function, etc */
}
/* other code... */
您可以将配置移至 Properties defaultNavigationOptions
下的堆栈导航器。
headerMode指定应如何呈现标题:
const RootStack = createStackNavigator(
{
Apps: AppScreen,
Details: DetailsScreen,
},
{
initialRouteName: 'Apps',
headerMode: 'none'
/* if use header The header config from Apps is now here */
}
);
您可以从功能组件中删除标题
const AppScreen = ({ navigation }) => {
return (
<Text>LoginScreen</Text>
);
};
通过在功能组件之外使用它。
AppScreen.navigationOptions = {
header: null
};
要删除功能组件屏幕上的标题,请在路由配置中执行以下操作:
const AuthStack = createStackNavigator(
{
Login: AuthScreen
},
{
headerMode: 'none' //this will remove the header from the screen of AuthScreen
})
在你的路由配置中设置 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.