我想回到以前的觀點在我使用此代碼返回鍵反應android原生
'use strict';
var React = require('react-native');
var {
AppRegistry,
Component,
StyleSheet,
Text,
View,
BackAndroid,
Navigator
} = React;
var HomePage = require('./HomePage');
class DetailsPage extends Component{
constructor(props){
super(props);
}
render(){
return(
<View style={styles.container}>
<Text style={styles.text}>
{this.props.description}
</Text>
</View>
)
}
}
BackAndroid.addEventListener('hardwareBackPress', function() {
this.props.navigator.pop(); // line 32
return true;
});
var styles = StyleSheet.create({
container: {
flex: 1
},
text:{
color:'#000',
textAlign:'center',
fontWeight:'bold',
flex:1,
fontSize:20
},
});
module.exports = DetailsPage;
反應本機應用程序在調試我看到成功偵測回事件,但它崩潰,在這條線this.props.navigator.pop()
給我這個錯誤。
無法讀取undefinedhandleException的特性 '道具' @ d:\陣營\高良\ node_modules \反應母語\庫\ JavaScriptAppEngine \初始化\ ExceptionsMana ...:61handleError @ d:\陣營\高良\ node_modules \ react-native \ Libraries \ JavaScriptAppEngine \ Initialization \ InitializeJava ...:80ErrorUtils.reportFatalError @ D:\ React \ Kora \ node_modules \ react-native \ packager \ react-packager \ src \ Resolver \ polyfills \ error-guard。... :28guard @ D:\ React \ Kora \ node_modules \ react-native \ Libraries \ Utilities \ MessageQueue.js:43callFunctionReturnFlushedQueue @ d:\陣營\高良\ node_modules \反應母語\庫\公用\ MessageQueue.js:86onmessage @ debuggerWorker.js:39
我想這是this.props
無法訪問但是我不知道如何克服這個問題。如果我把BackAndroid.addEventListener
它給人的類中我錯誤
UnExpectedToken
感謝您的回答。它的工作,但與'this.props.navigator.pop();'而不是'this.navigator.pop();'..編輯答案接受它 –
哦,看看那一個。很高興它可以幫助,雖然 – stinodes
@Sinitodes這不適用於我:/它給了我這個錯誤'未定義不是一個對象(評估'this.props.navigator.pop()')'。我有你在我的導航器組件中發佈的完全相同的代碼。 – corasan