-
Notifications
You must be signed in to change notification settings - Fork 0
/
TabUtilsExample.js
112 lines (100 loc) · 3.93 KB
/
TabUtilsExample.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
106
107
108
109
110
111
112
/**
* Created by ananya.chandra on 01/06/18.
*/
import React from 'react';
import {Text, View, StyleSheet, ToastAndroid} from 'react-native';
import TabIndicators from './TabIndicators';
import TabUtilsBar from './TabUtilsBar';
import {TabViewAnimated} from 'rn-keyboard-aware-tab-view';
export default class TabUtilsExample extends React.Component {
constructor(props) {
super(props);
this._getTabUtilsButtonViews = this._getTabUtilsButtonViews.bind(this);
this._onTabViewScroll = this._onTabViewScroll.bind(this);
this.tabs = [0, 1, 2];
this.openingTabIndex = 0;
this.tabButtonViews = this._getTabUtilsButtonViews();
}
render() {
return (
<View style={{flex: 1}}>
<TabViewAnimated
onIndexChange={() => {}}
onPositionChange={this._onTabViewScroll}
style={{flex: 1}}
keyboardDismissMode='none'
navigationState={{
index: this.openingTabIndex,
routes: this.tabs.map((item, position) => {
return {data: item, index: position};
})
}}
renderScene={({route, navigationState}) => {
return (
<View style={{flex: 1, alignItems: 'center', justifyContent: 'center'}}>
<Text style={{margin: 30, fontSize: 20, alignSelf: 'center'}}>Tab {route.data + 1}</Text>
</View>
);
}}
/>
<View style={{height: 1, backgroundColor: '#F0F0F0'}}/>
<TabIndicators ref={(ref) => {this.tabIndicator = ref;}}
tabs={this.tabs}
openingTabIndex={this.openingTabIndex}
activeColor='#E0202C' //YNWA
tabIndicatorsView={{borderRadius: 0}}
/>
<View style={{height: 1, backgroundColor: '#F0F0F0'}}/>
<TabUtilsBar ref={(ref) => {this.tabUtilsBar = ref; }}
buttonViews={this.tabButtonViews}
selectedTabIndex={0}
tabUtilsBarContainer={{
backgroundColor: 'white'
}}
tabIndicatorProps={{
activeColor: '#2874f0',
inactiveColor: 'lightgray'
}}
/>
</View>
);
}
_onTabViewScroll(value) {
this.tabUtilsBar.updateOffset(value);
this.tabIndicator.updateOffset(value);
}
_getTabUtilsButtonViews() {
let buttonViews = [];
this.tabs.forEach((tab) => {
switch (tab) {
case 0:
buttonViews.push([
(<Text style={styles.buttonViews} onPress={() => this._showToast('TAB 1.1')}>TAB 1.1</Text>),
(<Text style={styles.buttonViews} onPress={() => this._showToast('TAB 1.2')}>TAB 1.2</Text>)
]);
break;
case 1:
buttonViews.push(null);
break;
case 2:
buttonViews.push([
(<View/>),
(<Text style={styles.buttonViews} onPress={() => this._showToast('TAB 3.2')}>TAB 3.2</Text>)
]);
break;
}
});
return buttonViews;
}
_showToast(message) {
ToastAndroid.show(message, ToastAndroid.SHORT);
}
}
const styles = StyleSheet.create({
buttonViews: {
alignSelf: 'flex-end',
color: '#2874f0',
fontSize: 14,
padding: 14
}
});