我对 react-native 很陌生。我正在制作一个具有抽屉导航和堆栈导航的示例应用程序。我在抽屉按钮的抽屉代码中一次又一次地收到错误。如何打开和关闭抽屉?我试图在互联网上搜索很多。并尝试了我得到的任何东西。但没有任何帮助。任何帮助表示赞赏。我写了以下代码:
import React, {Component} from 'react';
import {createDrawerNavigator, createStackNavigator, createAppContainer} from 'react-navigation';
import {TouchableOpacity, Text} from 'react-native';
import Signup from './Screens/Signup';
import SignIn from './Screens/SignIn';
import TradeType from './Screens/TradeType';
import SState from './Screens/SState';
import IState from './Screens/IState';
import Result from './Screens/Result';
import Home from './Screens/Home';
import DrawerTbl from './Screens/DrawerTbl';
export const Drawer = createDrawerNavigator({
SignIn: {screen: SignIn},
Home: {screen: Home},
}, {
initialRouteName: 'SignIn',
contentComponent: 'DrawerTbl',
drawerWidth: 300
});
export const Stack = createStackNavigator({
SignIn: {screen: SignIn,
navigationOptions: ({navigation}) => ({
headerLeft:(
<TouchableOpacity onPress={() => navigation.dispatch(DrawerActions.toggleDrawer())}>
<Text>Drawer</Text>
</TouchableOpacity>
),
})
},
Signup: {screen: Signup},
Home: { screen: Home },
Drawer: { screen: Drawer },
DrawerTbl: { screen: DrawerTbl },
Trade: { screen: TradeType },
SState: { screen: SState },
IState: { screen: IState },
Result: { screen: Result }
},
{
initialRouteName: "SignIn",
});
const AppC = createAppContainer(Stack);
class App extends Component {
render() {
return(
<AppC/>
);
}
}
export default App;
我收到以下错误:找不到变量:'DrawerActions'。
尝试1:
navigationOptions: ({navigation}) => ({
headerLeft:(
<TouchableOpacity onPress={() => navigation.toggleDrawer()}>
<Text>Drawer</Text>
</TouchableOpacity>
),
})
得到错误:
Undefined is not a function(evaluating'navigation.toggleDrawer()')
尝试2:
this.props.navigation.openDrawer()
这也有错误。