ReactNative——笔记

1、全局错误异常捕获

ErrorUtils.setGlobalHandler() 

在生命周期里执行这个,相当于一个监听事件,当出现爆红等问题是,会直接进入里面的函数里,做任何你的操作。


2、监听安卓物理返回键

componentWillMount() {if(Platform.OS ==='android') { BackHandler.addEventListener('hardwareBackPress',this.onBackHandler); }}

componentWillUnmount() {if(Platform.OS ==='android') {BackHandler.removeEventListener('hardwareBackPress',this.onBackHandler); } }

onBackHandler =()=>{// this.onMainScreen and this.goBack are just examples, you need to use your own implementation here// Typically you would use the navigator here to go to the last state.if(!this.onMainScreen()) {this.goBack();returntrue; }returnfalse; };

ReactNative——笔记_第1张图片
安卓物理返回键

你可能感兴趣的:(ReactNative——笔记)