HotCategoryIndividualization.js 4.26 KB
/**
 * Description:
 * hot_category_individualization:热门品类楼层 + title,大数据版
 * Author:  Bruce.Lu
 * Version: 1.0
 * Created on 2017/2/14.
 */
import React, {Component} from 'react';
import ReactNative, {
    Image,
    Text,
    StyleSheet,
    ListView,
    View,
    TouchableOpacity,
    Dimensions,
} from 'react-native';
import Swiper from 'react-native-swiper';
import ImmutablePropTypes from 'react-immutable-proptypes';
import Immutable from 'immutable';
import SlicedImage from '../../../common/components/SlicedImage';
import HeadTitleCell from '../cell/HeadTitleCell';
import YH_Image from '../../../common/components/YH_Image';

export default class HotCategoryIndividualization extends Component {
    constructor(props) {
        super(props);
        this.dataSource = new ListView.DataSource({
            rowHasChanged: (r1, r2) => !Immutable.is(r1, r2),
        });
    }

    render() {
        let title = this.props.data.get('title');
        let data = this.props.data.get('list').toArray();
        let lineNumber = parseInt((data.length + 3) / 4);
        let listHeight = Math.floor(lineNumber * cellHeight);
        let containerHeight = listHeight + 40;
        return (
            <View style={[styles.container, {height: containerHeight}]}>
                <HeadTitleCell title={title.get('title')} moreUrl={title.get('more_url')} onPressTitleMore={this.props.onPressTitleMore}/>
                <View style={[styles.list, {height: listHeight}]}>
                    {data.map((item, i) => {
                        let url = YH_Image.getSlicedUrl(item.get('src'), imageWidth, imageHeight, 2);
                        return (
                            <TouchableOpacity
                                key={i}
                                style={styles.cellContainer}
                                activeOpacity={1}
                                onPress={() => {
                                    this.props.onPressVipBannerItem && this.props.onPressVipBannerItem(item.get('url'), i + 1);
                                }}>
                                <YH_Image url={url} style={styles.image} />
                                <Text style={styles.text}>{item.get('title')}</Text>
                            </TouchableOpacity>
                        );
                    })}
                    <View style={[styles.vLine1, {height: listHeight}]} />
                    <View style={[styles.vLine2, {height: listHeight}]} />
                    <View style={[styles.vLine3, {height: listHeight}]} />
                    <View style={styles.hLine1} />
                    <View style={styles.hLine2} />
                </View>

            </View>
        );
    }
}

let {width, height} = Dimensions.get('window');
let cellWidth = width / 4;
let imageWidth = cellWidth - 14 * 2;
let imageHeight = imageWidth * 168 / 126;
let cellHeight = imageHeight + 20;

const styles = StyleSheet.create({
    container: {
        width: width,
        flexDirection: 'column',
    },
    list: {
        flexDirection: 'row',
        flexWrap: 'wrap',
        width:width,
    },
    cellContainer: {
        backgroundColor: '#f5f7f6',
        width:cellWidth,
        height:cellHeight,
        alignItems:'center',
        flexDirection:'column'
    },
    image: {
        width: imageWidth,
        height: imageHeight,
    },
    text: {
        backgroundColor: '#f5f7f6',
        fontSize: 12,
        color: '#444444',
        textAlign: 'center',
        width:cellWidth,
        height:20
    },
    vLine1: {
        position: 'absolute',
        backgroundColor: '#e5e5e5',
        width: 0.5,
        top: 0,
        left: cellWidth,
    },
    vLine2: {
        position: 'absolute',
        backgroundColor: '#e5e5e5',
        width: 0.5,
        top: 0,
        left: cellWidth * 2,
    },
    vLine3: {
        position: 'absolute',
        backgroundColor: '#e5e5e5',
        width: 0.5,
        top: 0,
        left: cellWidth * 3,
    },
    hLine1: {
        position: 'absolute',
        backgroundColor: '#e5e5e5',
        width,
        height: 0.5,
        top: cellHeight,
        left: 0,
    },
    hLine2: {
        position: 'absolute',
        backgroundColor: '#e5e5e5',
        width,
        height: 0.5,
        top: cellHeight * 2,
        left: 0,
    },
});