gpt4 book ai didi

javascript - react native 抽屉导航在按钮单击时不起作用

转载 作者:行者123 更新时间:2023-12-03 00:55:44 25 4
gpt4 key购买 nike

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

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',
});

最佳答案

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

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

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

关于javascript - react native 抽屉导航在按钮单击时不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52846460/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com