forked from nazrdogan/react-native-vector-icons
-
Notifications
You must be signed in to change notification settings - Fork 0
/
RNIMigration.js
59 lines (51 loc) · 1.56 KB
/
RNIMigration.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
55
56
57
58
59
import React, { PureComponent } from 'react';
import PropTypes from 'prop-types';
import FontAwesome from 'react-native-vector-icons/FontAwesome';
import Foundation from 'react-native-vector-icons/Foundation';
import Ionicons from 'react-native-vector-icons/Ionicons';
import MaterialIcons from 'react-native-vector-icons/MaterialIcons';
import Zocial from 'react-native-vector-icons/Zocial';
import SimpleLineIcons from 'react-native-vector-icons/SimpleLineIcons';
const ICON_SET_MAP = {
fontawesome: FontAwesome,
foundation: Foundation,
ion: Ionicons,
material: MaterialIcons,
zocial: Zocial,
simpleline: SimpleLineIcons,
};
// This is a composition is a drop in replacement for users migrating from the
// react-native-icons module. Please don't use this component for new apps/views.
export default class Icon extends PureComponent {
static propTypes = {
name: PropTypes.string.isRequired,
size: PropTypes.number,
color: PropTypes.string,
};
setNativeProps(nativeProps) {
if (this.iconRef) {
this.iconRef.setNativeProps(nativeProps);
}
}
iconRef = null;
handleComponentRef = ref => {
this.iconRef = ref;
};
render() {
const nameParts = this.props.name.split('|');
const setName = nameParts[0];
const name = nameParts[1];
const IconSet = ICON_SET_MAP[setName];
if (!IconSet) {
throw new Error(`Invalid icon set "${setName}"`);
}
return (
<IconSet
allowFontScaling={false}
ref={this.handleComponentRef}
{...this.props}
name={name}
/>
);
}
}