RN or QRN 知识点

2018-03-30  本文已影响24人  McDu

part1

  1. 定位:默认 position:relative,position:absolute 相对父元素
<View>
    <View>
        <View style={{height: 200, width: 200, backgroundColor: 'red', position: 'absolute'}}/>
    </View>
    <View style={{height: 100, width: 100, backgroundColor: 'pick'}}/>
    <View style={{height: 100, width: 100, backgroundColor: 'blue', position: 'absolute'}}/>
</View>
  1. ScrollView
  1. ListView:
constructor() {
    super();

    this.ds = new ListView.DataSource({
        rowHasChanged: (r1, r2) => r1 !== r2,
        sectionHeaderHasChanged: (s1, s2) => s1 !== s2
    });
    let sections = {
        part1: [],
        part2: []
    };
    for (let i = 0; i < 10; i++) {
        if (i < 10) {
            sections.part1.push(i)
        } else {
            sections.part2.push(i)
        }
    }
    this.state = {
        noMore: false,
        sections: sections,
        dataSource: this.ds.cloneWithRowsAndSections(sections),
    };
}
<View style={{flex: 1, padding:100}}>
    <ListView
        ref="ListView"
        dataSource={this.state.dataSource}
        renderRow={(rowData) => <View style={{flex: 1, borderBottomWidth: 1, borderColor: '#ccc'}}><Text
            style={{padding: 10, fontSize: 14}}>{rowData}</Text></View>}
        renderSectionHeader={(sectionData, sectionID) => <Text
            style={{padding: 10, backgroundColor: 'pink'}}>{sectionData} {sectionID}</Text>}
        refreshControl={refreshControl}
        loadControl={loadControl}
    />
</View>
  1. 动画
_animate(){
    this.state.angle.setValue(0);
    this._anim = Animated.timing(this.state.angle, {
        toValue:1,
        duration: this.props.speed,
        easing: Easing.linear
   }).start(() => this._animate())
}
componentDidMount(){
    this._animate();
}

componentWillUnmount(){
    if(this._anim){
         this._anim.stop();
        this._anim = null;
    }
}
  1. 开发者可以通过 class Demo extends QXXX {} 的方式创建 QReact View 或 Component,并使用 QReact 的插件特性。在你引用 Ext 进来的同时,会默认引入全局变量 QView 和 QComponent。
  2. Router 的使用:封装原生的 Navigator 组件,无需手动配置路由映射关系,RN、QRN 本来就没有 url,根本不存在路径。
class PageA extends QView{}
class PageB extends QView{}
import './PageA';
import './PageB';

Ext.defaults.hybridId = 'HelloWorld';
Ext.defaults.appName = 'HelloWorld';
Ext.defaults.indexView = 'PageA';
Ext.open('PageA');
//....
Ext.back();
  1. Hy 并不具备中间页面的功能,Hy 是多页的,一个页面是一个 native 页面;RN 是伪多页,多个页面是一个 native 页面。

part2


  1. Chrome 调试:
  1. 项目入口:iconfont
import { FontLoader } from ''qunar-react-native;
FontLoader.loadFontSet(require('QFontSet'));

在 QRN 中使用 iconfont:

module.exports = {
   'hybridId': 'https://s.qunarzz.com/../hybridId.ttf'
}

使用:

<Text style={{fontFamily: ''}}

part3


  1. 获取屏幕像素密度的方法
  1. 获取页面宽高的方法
  1. 获取状态栏高度的方法
上一篇 下一篇

猜你喜欢

热点阅读