反应本机抽屉导航不适用于按钮单击

时间:2018-10-17 02:30:51

标签: javascript react-native react-navigation

我为抽屉导航添加了代码,但似乎无法正常工作。有人可以帮我这个忙吗?

DrawerNavigation.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 个答案:

答案 0 :(得分:1)

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

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

 onPress={()=> navigation.toggleDrawer()}