Title.js 2.73 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 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;

	  	return(
			<View style={styles.container}>
                <View style={{width: width,height: 0.5,backgroundColor: '#e5e5e5'}}/>
				<View style={styles.title}>
					<Text style={[styles.text, fontFamilyStyle]}>{title}</Text>
                    {hasMoreButton?
                    <TouchableOpacity activeOpacity={0.5} style={styles.thumbnail} onPress={() => {
                        this.props.onPressProduct && this.props.onPressProduct(linkType,linkReource);
                    }}>
                      	<Image
                            source={require('../../../brandStore/image/btn_more_p.png')}
                            style={{width: 22, height: 4,backgroundColor:'white',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: 'white',
    },
	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',
    },
});