@@ -10,8 +10,13 @@ import Icon from '../Icon';
10
10
const propTypes = {
11
11
/**
12
12
* Will be rendered above the label as a content of the action.
13
+ * If string, result will be <Icon name={icon} ...rest />
14
+ * If ReactElement, will be used as is
13
15
*/
14
- icon : PropTypes . string . isRequired ,
16
+ icon : PropTypes . oneOfType ( [
17
+ PropTypes . element ,
18
+ PropTypes . string ,
19
+ ] ) . isRequired ,
15
20
/**
16
21
* Will be rendered under the icon as a content of the action.
17
22
*/
@@ -79,16 +84,29 @@ function getStyles(props, context) {
79
84
80
85
81
86
class BottomNavigationAction extends PureComponent {
87
+
88
+ renderIcon ( icon , styles , color ) {
89
+ let element ;
90
+ if ( React . isValidElement ( icon ) ) {
91
+ element = icon ;
92
+ } else {
93
+ element = < Icon name = { icon } style = { styles . icon } color = { color } /> ;
94
+ }
95
+ return element ;
96
+ }
97
+
82
98
render ( ) {
83
99
const { icon, label, onPress } = this . props ;
84
100
85
101
const styles = getStyles ( this . props , this . context ) ;
86
102
const color = StyleSheet . flatten ( styles . icon ) . color ;
87
103
104
+ const iconElement = this . renderIcon ( icon , styles , color ) ;
105
+
88
106
return (
89
107
< RippleFeedback onPress = { onPress } >
90
108
< View style = { styles . container } >
91
- < Icon name = { icon } style = { styles . icon } color = { color } />
109
+ { iconElement }
92
110
< Text style = { styles . label } > { label } </ Text >
93
111
</ View >
94
112
</ RippleFeedback >
0 commit comments