BrandIntro.js 4.2 KB
/*
 * 潮流优选、明星原创
 */

'use strict';

import React, {Component} from 'react';
import ReactNative, {
    View,
    ScrollView,
    Text,
    NativeAppEventEmitter,
    StyleSheet,
    Image,
    Dimensions,
    TouchableOpacity,
} from 'react-native';
import Immutable, {Map} from 'immutable';
import SlicedImage from '../../../common/components/SlicedImage';


export default class BrandIntro extends Component {

    constructor(props) {
        super(props);
    }

    componentDidMount() {

    }

    render() {
        let{brandIntro, brandFav}=this.props;
        let detail = brandIntro.get('detail').toJS();
        let favIcon = brandFav.get('isFav') ? require("../../images/red_heart.png") : require("../../images/gray_heart.png");
        let titleFoldArrowIcon = brandIntro.titleUnfold ? require("../../images/arrow_small_up.png") : require("../../images/arrow_small_down.png");
        return (
            <View style={styles.container}>
                <SlicedImage style={styles.coverImage} source={{uri: detail.cover_img}} style={{width, height:coverImageHeight}}/>

                <View style={styles.titleLikeView}>

                    <TouchableOpacity onPress={() => {
                        this.props.onPressFav && this.props.onPressFav(!brandFav.get('isFav'));
                    }}>
                    <Image style={styles.like} source={favIcon} />

                    </TouchableOpacity>
                    <Text style={styles.title}>
                        {detail.brand_name}
                    </Text>
                </View>

                <Text style={styles.intro} numberOfLines={brandIntro.titleUnfold ? 0 : 4}>
                    {detail.brand_intro}
                </Text>

                <TouchableOpacity onPress={() => {
                    this.props.onPressBrandIntroMore && this.props.onPressBrandIntroMore(!brandIntro.titleUnfold);
                }}>
                    <View style={styles.moreView}>
                        <Image style={styles.moreArrow} source={titleFoldArrowIcon}/>
                        <Text style={styles.moreText}>
                            {brandIntro.titleUnfold ? '收起' : 'more'}
                        </Text>
                    </View>
                </TouchableOpacity>

                <View style={styles.brandIcon}>
                    <SlicedImage resizeMode={'stretch'} source={{uri: detail.brand_ico}} style={{width:brandIconWidth-2, height:brandIconWidth-2}}/>

                </View>

                <View style={styles.blackView}>
                </View>
            </View>
        );
    }
}
let {width, height} = Dimensions.get('window');
const DEVICE_WIDTH_RATIO = width / 320;
let coverImageHeight = 155 * DEVICE_WIDTH_RATIO;
let brandIconWidth = 84 * DEVICE_WIDTH_RATIO;

let styles = StyleSheet.create({
    container: {
        backgroundColor: 'white',
    },
    coverImage: {
        height: 200,
    },
    brandIcon: {
        position: 'absolute',
        top: 116 * DEVICE_WIDTH_RATIO,
        left: 25 * DEVICE_WIDTH_RATIO,
        borderWidth: 1,
        height: brandIconWidth,
        width: brandIconWidth,
        borderWidth: 1,
        borderColor: '#b5b5b5',
    },
    titleLikeView: {
        height:41 * DEVICE_WIDTH_RATIO,
        flexDirection: 'row-reverse',
    },
    title: {
        fontSize: 17 * DEVICE_WIDTH_RATIO,
        width: 147.5 * DEVICE_WIDTH_RATIO,
        height: 20.5 * DEVICE_WIDTH_RATIO,
        top: 12 * DEVICE_WIDTH_RATIO,
    },
    like: {
        width: 17 * DEVICE_WIDTH_RATIO,
        height: 16 * DEVICE_WIDTH_RATIO,
        margin: 15 * DEVICE_WIDTH_RATIO,
    },
    intro: {
        margin: 15 * DEVICE_WIDTH_RATIO,
        fontSize: 12 * DEVICE_WIDTH_RATIO,
        color: '#444444',
        lineHeight:  Math.ceil(18 * DEVICE_WIDTH_RATIO),
    },
    moreView: {
        paddingBottom: 15 * DEVICE_WIDTH_RATIO,
        flexDirection: 'row-reverse',
    },
    moreText: {
        fontSize: 14 * DEVICE_WIDTH_RATIO,
        color: '#bbbbbb',
    },
    moreArrow: {
        marginTop: 5 * DEVICE_WIDTH_RATIO,
        marginLeft: 15 * DEVICE_WIDTH_RATIO,
        marginRight: 15 * DEVICE_WIDTH_RATIO,
    },
    blackView: {
        backgroundColor: '#f0f0f0',
        height: 15 * DEVICE_WIDTH_RATIO,
    }
});