UserBrief.js 2.32 KB
'use strict';

import React from 'react';
import ReactNative from 'react-native';
import ImmutablePropTypes from 'react-immutable-proptypes';
import SlicedImage from '../../../common/components/SlicedImage';

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

export default class UserBrief extends React.Component {

    static propTypes = {
        avatar: React.PropTypes.string,
        name: React.PropTypes.string,
        timeago: React.PropTypes.string,
        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();
                }}>
                    <SlicedImage style={styles.avatar} source={{uri: this.props.avatar}} resizeMode={'cover'} defaultSource={require('../../images/user/avatar-default.png')}/>
                </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,
        maxWidth: 130,
    },
    owner: {
        color: '#4a90e2',
    },
    timeago: {
        fontFamily: 'Helvetica Light',
        color: '#b0b0b0',
        fontSize: 10,
    },
});