BannerReourceList.js 3.51 KB
'use strict';

import React from 'react';
import ReactNative from 'react-native';
import {getSlicedUrl} from '../../utils/Utils';

const {
  AppRegistry,
  StyleSheet,
  Text,
  View,
  Image,
  ListView,
  Dimensions,
  TouchableOpacity,
  PixelRatio,
} = ReactNative;

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

    renderRow(rowData,sectionID,rowID,highlightRow) {

        let newSrc = getSlicedUrl(rowData.src, 140, 100, 2);
        return (
            <TouchableOpacity activeOpacity={0.5} onPress={() => {
				this.props.onPressSlideItem && this.props.onPressSlideItem(rowData);
			}}>
                <View style={styles.row}>
                    <View style={styles.thumbnailV}>
                          <Image
                            source={{uri: newSrc}}
                            style={styles.thumbnail}
                            resizeMode={'contain'}
                          ></Image>
                    </View>
                     <View style={styles.textV}>
                        <Text style={styles.text}  numberOfLines={1}>
                            {rowData.name}
                        </Text>
                    </View>
                </View>
            </TouchableOpacity>
        );
    }

    render() {
		let {resource} = this.props;
        let res = resource.toJS();
		let data = res.data;
        let title = data?data.title:null;
		let list = data?data.list:null;

		if (!resource || resource.size == 0 || !list) {
			return null;
		}

        return (
            <View style={styles.cellList}>
                <View style={styles.titleStyle}>
    				<Text style={styles.titleText} numberOfLines={1}>{title.title}</Text>
    			</View>
                <ListView
                    showsHorizontalScrollIndicator ={false}
                    dataSource={this.dataSource.cloneWithRows(list)}
                    horizontal={true}
                    renderRow={this.renderRow.bind(this)}
                />
                <View style={styles.container}>
                </View>
            </View>
        );
    }
};


let {width, height} = Dimensions.get('window');
let itemWidth= Math.ceil(width/4);
let itemHeight = itemWidth - 20;

let styles = StyleSheet.create({
    cellList:{
        justifyContent: 'center',
        width: Dimensions.get('window').width,
        height: itemHeight + 120,
		backgroundColor: 'white',
    },
    titleStyle:{
		alignItems: 'center',
		justifyContent: 'center',
		height: 48,
		width:Dimensions.get('window').width,
        backgroundColor: 'white',
    },
    row: {
        marginLeft: 10,
        width: itemWidth,
        height: itemWidth,
        backgroundColor: 'white',
     },
     textV: {
         width: itemWidth,
         justifyContent: 'center',
         alignItems: 'center',
         height: 20,
         backgroundColor:'white',
     },
    text: {
        color: 'gray',
        width: itemWidth,
        textAlign: 'center',
        justifyContent: 'center',
        fontSize: 12,
        backgroundColor:'white',
    },
    titleText: {
        textAlign: 'center',
        fontSize: 15,
    },
    thumbnailV: {
        marginTop: 20,
		width: itemWidth,
		height: itemHeight,
	},
    thumbnail: {
		width: itemWidth,
		height: itemHeight,
        backgroundColor: 'white',
	},
    container: {
        width: width,
        height: 15,
        backgroundColor:'#f0f0f0',
    },
});