SmallPic.js 2.08 KB
'use strict';

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

const {
    Image,
	View,
    StyleSheet,
    Dimensions,
    TouchableOpacity,
} = ReactNative;

import Immutable, {Map} from 'immutable';

export default class SmallPic extends React.Component {

    constructor(props) {
        super (props);
    }

    shouldComponentUpdate(nextProps){
        if (Immutable.is(nextProps.resource, this.props.resource)) {
            return false;
        } else {
            return true;
        }
    }

    render() {

		if (this.props.resource.size == 0) {
			return null;
		}
		let res = this.props.resource.get('data');
        let list = res.toJS();


		let image0 = getSlicedUrl(list[0].src, 100, 50, 2);
        let image0_url = list[0].url;
		let image1 = getSlicedUrl(list[1].src, 100, 50, 2);
        let image1_url = list[1].url;

		return (
			<View style={styles.viewStyle}>
                <TouchableOpacity activeOpacity={0.5}  onPress={() => {
                    this.props.onPressRecommendItem && this.props.onPressRecommendItem(image0_url);
                }}>
					  <Image
					  	  source={{uri: image0}}
						  style={styles.thumbnail}
						  resizeMode={'cover'}
					  ></Image>
                </TouchableOpacity>
                <TouchableOpacity activeOpacity={0.5}  onPress={() => {
                    this.props.onPressRecommendItem && this.props.onPressRecommendItem(image1_url);
                }}>
				      <Image
					  	  source={{uri: image1}}
						  style={styles.thumbnail}
				          resizeMode={'cover'}
				      ></Image>
                </TouchableOpacity>
			</View>
		);
    }
};

let  width = (Dimensions.get('window').width - 45)/2;
let  height = (9*width)/16;

const styles = StyleSheet.create({
    thumbnail: {
        width: width,
        height: height,
        borderRadius: 10,
        marginLeft: 15,
    },
	viewStyle:{
		flexDirection: 'row',
		alignItems: 'center',
        width: Dimensions.get('window').width,
        height: height,
        backgroundColor: '#f0f0f0',
    },
});