Header.js 3.24 KB
'use strict';

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

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


export default class Header extends React.Component {
    constructor(props) {
        super(props);
    }

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


    render() {

		let {resource} = this.props;
        let {author,article} = resource;

		let author_data = author.get('data');
        let article_data = article.get('data');
		if (!author_data || !article_data) {
			return null;
		}

        let author_desc = author_data.get('author_desc');
        let author_avatar = author_data.get('avatar');
        let author_name = author_data.get('name');
        let author_url = author_data.get('url');

        let article_title = article_data.get('article_title');
        let pageViews = article_data.get('pageViews');
        let publishTime = article_data.get('publishTime');

        return(
            <View style={styles.contentContainer}>
                <TouchableOpacity activeOpacity={0.5} onPress={() => {
    				// this.props.onPressBrandItem && this.props.onPressBrandItem(rowData.url, rowID);
    			}}>
                    <View style={styles.header}>
    					<Image source={{uri: author_avatar}} style={styles.thumb}></Image>
                        <Text style={styles.name}>{author_name}</Text>
    					<Text style={styles.desc}>{author_desc}</Text>
                    </View>
                </TouchableOpacity>
                <View style={{width: width,height: 0.5,backgroundColor: '#e5e5e5',}}/>
                <Text style={styles.article_title}>{article_title}</Text>
                <View style={styles.time}>
                    <Image source={require('../../image/time_icon.png')} style={styles.timeThumb}resizeMode={'contain'}></Image>
                    <Text style={styles.text}>{publishTime}</Text>
                    <Image source={require('../../image/shared_view_icon.png')} style={styles.timeThumb}resizeMode={'contain'}></Image>
                    <Text style={styles.text}>{pageViews}</Text>
                </View>
                <View style={{width: width,height: 10}}/>
            </View>
        );
    }
};


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

let styles = StyleSheet.create({
	contentContainer: {
        width:width,
		backgroundColor: 'white',
    },
	header: {
        flexDirection: 'row',
		height: 47.5,
		width:width,
		alignItems: 'center',
	},
	thumb: {
		width: 25,
		height: 25,
		marginLeft: 20,
		borderRadius: 12,
	},
	name: {
		marginLeft: 20,
	},
	desc: {
		marginLeft: 20,
		color: '#e5e5e5',
	},
    article_title: {
        marginLeft: 20,
        marginRight: 10,
        fontSize: 23,
        fontWeight: 'bold',
        lineHeight: 35,
    },
    time: {
        flexDirection: 'row',
		height: 20,
		width:width,
		alignItems: 'center',
        marginTop: 5,
	},
    timeThumb: {
        marginLeft: 20,
		height: 12,
		width:20,
	},
    text: {
        marginLeft: 5,
        fontSize: 12,
        color: 'gray'
    },
});