我正在使用 RN 并想返回到上一个屏幕,但调试显示:“C:\Users\DELL\Desktop\DGar\DGar\node_modules\react-native\Libraries\Core\ExceptionsManager.js :179 类型错误:无法读取未定义的属性“导航””。我现在该怎么办?请帮帮我!
import React, { Component } from 'react'; 进口 { 警报, 方面, 滚动视图, 文本输入, 可触摸不透明度, 后台处理程序, 来自'反应原生'; import { StyleSheet, View, Text, Image } from 'react-native';
const screenWidth = Dimensions.get('screen').width;
const screenHeight = Dimensions.get('screen').height;
import Icon from 'react-native-vector-icons/FontAwesome';
import ImagePicker from 'react-native-image-crop-picker';
import { NavigationUtils } from '../../navigations';
import { Navigation } from 'react-native-navigation';
export default class RecentReport extends Component {
constructor(props) {
super(props);
Navigation.events().bindComponent(this);
}
componentDidMount() {
BackHandler.addEventListener('hardwareBackPress', this.handleBackPress);
}
componentWillUnmount() {
BackHandler.removeEventListener('hardwareBackPress', this.handleBackPress());
}
navigationButtonPressed({ buttonId }) {
switch (buttonId) {
case 'backPress': {
this.handleBackPress();
break;
}
}
}
handleBackPress = (props) => {
props.navigation.goBack(null);
return true;
};
render() {
return (
<View style={styles.container}>
<Text>Hi</Text>
</View>
);
}
}
RecentReport.options = {
topBar: {
animate: true,
elevation: 0,
title: {
text: 'Warning',
fontWeight: 'bold',
alignment: 'center',
},
leftButtons: [
{
id: 'backButton',
icon: require('../../assets/icons/back-button.png'),
color: '#5B7C56',
},
],
},
statusBar: {
backgroundColor: '#5B7C56',
},
};
const styles = StyleSheet.create({
container: {
flex: 1,
},
imageItem: {
height: screenHeight / 4,
borderWidth: 1,
borderColor: '#5B7C56',
borderRadius: 20,
resizeMode: 'cover',
marginBottom: 10,
},
warningContainer: {
padding: 10,
},
spacingBetween: {
flexDirection: 'row',
alignItems: 'center',
justifyContent: 'space-between',
},
spacing: {
flexDirection: 'row',
alignItems: 'center',
},
contentContainer: {
padding: 10,
},
addWarningButton: {
height: 70,
width: 70,
borderRadius: 50,
borderColor: 'black',
backgroundColor: '#5B7C56',
borderWidth: 1,
alignItems: 'center',
justifyContent: 'space-around',
marginRight: 13,
marginTop: 13,
},
});