React native 反应本机和嵌套导航,好方法?

React native 反应本机和嵌套导航,好方法?,react-native,mobile,react-native-navigation,React Native,Mobile,React Native Navigation,几天后,我在这里询问,因为我在网上没有找到合适的解决方案 My App.js render()返回抽屉导航器,如您所见: render(){ 返回( } initialRouteName=“过去的发布” > ); } 在这里,您可以看到PastLaunchs函数返回的堆栈导航器: pastLaunchs(){ 返回( ); } 结果如下: 但当我打开过去发布的详细信息时: 我们可以看到抽屉头和堆栈头 我的问题:当我在此视图中时,如何隐藏抽屉标题? 非常感谢 最后使用headerShown

几天后,我在这里询问,因为我在网上没有找到合适的解决方案

My App.js render()返回抽屉导航器,如您所见:

render(){
返回(
}
initialRouteName=“过去的发布”
>
);
}
在这里,您可以看到PastLaunchs函数返回的堆栈导航器:

pastLaunchs(){
返回(
);
}
结果如下:

但当我打开过去发布的详细信息时:

我们可以看到抽屉头和堆栈头

我的问题:当我在此视图中时,如何隐藏抽屉标题?


非常感谢

最后使用headerShown:false

const drawerOptions = { headerStyle: { backgroundColor: "#181C1F"}, headerTintColor: "white" };



export default class App extends React.Component {
    pastLaunches() {
        return (
          <Stack.Navigator headerMode='none'>
            <Stack.Screen name="launches" component={Launches} />
            <Stack.Screen name="details" component={PastLaunchDetails} options={drawerOptions}
            />
          </Stack.Navigator>
        );
    }

    customDrawerContent(props) {
        return (
            <ImageBackground style={{flex: 1, justifyContent: "center"}}>
                <DrawerContentScrollView {...props} style={{ backgroundColor: 'rgba(0, 0, 0, 0.6)', flex: 1}} >
                    <DrawerItemList {...props} labelStyle={{ color: "white" }} activeTintColor="black" itemStyle={{ flex: 1 }}/>
                </DrawerContentScrollView>
            </ImageBackground>
        );
    }

    render() {
        return (
            <NavigationContainer>
                <Drawer.Navigator
                    drawerContent={(props) => <this.customDrawerContent {...props} />}
                    initialRouteName="Past Launches"
                    headerMode='none'
                >
                    <Drawer.Screen name="Home" component={HomeScreen} options={{...drawerOptions, headerShown: false}}/>
                    <Drawer.Screen name="Next Launch" component={NextLaunch} options={{...drawerOptions, headerShown: false}}/>
                    <Drawer.Screen name="Past Launches" component={this.pastLaunches} options={{...drawerOptions, headerShown: false}}/>
                </Drawer.Navigator>
            </NavigationContainer>
        );
    }
}
const-drawerOptions={headerStyle:{backgroundColor:#181C1F},headertincolor:“white”};
导出默认类App扩展React.Component{
新闻发布会(){
返回(
);
}
定制抽屉内容(道具){
返回(
);
}
render(){
返回(
}
initialRouteName=“过去的发布”
headerMode='none'
>
);
}
}
自定义抽屉标题

import { DrawerActions } from '@react-navigation/native'

export const CustomDrawerHeader = (props) => {
      const navigation = useNavigation();
      return (<View style={{ flexDirection: 'row', paddingVertical: 12, paddingHorizontal: 12}}>
         <Button onPress={() => {
           navigation.dispatch(DrawerActions.toggleDrawer());
         }}
         title='Menu icon'></Button>
         <Text style={{textAlign: 'center'}}>{props.title}</Text>
      </View>)
}
从'@react导航/native'导入{DrawerActions}
导出常量CustomDrawerHeader=(道具)=>{
const navigation=useNavigation();
返回(
{
dispatch(DrawerActions.toggleDrawer());
}}
title='Menu icon'>
{props.title}
)
}
自定义后收割台


export const CustomStackHeader = (props) => {
      const navigation = useNavigation();
      return (<View style={{ flexDirection: 'row', paddingVertical: 12, paddingHorizontal: 12}}>
         <Button onPress={() => {
           navigation.goBack();
         }}
         title='Back icon'></Button>
         <Text style={{textAlign: 'center'}}>{props.title}</Text>
      </View>)
}

导出常量CustomStackHeader=(道具)=>{
const navigation=useNavigation();
返回(
{
navigation.goBack();
}}
title='Back图标'>
{props.title}
)
}

此外,我也不建议将stackNavigator保留在抽屉组件内部的方法中,将其移到外部(您将获得重新渲染,并将失去性能)。

我尝试过,但您的想法是在查看过去的启动详细信息时,从抽屉导航而不是标题中隐藏“过去的启动”。我理解你的第二个评论,我的堆栈导航器应该在过去的发布组件中?把这小吃叉起来,重新制作你的问题,包括你过去发布的位置,我可以以更好的方式帮助你。在这里你可以看到代码:我更新了答案抱歉无法登录expo共享新答案我看到了你的答案但你隐藏了标题抽屉,现在你无法在不同的视图之间导航。另外,如何知道用户更改页面?再次感谢!