-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtab.js
86 lines (82 loc) · 2.94 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
import React, { Component } from 'react';
import {
Platform,
StyleSheet,
TouchableOpacity,
Text,
View,
NavigatorIOS
} from 'react-native';
export default class Tabs extends Component {
// Initialize State
state = {
// First tab is active by default
activeTab: 0
}
// Pull children out of props passed from App component
render({ children } = this.props) {
return (
<View style={styles.container}>
{/* Tabs row */}
<View style={styles.tabsContainer}>
{/* Pull props out of children, and pull title out of props */}
{children.map(({ props: { title } }, index) =>
<TouchableOpacity
style={[
// Default style for every tab
styles.tabContainer,
// Merge default style with styles.tabContainerActive for active tab
index === this.state.activeTab ? styles.tabContainerActive : []
]}
// Change active tab
onPress={() => this.setState({ activeTab: index })}
// Required key prop for components generated returned by map iterator
key={index}
>
<Text style={styles.tabText}>
{title}
</Text>
</TouchableOpacity>
)}
</View>
{/* Content */}
<View style={styles.contentContainer}>
{children[this.state.activeTab]}
</View>
</View>
);
}
}
const styles = StyleSheet.create({
// Component container
container: {
flex: 1, // Take up all available space
},
// Tabs row container
tabsContainer: {
flexDirection: 'row', // Arrange tabs in a row
paddingTop: 30, // Top padding
},
// Individual tab container
tabContainer: {
flex: 1, // Take up equal amount of space for each tab
paddingVertical: 15, // Vertical padding
borderBottomWidth: 3, // Add thick border at the bottom
borderBottomColor: 'transparent', // Transparent border for inactive tabs
},
// Active tab container
tabContainerActive: {
borderBottomColor: '#FFFFFF', // White bottom border for active tabs
},
// Tab text
tabText: {
color: '#FFFFFF',
fontFamily: 'Avenir',
fontWeight: 'bold',
textAlign: 'center',
},
// Content container
contentContainer: {
flex: 1 // Take up all available space
}
});