React Native 问题小结

来源:互联网 发布:淘宝举报网址 编辑:程序博客网 时间:2024/05/12 17:46

一. ES6的this需要绑定带函数,一共三种绑定方式
1. 在构造函数中绑定

constroct() {        this.myFunc = this.myFunc.bind(this);    }    myFunc() {...}

2.在函数被调用的地方绑定

    <Swipe        onLoad = { this.myFunc.bind(this) }    />

3.定义函数时使用lambda的形式

myFunc = () => { ... }

二. props中的参数都是不可更改的,只可以通过 className.defaultProps({ … })来设置默认值

三. 如何让Component支持横竖屏切换
大部分react-native库的Component都是支持的,但第三方库的Component和必须要写死长宽的Component都需要去手动支持。我的实现方式是在 onLayout这个回调函数中调用Dimensions.get(‘window’).width/height来实时获得切换后屏幕的长宽,然后把获得的长宽更新到state中。判断当前手机的横竖屏。

四. Dimensions的get(‘window’)和get(‘screen’)的区别
get(‘window’)获得长宽不包含屏幕下方的虚拟键部分,而get(‘screen’)会包含这一部分。

0 0