forked from GeekyAnts/NativeBase
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
108 lines (98 loc) · 2.77 KB
/
index.js
File metadata and controls
108 lines (98 loc) · 2.77 KB
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { Platform } from 'react-native';
import { connectStyle } from 'native-base-shoutem-theme';
import variable from '../../theme/variables/platform';
import mapPropsToStyleNames from '../../utils/mapPropsToStyleNames';
import { IconNB } from '../IconNB';
import ic from './NBIcons.json';
class Icon extends Component {
static contextTypes = {
theme: PropTypes.object
};
getName() {
const variables = this.context.theme
? this.context.theme['@@shoutem.theme/themeStyle'].variables
: variable;
const platformStyle = variables.platformStyle;
const platform = variables.platform;
if ((this.props.type || variables.iconFamily) === 'Ionicons') {
if (typeof ic[this.props.name] !== 'object') {
return this.props.name;
} else if (typeof ic[this.props.name] === 'object') {
let name;
if (platform === 'ios' && platformStyle !== 'material') {
name = this.props.active
? ic[this.props.name].ios.active
: ic[this.props.name].ios.default;
} else {
name = this.props.active
? ic[this.props.name].android.active
: ic[this.props.name].android.default;
}
return name;
}
} else {
return this.props.name;
}
return null;
}
getIconName() {
if (Platform.OS === 'ios') {
if (this.props.ios) {
return this.props.ios;
}
return this.props.active
? ic[this.props.name].ios.active
: ic[this.props.name].ios.default;
} else if (this.props.android) {
return this.props.android;
}
return this.props.active
? ic[this.props.name].android.active
: ic[this.props.name].android.default;
}
render() {
if (this.props.ios && this.props.android) {
return (
<IconNB
ref={c => (this._root = c)}
{...this.props}
name={Platform.OS === 'ios' ? this.props.ios : this.props.android}
/>
);
} else if (this.props.name && (this.props.android || this.props.ios)) {
return (
<IconNB
ref={c => (this._root = c)}
{...this.props}
name={this.getIconName()}
/>
);
}
return (
<IconNB
ref={c => (this._root = c)}
{...this.props}
name={this.getName()}
/>
);
}
}
Icon.propTypes = {
...IconNB.propTypes,
style: PropTypes.oneOfType([
PropTypes.object,
PropTypes.number,
PropTypes.array
]),
name: PropTypes.string,
ios: PropTypes.string,
android: PropTypes.string,
active: PropTypes.bool,
type: PropTypes.string
};
const StyledIcon = connectStyle('NativeBase.Icon', {}, mapPropsToStyleNames)(
Icon
);
export { StyledIcon as Icon };