React-Native 的BackAndroid
来源:互联网 发布:金钱永不眠世基版软件 编辑:程序博客网 时间:2024/06/08 03:19
BackHandler or BackAndroid
BackAndroid已经废弃
这个只有三个static 方法
static exitApp() static addEventListener(eventName, handler) static removeEventListener(eventName, handler)
使用说明
Navigator.initialRoute配置的Component
因为在Navigator配置页面中 this.props.navigator is undefined is not an object 不知道为啥这样????
解决方法
在第一个 页面 中设置 如下
_onBackEvent() { const navigator = this.props.navigator; let count = navigator.getCurrentRoutes(); if (count.length > 1) { navigator.pop(); return true; } else { let timestamp = (new Date()).valueOf(); if (timestamp - firstClick > 2000) { firstClick = timestamp; ToastAndroid.show('再按一次退出', ToastAndroid.SHORT); return true; } } return false; } <!--添加到constructor 中this.onBackEvent=this._onBackEvent.bind(this)--> componentWillMount() { BackHandler.addEventListener("hardwareBackPress", this.onBackEvent); } componentWillUnmount() { BackHandler.removeEventListener("hardwareBackPress", this.onBackEvent); }
<span id="jump">解决不能在<Navigator Component />中设置返回和 this.props.navigator is undefined is not an object 错误
</span>
<Navigaor ref={component => this.navigator = component} ... /> <!--加入 ref={component => this.navigator = component}-->
在_onBackEvent 使用 的this.props.navigator 换成 this.navigator 问题就解决了
阅读全文
0 0
- React-Native 的BackAndroid
- React-native学习笔记之<BackAndroid>
- React Native学习安卓手机上的返回键BackAndroid
- React Native学习安卓手机上的返回键BackAndroid
- React Native学习安卓手机上的返回键BackAndroid
- React Native API模块BackAndroid自定义返回键事件处理
- React Native API模块BackAndroid自定义返回键事件处理
- 【React Native】React Native的bind方法
- React-Native的学习指南
- react-native 的简介
- react-native的Hello_World
- React Native的调试
- react-native的坑
- react native 的坑
- react-native的性能
- react-native的state
- React Native的征程
- React&React-Native的实践的问题
- MySQL(2):命令行基本操作
- Python问题:使用docker,putty重新配置linux虚拟环境
- WIfi Socket数据传输
- 彻底理解ThreadLocal
- 属性选择器 优先级
- React-Native 的BackAndroid
- Unity3D: 自制提示框消息 (Toast)
- Android:Date、String、Long三种日期类型之间的相互转换
- spring中的web上下文,spring上下文,springmvc上下文区别(超详细)
- RecycleView+BaseRecycleViewAdapterHelper多布局实现
- kafka--Topics and Logs
- 思考让人学有所得,学有所获
- 如何保护你的隐私(二)
- 被低估的BIRT报表(四):中文乱码的解决办法