Title.js 3.76 KB
'use strict';

import React from 'react';
import ReactNative from 'react-native';
import Immutable, {Map} from 'immutable';
import DeviceInfo from 'react-native-device-info';

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

export default class Title extends React.Component {

    constructor(props) {
        super (props);
    }

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

    render() {

        let {resource} = this.props;
        if (!resource) {
            return null;
        }
        let yh_exposureData = this.props.yh_exposureData?this.props.yh_exposureData:null;

		let fontFamilyStyle = {};
 		if (Platform.OS === 'ios') {
 			let systemVersion = DeviceInfo.getSystemVersion();
 			systemVersion = parseFloat(systemVersion);
 			if (systemVersion >= 9.0) {
 				fontFamilyStyle = {fontFamily: 'PingFang SC'};
 			}
 		}

        let list = resource.get('module_data').get('data').toJS();
        let data = list?list[0]:null;
        let linkType = data.linkType;
        let linkReource = data.resource;
        let title = data.text;
        let hasMoreButton = linkType==''?false:true;
        let moduleOrder = resource.get('module_order') + 1;
        let moduleType = resource.get('module_type');
        let properties = resource.get('module_data').get('properties').toJS();
        let isModuleMargin = properties.isModuleMargin;

        let url = '';
        if (linkType == '0') {
            url = `http://m.yohobuy.com?openby:yohobuy={"action":"go.poollist","params":{"productPool":"${linkReource}"}}`;
        } else if (linkType == '1') {
            url = `http://m.yohobuy.com?openby:yohobuy={"action":"go.productDetail","params":{"product_skn":"${linkReource}"}}`;
        } else if (linkType == '2') {
            url = linkReource;
        }
        if (yh_exposureData) {
            yh_exposureData = {
                I_INDEX: 0,
                ACTION_URL: url,
                ...yh_exposureData,
            };
        }

	  	return(
			<View style={[styles.container,{height: isModuleMargin=='1'?40+10:40,backgroundColor: '#f0f0f0'}]}>
                <View style={{width: width,height: 0.5,backgroundColor: '#e5e5e5'}}/>
				<View style={styles.title}>
					<Text style={[styles.text, fontFamilyStyle]}>{title}</Text>
                    {hasMoreButton?
                    <TouchableOpacity yh_exposureData={yh_exposureData} activeOpacity={0.5} style={styles.thumbnail} onPress={() => {
                        this.props.onPressProduct && this.props.onPressProduct(linkType,linkReource,moduleOrder,moduleType,0);
                    }}>
                      	<Image
                            source={require('../../../brandStore/image/btn_more_p.png')}
                            style={{width: 22, height: 4,marginLeft:3}}
                            resizeMode={'contain'}
                        />
                    </TouchableOpacity>:null}
				</View>
                <View style={{width: width,height: 0.5,backgroundColor: '#e5e5e5'}}/>
			</View>
		);
    }
}

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

let styles = StyleSheet.create({
    container: {
        height: 40,
		width: width,
    },
	title: {
		alignItems: 'center',
		justifyContent: 'center',
		height: 39,
		width: width,
		backgroundColor: '#e5e5e5',
    },
	text: {
		textAlign: 'left',
		fontSize: 16,
		fontWeight: 'bold',
		color: '#444',
    },
    thumbnail: {
        position: 'absolute',
        width: 40,
        height: 38,
        top: 1,
        bottom: 1,
        marginLeft: width - 40,
        backgroundColor: 'transparent',
        justifyContent: 'center',
    },
});