MessageIcon.js 2.15 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 MessageIcon extends React.Component {

    static propTypes = {
        msgCount: React.PropTypes.string,
        iconTap: React.PropTypes.func,
    }

    constructor(props) {
        super (props);
    }

    renderMsgCount() {
        if (parseInt(this.props.msgCount) !== 0) {

            return (
                <View style={styles.textContainer}>
                    <Text style={styles.text}>{this.props.msgCount}</Text>
                </View>
            );
        } else {
            return null;
        }
    }

    render() {
        return (
            <View style={[styles.container, this.props.extraStyle]}>
                <TouchableOpacity activeOpacity={0.8} onPress={() => {
                    this.props.iconTap && this.props.iconTap();
                }}>

                    <Image
                        style={styles.icon}
                        source={require('../../images/user/message.png')}
                    />

                    {this.renderMsgCount()}

                </TouchableOpacity>
            </View>
        );
    }
}


let styles = StyleSheet.create ({

    container: {
        flexDirection: 'row',
        alignItems: 'center',
        justifyContent: 'center',
        backgroundColor: 'transparent',
        width: 32,
        height: 23,
    },

    icon: {

    },

    textContainer: {
        position: 'absolute',
        top: -10,
        right: -8,
        height: 18,
        borderRadius: 9,
        borderColor: 'red',
        borderWidth: 1,
        justifyContent: 'center',
        alignItems: 'center',
        opacity: 1,
        backgroundColor: 'white',
        flexDirection:'row',
    },

    text: {
        fontSize: 12,
        color: 'red',
        textAlign: 'center',
        marginHorizontal: 6,
        marginVertical: 6,
        backgroundColor: 'transparent',
    },
});