-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathStatefulTabLayout.js
58 lines (55 loc) · 1.38 KB
/
StatefulTabLayout.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
import React, {
Component,
} from 'react';
import {
StyleSheet,
Text,
TouchableOpacity,
View
} from 'react-native';
import { Tab, TabLayout } from 'react-native-android-tablayout'
import Labels from './Labels';
export default class StatefulTabLayout extends Component {
constructor() {
super(...arguments);
this.state = {
pagePosition: 2, // start on third tab
};
}
render() {
return (
<View>
<TabLayout
style={styles.tabLayout}
selectedTab={this.state.pagePosition}
onTabSelected={(e:Event) => {
this.setState({ pagePosition: e.nativeEvent.position });
}}>
<Tab name="Tab 1" accessibilityLabel={Labels.Stateful.tab1}/>
<Tab name="Tab 2" accessibilityLabel={Labels.Stateful.tab2}/>
<Tab name="Tab 3" accessibilityLabel={Labels.Stateful.tab3}/>
</TabLayout>
<TouchableOpacity
style={styles.button}
onPress={() => {
this.setState({ pagePosition: 1 });
}}>
<View accessibilityLabel={Labels.Stateful.button}>
<Text>Switch to second tab</Text>
</View>
</TouchableOpacity>
</View>
);
}
}
const styles = StyleSheet.create({
tabLayout: {
backgroundColor: '#ddd'
},
button: {
borderWidth: 1,
borderColor: '#888',
margin: 10,
padding: 10,
},
});