我创建了一个React Native App。
我正在使用BackHandler。 https://facebook.github.io/react-native/docs/backhandler.html
当我使用
运行我的应用时,我遇到了一个奇怪的问题react-native run-android
我的后退按钮按预期工作。
但是当我使用Android Studio运行时,每当我点击任何屏幕上的后退按钮时,它都会直接退出App。
我已经检查过,捆绑js文件正在生成。
以下是代码:
import {BackHandler} from 'react-native';
class App extends Component {
constructor(props) {
super(props)
this.handleBackButtonClick = this.handleBackButtonClick.bind(this);
}
componentWillMount(){
BackHandler.addEventListener('hardwareBackPress', this.handleBackButtonClick);
}
componentWillUnmount(){
BackHandler.removeEventListener('hardwareBackPress', this.handleBackButtonClick);
}
handleBackButtonClick(){
this.props.navigation.goBack(null);
return true;
}
}
编辑:问题是当调试器打开时,后退按钮正在工作,如果没有打开,后退按钮不起作用。