反应本机抽屉导航在按钮单击时不起作用

Posted

技术标签:

【中文标题】反应本机抽屉导航在按钮单击时不起作用【英文标题】:React native drawer navigation not working on button click 【发布时间】:2018-10-17 02:30:51 【问题描述】:

我为抽屉导航添加了一个代码,但它似乎不起作用。有人可以帮我解决这个问题吗?

抽屉导航.js

import React from 'react';
import  AppRegistry from 'react-native';
import  createDrawerNavigator  from 'react-navigation';
import  Icon  from 'react-native-elements';

import link from '../link';
export const Drawer = createDrawerNavigator(
    link: 
        screen: link,
        navigationOptions: 
            drawerLabel: "Drawer Item 1",
            drawerIcon: ( tintColor ) => <Icon name="rocket" size=24 />
        ,
    
);

AppRegistry.registerComponent('myapp', () => Drawer);

在 navigator/index.js 中,我正在为我在左侧创建的汉堡包按钮调用 DrawerOpen onPress 函数。

import React from 'react';
import createStackNavigator from 'react-navigation';
import  Icon  from 'react-native-elements';
import  ScrollView, Text, StyleSheet, View, Button from 'react-native';
import  TouchableOpacity  from 'react-native';
import iosIcon from "react-native-vector-icons/Ionicons";


import Tabs from "./TabbedNavigation";
import Drawer from "./DrawerNavigation";

export default createStackNavigator(
    Tabs: 
        screen: Tabs,
        navigationOptions: ( navigation ) => (
                title: 'Flurry Fit',
                //headerLeft:<Icon name="menu" size=30 iconStyle=padding: 8 onPress= () => navigation.navigate('DrawerOpen')  />,
                headerLeft:(
              <TouchableOpacity onPress=() => navigation.navigate('DrawerOpen')><!-- Button click event seems having an issue. -->
                <IOSIcon name="ios-menu" size=30 />
              </TouchableOpacity>
            ),
              headerRight:<Button onPress=() => alert('Link to Map') title="Map" color="#000" style=fontSize: 14/>,
                    )
    ,
,

    //mode: 'modal',
    //headerMode: 'screen',
);

【问题讨论】:

【参考方案1】:

我不确定您所说的“不工作”是什么意思。但我使用 toggleDrawer() 方法来显示/隐藏抽屉菜单。

  import  createStackNavigator,createDrawerNavigator, DrawerItems, SafeAreaView   from 'react-navigation';

 onPress=()=> navigation.toggleDrawer()

【讨论】:

以上是关于反应本机抽屉导航在按钮单击时不起作用的主要内容,如果未能解决你的问题,请参考以下文章

反应本机 NavigationDrawer navigation.toggleDrawer() 不起作用

从左到右反应原生抽屉导航拖动抽屉不起作用

导航栏按钮在 Shiny 中单击时不起作用

侧面导航抽屉项目单击不起作用

反应本机代码内联​​工作,但在导入时不起作用

navigation.goBack 在本机反应中不起作用