react native 九宫格

import React, { Component } from 'react';
import {
    AppRegistry,
    StyleSheet,
    TextInput,
    ListView,
    TouchableOpacity,
    Image,
    ScrollView,
    Text,
    Alert,
    View
} from 'react-native';
//导入数据
import ShareData from ".././shareData.json";

//获取屏幕宽度
let Dimensions = require("Dimensions");
let {width} = Dimensions.get('window');
//常量设置
let cols = 3;
let cellWH =80;
let vMargin = (width-cellWH*cols)/(cols+1);
let hMargin = 30;


export default class App extends Component {

    constructor(props){
        super(props);
        //1.设置数据源
        let ds = new ListView.DataSource({rowHasChanged: (r1, r2) => r1 !== r2});
        //2.设置返回数据
        this.state = {dataSource:ds.cloneWithRows(ShareData.data)};
        thiz = this;
    }

    render() {
        return (
            
        );
    }

    _renderRow(rowData, sectionID, rowID, highlightRow){
        return(
            {thiz._onPress(rowData.title)}}>
                
                    
                    {rowData.title}
                
            
        );
    }

    _onPress(e) {

        alert(">>>点击 "+e);
    }

}


const styles = StyleSheet.create({
    listViewStyle:{
        flexDirection:'row',
        flexWrap:'wrap',
    },
    iconStyle:{
        width:50,
        height:50,
    },
    innerViewStyle:{
        width:cellWH,
        height:cellWH,
        marginLeft:vMargin,
        marginTop:hMargin,
        alignItems:'center',
    }
});

你可能感兴趣的:(react native 九宫格)