forked from ptomasroos/react-native-tab-navigator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Tab.js
105 lines (95 loc) · 2.11 KB
/
Tab.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
97
98
99
100
101
102
103
104
105
'use strict';
import React, {
PropTypes,
} from 'react';
import {
StyleSheet,
Text,
TouchableOpacity,
View,
} from 'react-native';
import Layout from './Layout';
export default class Tab extends React.Component {
static propTypes = {
testID : PropTypes.string,
title: PropTypes.string,
titleStyle: Text.propTypes.style,
badge: PropTypes.element,
onPress: PropTypes.func,
hidesTabTouch: PropTypes.bool,
allowFontScaling: PropTypes.bool,
style: View.propTypes.style,
};
constructor(props, context) {
super(props, context);
this._handlePress = this._handlePress.bind(this);
}
render() {
let { title, badge } = this.props;
let icon = null;
if (React.Children.count(this.props.children) > 0) {
icon = React.Children.only(this.props.children);
}
if (title) {
title =
<Text
numberOfLines={1}
allowFontScaling={!!this.props.allowFontScaling}
style={[styles.title, this.props.titleStyle]}>
{title}
</Text>;
}
if (badge) {
badge = React.cloneElement(badge, {
style: [styles.badge, badge.props.style],
});
}
let tabStyle = [
styles.container,
title ? null : styles.untitledContainer,
this.props.style,
];
return (
<TouchableOpacity
testID={this.props.testID}
activeOpacity={this.props.hidesTabTouch ? 1.0 : 0.8}
onPress={this._handlePress}
style={tabStyle}>
<View>
{icon}
{badge}
</View>
{title}
</TouchableOpacity>
);
}
_handlePress(event) {
if (this.props.onPress) {
this.props.onPress(event);
}
}
}
let styles = StyleSheet.create({
badge: {
position: 'absolute',
top: -6,
right: -10,
},
container: {
flex: 1,
flexDirection: 'column',
justifyContent: 'flex-end',
alignItems: 'center',
},
untitledContainer: {
paddingBottom: 13,
},
title: {
color: '#929292',
fontSize: 10,
textAlign: 'center',
alignSelf: 'stretch',
marginTop: 4,
marginBottom: 1 + Layout.pixel,
},
});