ReactNative——笔记

作者: 一朝瑾秋色 | 来源:发表于2018-08-29 15:44 被阅读13次

    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——笔记

        本文链接:https://www.haomeiwen.com/subject/cnqyiftx.html