-
Notifications
You must be signed in to change notification settings - Fork 55
/
Copy pathFlag.js
55 lines (50 loc) · 1.37 KB
/
Flag.js
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
/**
* SVG or PNG
*
* width : height = 21 : 15
*/
import React, { Component } from 'react';
import { View, Text, Image, TouchableOpacity } from 'react-native';
import PropTypes from 'prop-types';
import { getFlagByDollarCode } from 'react-native-svg-flagkit'
export default class Flag extends Component {
static propTypes = {
id: PropTypes.string,
size: PropTypes.number,
width: PropTypes.number,
height: PropTypes.number,
onPress: PropTypes.func
};
static defaultProps = {
size: 1,
width: 210,
height: 150
};
_renderIcon() {
const { size, width, height, id } = this.props
const flag = getFlagByDollarCode(id)
if (typeof flag === 'function') {
const SvgComponent = flag
return <SvgComponent width={width * size} height={height * size} />
}
return (
<Image
style={{ width: width * size, height: height * size }}
source={flag}
/>
)
}
_onPress = () => {
this.props.onPress && this.props.onPress(this.props.id)
}
render() {
return (
<TouchableOpacity
disabled={!this.props.onPress}
onPress={this._onPress}
>
{ this._renderIcon() }
</TouchableOpacity>
)
}
}