summaryrefslogtreecommitdiff
path: root/frontend/app/components/avatar/index.js
blob: b01800ad88e5c09a4e6fdf5b0355952ae919e4f2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import React from 'react';
import {
  Image,
  View,
} from 'react-native';
import {
  RkComponent,
  RkText,
  RkTheme,
} from 'react-native-ui-kitten';
import { FontAwesome } from '../../assets/icons';

export class Avatar extends RkComponent {
  componentName = 'Avatar';
  typeMapping = {
    container: {},
    image: {},
    badge: {},
    badgeText: {},
  };

  getBadgeStyle = (badgeProps) => {
    switch (badgeProps) {
      case 'like':
        return {
          symbol: FontAwesome.heart,
          backgroundColor: RkTheme.current.colors.badge.likeBackground,
          color: RkTheme.current.colors.badge.likeForeground,
        };
      case 'follow':
        return {
          symbol: FontAwesome.plus,
          backgroundColor: RkTheme.current.colors.badge.plusBackground,
          color: RkTheme.current.colors.badge.plusForeground,
        };
      default: return {};
    }
  };

  renderImg = (styles) => (
    <View>
      <Image style={styles.image} source={this.props.img} />
      { this.props.badge && this.renderBadge(styles.badge)}
    </View>
  );

  renderBadge = (style, textStyle) => {
    const badgeStyle = this.getBadgeStyle(this.props.badge);
    return (
      <View style={[style, { backgroundColor: badgeStyle.backgroundColor }]}>
        <RkText rkType='awesome' style={[textStyle, { color: badgeStyle.color }]}>
          {badgeStyle.symbol}
        </RkText>
      </View>
    );
  };

  render() {
    const { container, ...other } = this.defineStyles();
    return (
      <View style={[container, this.props.style]}>
        {this.renderImg(other)}
      </View>
    );
  }
}