Версия зависимостей:
"dependencies": {
"react": "16.3.1",
"react-native": "~0.55.2",
"react-navigation": "^2.0.1",
}
Я использую react-navigation
для навигации по моему экрану, я создаю два экрана и ящик
Router.js:
import { createStackNavigator, createDrawerNavigator } from 'react-navigation';
import MainActivity from './components/MainActivity';
import ThisWeek from './components/ThisWeek';
import DrawerPanel from './components/DrawerPanel';
const Stack = createStackNavigator({
MainActivity: {
screen: MainActivity,
navigationOptions: {
title: 'Welcome',
headerStyle: {
backgroundColor: '#81A3A7',
elevation: null
}
}
},
ThisWeek: {
screen: ThisWeek
}
},
{
initialRouteName: 'MainActivity'
}
);
const Router = createDrawerNavigator({
FirstScreen: {
screen: Stack
}
},
{
contentComponent: DrawerPanel,
drawerWidth: 200
});
export default Router;
В моем DrawerPanel.js
я могу нажать две кнопки, чтобы перейти к экрану, но когда я пытаюсь использовать this.props.navigation.closeDrawer();
, который показывает ошибку _this2.props.navigation.closeDrawer is not a function
.
Так что я пытаюсь console.log(this.props);
, я могусм openDrawer
и closeDrawer
под navigation
Вот мой DrawerPanel.js:
import React, { Component } from 'react';
import { ScrollView, FlatList, Text } from 'react-native';
import { View } from 'react-native-animatable';
import { List, Button } from 'react-native-elements';
class DrawerPanel extends Component {
render() {
console.log(this.props);
return (
<ScrollView style={{ backgroundColor: '#81A3A7' }}>
<Button
onPress={() => {
this.props.navigation.actions.closeDrawer();
this.props.navigation.navigate('MainActivity');
}}
backgroundColor={'#81A3A7'}
containerViewStyle={{ width: '100%', marginLeft: -61 }}
title='Main page'
/>
<Button
onPress={() => this.props.navigation.navigate('ThisWeek')}
backgroundColor={'#81A3A7'}
containerViewStyle={{ width: '100%', marginLeft: -46 }}
title='This weel'
/>
</ScrollView>
);
}
}
export default DrawerPanel;
Я не могу понять этопочему я могу использовать this.props.navigation.navigate();
, чтобы другой экран не позволял использовать this.props.navigation.closeDrawer();
Я пытаюсь внести изменения, чтобы использовать this.props.navigation.actions.closeDrawer();
ошибка покажет Cannot read property 'closeDrawer' of undefined
.
Какой шаг ясделать это неправильно?Любая помощь будет оценена.Заранее спасибо.