UserBrief.js 2.22 KB
'use strict';

import React from 'react';
import ReactNative from 'react-native';
import ImmutablePropTypes from 'react-immutable-proptypes';

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

export default class UserBrief extends React.Component {

    static propTypes = {
        avatar: React.PropTypes.string.isRequired,
        name: React.PropTypes.string.isRequired,
        timeago: React.PropTypes.string.isRequired,
        isOwner: React.PropTypes.bool,
        onPressAvatar: React.PropTypes.func,
    };

    constructor(props) {
        super (props);


    }

    _renderUserName() {
        if (this.props.isOwner) {
            return (
                <Text style={styles.name} numberOfLines={1}>
                    {this.props.name + ' | '}
                    <Text style={styles.owner}>楼主</Text>
                </Text>
            );
        } else {
            return (
                <Text style={styles.name} numberOfLines={1}>
                    {this.props.name}
                </Text>
            );
        }
    }

    render() {
        return (
            <View style={styles.container}>
                <TouchableOpacity onPress={() => {
                    this.props.onPressAvatar && this.props.onPressAvatar();
                }}>
                    <Image style={styles.avatar} source={{uri: this.props.avatar}} resizeMode={'cover'}/>
                </TouchableOpacity>

                <View style={styles.text}>
                    {this._renderUserName()}
                    <Text style={styles.timeago}>{this.props.timeago}</Text>
                </View>
            </View>
        );
    }
}

let styles = StyleSheet.create({
    container: {
        flexDirection: 'row',
        alignItems: 'center',
        backgroundColor: 'white',
    },
    avatar: {
        width: 30,
        height: 30,
        borderRadius: 15,
    },
    text: {
        marginLeft: 5,
    },
    name: {
        fontFamily: 'Helvetica Light',
        color: 'black',
        fontSize: 13,
        width: 130,
    },
    owner: {
        color: '#4a90e2',
    },
    timeago: {
        fontFamily: 'Helvetica Light',
        color: '#b0b0b0',
        fontSize: 10,
    },
});