SmallPic.js 2.72 KB
'use strict';

import React from 'react';
import ReactNative from 'react-native';
import YH_Image from '../../../common/components/YH_Image';
import Immutable, {Map} from 'immutable';

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

export default class SmallPic extends React.Component {

    constructor(props) {
        super (props);

    }

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

    render() {
        let {data} = this.props;
        
        if (!data || data.size == 0) {
            return null;
        }

        let url1 = YH_Image.getSlicedUrl(data.get(0).get('src'), imageWidth, imageHeight, 2);
        let url2 = YH_Image.getSlicedUrl(data.get(1).get('src'), imageWidth, imageHeight, 2);

        return (
            <View style={styles.container}>
                <TouchableOpacity
                    activeOpacity={1}
                    onPress={() => {
                        this.props.onPressPicItem && this.props.onPressPicItem(data.get(0).get('url'), 0);
                    }}
                >
                    <YH_Image
                        url={url1}
                        masksToBounds={true}
                        radius={{'topLeft':'3','topRight':'3','bottomRight':'3','bottomLeft':'3'}}
                        style={[styles.image, styles.left]}
                    />
                </TouchableOpacity>
                <TouchableOpacity
                    activeOpacity={1}
                    onPress={() => {
                        this.props.onPressPicItem && this.props.onPressPicItem(data.get(1).get('url'), 1);
                    }}
                >
                    <YH_Image
                        url={url2}
                        masksToBounds={true}
                        radius={{'topLeft':'3','topRight':'3','bottomRight':'3','bottomLeft':'3'}}
                        style={[styles.image, styles.right]}
                    />
                </TouchableOpacity>
            </View>
        );
    }
}

let {width, height} = Dimensions.get('window');

const DEVICE_WIDTH_RATIO = width / 320;
let containerHeight = Math.ceil(80 * (width - 45) / 2 / 137.5);
let imageWidth = Math.ceil((width - 45) / 2);
let imageHeight =  Math.ceil(80 * (imageWidth / 137.5));

let styles = StyleSheet.create({
    container: {
        width: width,
        height: containerHeight,
        flexDirection: 'row',
    },
    image: {
        width: imageWidth,
        height: imageHeight,
        borderRadius: 3,
        backgroundColor: 'white',
        marginLeft: 15,
    },
    left: {

    },
    right: {

    },
});