forked from corymsmith/react-native-icons
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SMXTabBarIconItemIOS.ios.js
96 lines (84 loc) · 2.4 KB
/
SMXTabBarIconItemIOS.ios.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
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
/**
*
* @providesModule SMXTabBarItemIOS
* @flow
*/
'use strict';
var Image = require('Image');
var React = require('React');
var ReactIOSViewAttributes = require('ReactIOSViewAttributes');
var Dimensions = require('Dimensions');
var StaticContainer = require('StaticContainer.react');
var StyleSheet = require('StyleSheet');
var View = require('View');
var createReactIOSNativeComponentClass = require('createReactIOSNativeComponentClass');
var merge = require('merge');
var SmixxTabBarItemIOS = React.createClass({
propTypes: {
//icon: Image.propTypes.source.isRequired,
onPress: React.PropTypes.func.isRequired,
selected: React.PropTypes.bool.isRequired,
badgeValue: React.PropTypes.string,
title: React.PropTypes.string,
style: View.propTypes.style,
},
getInitialState: function() {
return {
hasBeenSelected: false,
};
},
componentWillMount: function() {
if (this.props.selected) {
this.setState({hasBeenSelected: true});
}
},
componentWillReceiveProps: function(nextProps: { selected: boolean }) {
if (this.state.hasBeenSelected || nextProps.selected) {
this.setState({hasBeenSelected: true});
}
},
render: function() {
var tabContents = null;
// if the tab has already been shown once, always continue to show it so we
// preserve state between tab transitions
if (this.state.hasBeenSelected) {
tabContents =
<StaticContainer shouldUpdate={this.props.selected}>
{this.props.children}
</StaticContainer>;
} else {
tabContents = <View />;
}
var icon = {name : this.props.iconName, size: this.props.iconSize ? this.props.iconSize : 28};
return (
<SmixxTabBarItem
icon={icon}
selectedIcon={icon}
onPress={this.props.onPress}
selected={this.props.selected}
badgeValue={this.props.badgeValue}
title={this.props.title}
style={[styles.tab, this.props.style]}>
{tabContents}
</SmixxTabBarItem>
);
}
});
var styles = StyleSheet.create({
tab: {
position: 'absolute',
width: Dimensions.get('window').width,
height: Dimensions.get('window').height,
}
});
var SmixxTabBarItem = createReactIOSNativeComponentClass({
validAttributes: merge(ReactIOSViewAttributes.UIView, {
title: true,
icon: true,
selectedIcon: true,
selected: true,
badgeValue: true,
}),
uiViewClassName: 'SMXTabBarItem'
});
module.exports = SmixxTabBarItemIOS;