plateName.js 3.67 KB
/**
 * Created by Cassie on 2018/03/06
 */
import React, { Component } from 'react';
import {
    StyleSheet,
    View,
    Text,
    TouchableOpacity,
    Image,
    FlatList,
    StatusBar
} from 'react-native';

import {zoomW,zoomH} from '../../utils/getSize';
import {xnBorderWidth} from "../../utils/utils";
const back = require('../../img/back.png');
const close = require('../../img/close.png');
const cross = require('../../img/cross.png');
const plate = require('../../img/plate.png');
const arrow = require('../../img/arrow.png');

export default class PlateName extends Component {
    static navigationOptions = ({ navigation, screenProps })=>({
        title: '选择板块',
        headerLeft:(<View style={{display:'flex',flexDirection:'row'}}>
            <TouchableOpacity style={styles.leftIcon} onPress={navigation.state.params?navigation.state.params.back:null}>
                <Image source={back} style={styles.backIcon} resizeMode="contain" />
            </TouchableOpacity>
            <TouchableOpacity style={styles.leftIcon} onPress={navigation.state.params?navigation.state.params.close:null}>
                <Image source={close} style={styles.closeIcon} resizeMode="contain" />
            </TouchableOpacity>
        </View>),
        headerRight:(<View />)
    });

    constructor(props) {
        super(props);
        this.state = {
            list:['怪兽汉化','宝井理人','木原音濑','寒武纪年','苏州bjd','雪龙神君','藤原熏']
        };
    };

    componentDidMount(){
        //设置头部
        this.props.navigation.setParams({
            back:()=>{
                this.props.navigation.goBack();
            },
            close:()=>{
                NativeModules.system.navTo("BACK");
            }
        });
    };

    /* 渲染列表*/
    keyExtractor = (item,index) => index;
    /*首页列表*/
    renderItem = ({item,index}) => (
        <View style={styles.plateItem}>
            <TouchableOpacity style={styles.plateName}>
                <Text style={{fontSize:16,color:'#333'}}>灌水区</Text>
            </TouchableOpacity>
        </View>
    );

    render() {
        return (
            <View style={styles.background}>
                <StatusBar barStyle="light-content" />
                <FlatList keyExtractor={this.keyExtractor} data={this.state.list} renderItem={this.renderItem} numColumns={2} />
            </View>
        );
    }
}

const styles = StyleSheet.create({
    leftIcon:{
        width:(50/zoomW),
        height:'100%',
        display:'flex',
        flexDirection:'row',
        alignItems:'center'
    },
    backIcon:{
        width:(10/zoomW),
        height:(18/zoomH),
        marginLeft:(10/zoomW)
    },
    closeIcon:{
        width:(18/zoomW),
        height:(18/zoomH)
    },
    background:{
        flex:1,
        backgroundColor:'#f2f2f2',
        paddingLeft:(10/zoomW),
        paddingRight:(10/zoomW),
        flexDirection:'row',
        flexWrap:'wrap',
        paddingTop:(10/zoomW)
    },
    plateItem:{
        width:'50%',
        display:'flex',
        justifyContent:'center',
        alignItems:'center',
        marginTop:(5/zoomH),
        marginBottom:(5/zoomH)
    },
    plateName:{
        width:(170/zoomW),
        height:(40/zoomH),
        borderWidth:1,
        borderColor:'#ddd',
        borderStyle:'solid',
        display:'flex',
        justifyContent:'center',
        alignItems:'center',
        borderRadius:(4/zoomW),
        backgroundColor:'#fff'
    },
    rightItem:{
        height:'100%',
        borderLeftWidth:1,
        borderLeftColor:'#eee',
        borderStyle:'solid',
        display:'flex',
        justifyContent:'center',
        paddingLeft:(10/zoomW)
    }
});