summaryrefslogtreecommitdiffhomepage
path: root/app/components/Img.android.js
blob: 229cb2c1b712044240bdea2cb333084058359531 (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
// @flow
import React, { Component } from 'react';
import { StyleSheet } from 'react-native';
import { Image, Styles } from 'reactxp';

export default class Img extends Component {
  props: {
    source: string,
    style: Object,
    tintColor?: string,
    height?: number,
    width?: number,
  };

  render() {
    const width = this.props.width || 7;
    const height = this.props.height || 12;
    const source = this.props.source || 'icon-chevron';
    const tintColor = this.props.tintColor || 'currentColor';

    if (tintColor === 'currentColor' && this.props.style) {
      const { color: tint, ...otherStyles } = StyleSheet.flatten(this.props.style);
      return (
        <Image
          style={Styles.createViewStyle(
            { ...otherStyles, tintColor: tint, height: height, width: width },
            false,
          )}
          source={source}
        />
      );
    } else {
      return (
        <Image
          style={Styles.createViewStyle(
            { ...this.props.style, height: height, width: width },
            false,
          )}
          source={source}
        />
      );
    }
  }
}