import React from 'react';
import { NavigationContainer } from '@react-navigation/native';
import { createDrawerNavigator } from '@react-navigation/drawer';
import HomeComponent from '../../Home/index'
import ContactMeComponent from '../../ContactMe/index'
import AboutMeComponent from '../../AboutMe/index'
import BlogComponent from '../../Blog/index'
import { MainStackNavigation } from '../../StackNavigations/MainStackNavigation/index'
const Drawer = createDrawerNavigator();
export function MainDrawerNavigation() {
return (
<NavigationContainer
independent="true">
<Drawer.Navigator initialRouteName="Home"
drawerContentOptions= {{
activeTintColor:'#000000',
labelStyle: {fontFamily: 'comicNeueRegular'}
}}>
<Drawer.Screen
name="MainStackNavigation" component={MainStackNavigation} />
<Drawer.Screen name="Home" component={HomeComponent}/>
<Drawer.Screen name="About" component={AboutMeComponent} />
<Drawer.Screen name="Blog" component={BlogComponent} />
<Drawer.Screen name="Contact" component={ContactMeComponent} />
</Drawer.Navigator>
</NavigationContainer>
);
}
在上面的代码中,我想隐藏名称为“ MainStackNavigation”的Drawer.screen标签。我该怎么做?我正在使用React Native 0.62。谢谢。
只需尝试一次。创建一个返回null的类,如下所示
class Hidden extend React.Component{
render(){
return null;
}
}
然后向抽屉添加选项,如
export function MainDrawerNavigation() {
return (
<NavigationContainer
independent="true">
<Drawer.Navigator initialRouteName="Home"
drawerContentOptions= {{
activeTintColor:'#000000',
labelStyle: {fontFamily: 'comicNeueRegular'}
}}>
<Drawer.Screen
name="MainStackNavigation" component={MainStackNavigation} options = {drawerLabel: <Hidden />} />
<Drawer.Screen name="Home" component={HomeComponent}/>
<Drawer.Screen name="About" component={AboutMeComponent} />
<Drawer.Screen name="Blog" component={BlogComponent} />
<Drawer.Screen name="Contact" component={ContactMeComponent} />
</Drawer.Navigator>
</NavigationContainer>
);
}
希望它会起作用