LittleRedDotImage.js 2.35 KB
'use strict';

import React from 'react';
import PropTypes from 'prop-types';
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 = {
        isRedDot: PropTypes.bool,
        defaultSource: Image.propTypes.source,
        image: PropTypes.string,
        iconTap: PropTypes.func,
    }

    constructor(props) {
        super (props);
    }

    renderLittleRedDot() {
        if (this.props.isRedDot) {
            return (
                <View style={styles.redDot}>

                </View>
            );
        } else {
            return null;
        }
    }

    render() {

        let defaultSource = this.props.defaultSource || require('../../images/avatar/avatar_default.png');

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

                    <SlicedImage
                        style={styles.icon}
                        defaultSource={defaultSource}
                        source={{uri: this.props.image}}

                    />

                    {this.renderLittleRedDot()}

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


let styles = StyleSheet.create ({

    container: {
        flexDirection: 'row',
        alignItems: 'center',
        justifyContent: 'center',
        backgroundColor: 'transparent',
        width: 32,
        height: 23,
    },
    icon: {
        width: 30,
        height: 30,
        borderRadius: 15,
    },
    redDot: {
        position: 'absolute',
        top: 0,
        right: 0,
        height: 7,
        width: 7,
        borderRadius: 3.5,
        borderColor: 'red',
        justifyContent: 'center',
        alignItems: 'center',
        backgroundColor: 'red',
        flexDirection:'row',
    },
    text: {
        fontSize: 12,
        color: 'red',
        textAlign: 'center',
        marginHorizontal: 6,
        marginVertical: 6,
        backgroundColor: 'transparent',
    },
});