【问题标题】:How to create a menu Icon in a drawer navigation? React Native如何在抽屉导航中创建菜单图标?反应原生
【发布时间】:2021-08-08 13:34:35
【问题描述】:

我将 Drawer Navigator 嵌套在Stack Navigator 中,它运行良好并且在我滑动时打开,我想在按下抽屉打开时在其上方放置一个菜单图标。我尝试的每种方法总是以navigation can't be found 错误结束。

这是我的代码:

export class App extends Component {
.....

 function DrawerNav() {
      return (
        <Drawer.Navigator 
        drawerType="front" 
        initialRouteName="Main" drawerPosition="right">

            <Drawer.Screen name="Main" component={MainScreen} />
            <Drawer.Screen name="Wallet" component={WalletScreen} />
            <Drawer.Screen name="Appointments" component={Appointments} />
        </Drawer.Navigator>
               );}
   
      
  return ( 
       <Provider store={store}>
       
  

        <NavigationContainer>
        <Stack.Navigator initialRouteName="Menu">
          
           <Stack.Screen name="Menu" component={DrawerNav}  />
           <Stack.Screen name="Add" component={AddScreen}   navigation={this.props.navigation}/>
            <Stack.Screen name="Save" component={SaveScreen}  navigation={this.props.navigation}/>
           
        </Stack.Navigator>
        </NavigationContainer>
         
      </Provider>
          )}}

当我按下这个图标时,我想打开和关闭抽屉:

&lt;MaterialIcons name='menu' size={28} onPress={??} /&gt;

【问题讨论】:

    标签: react-native react-navigation navigation-drawer


    【解决方案1】:

    this.props.navigation.openDrawer()} />

    【讨论】:

    • 好的,我怎样才能打开抽屉?
    • 导航库中负责抽屉导航的函数
    • 好吧对不起一个非常愚蠢的问题。我应该把这个图标放在我的代码中的什么地方??
    • 在您要打开它的同一屏幕上,确保该屏幕包含在抽屉导航中。
    • 您在 drwaer 中有 3 个屏幕,您可以将图标放在这些屏幕的任何位置
    猜你喜欢
    • 2021-02-12
    • 2019-09-18
    • 1970-01-01
    • 1970-01-01
    • 2022-08-21
    • 1970-01-01
    • 2018-04-07
    • 2021-07-30
    • 1970-01-01
    相关资源
    最近更新 更多