forked from naqvitalha/react-native-scrollable-tab-header
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Tabs.js
57 lines (52 loc) · 1.57 KB
/
Tabs.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
import React from 'react';
import {
View,
StyleSheet,
Text,
TouchableWithoutFeedback
} from 'react-native';
export default class Tabs extends React.Component {
shouldComponentUpdate(newProps) {
return newProps.isTabActive !== this.props.isTabActive
}
render() {
const {activeTextColor, inactiveTextColor, textStyle,} = this.props;
const textColor = this.props.isTabActive ? activeTextColor : inactiveTextColor;
const fontWeight = this.props.isTabActive ? 'bold' : 'normal';
return <TouchableWithoutFeedback
key={`${name}_${this.props.page}`}
accessible={true}
accessibilityLabel={this.props.name}
accessibilityTraits='button'
onPress={() => this.props.onPressHandler(this.props.page)}
onLayout={this.props.onLayoutHandler}
>
<View style={[styles.tab, this.props.tabStyle,]}>
<Text style={[{color: textColor, fontWeight,}, textStyle,]}>
{this.props.name}
</Text>
</View>
</TouchableWithoutFeedback>;
}
}
const styles = StyleSheet.create({
tab: {
height: 49,
alignItems: 'center',
justifyContent: 'center',
paddingLeft: 20,
paddingRight: 20,
},
container: {
height: 50,
borderWidth: 1,
borderTopWidth: 0,
borderLeftWidth: 0,
borderRightWidth: 0,
borderColor: '#ccc',
},
tabs: {
flexDirection: 'row',
justifyContent: 'space-between',
},
});