|
| 1 | +import React, { Component } from 'react'; |
| 2 | +import { View, StyleSheet } from 'react-native'; |
| 3 | +import { TabViewAnimated, TabViewPage, TabBarTop } from 'react-native-tab-view'; |
| 4 | +import ListViewExample from './ListViewExample'; |
| 5 | + |
| 6 | +const styles = StyleSheet.create({ |
| 7 | + container: { |
| 8 | + flex: 1, |
| 9 | + }, |
| 10 | + tabbar: { |
| 11 | + backgroundColor: '#2196f3', |
| 12 | + }, |
| 13 | + indicator: { |
| 14 | + backgroundColor: '#ffeb3b', |
| 15 | + } |
| 16 | +}); |
| 17 | + |
| 18 | +export default class TopBarTextExample extends Component { |
| 19 | + static propTypes = { |
| 20 | + style: View.propTypes.style, |
| 21 | + }; |
| 22 | + |
| 23 | + state = { |
| 24 | + navigation: { |
| 25 | + index: 0, |
| 26 | + routes: [ |
| 27 | + { key: '1', title: 'First' }, |
| 28 | + { key: '2', title: 'Second' }, |
| 29 | + { key: '3', title: 'Third' }, |
| 30 | + ], |
| 31 | + }, |
| 32 | + }; |
| 33 | + |
| 34 | + _handleChangeTab = (index) => { |
| 35 | + this.setState({ |
| 36 | + navigation: { ...this.state.navigation, index }, |
| 37 | + }); |
| 38 | + }; |
| 39 | + |
| 40 | + _renderHeader = (props) => { |
| 41 | + return ( |
| 42 | + <TabBarTop |
| 43 | + {...props} |
| 44 | + pressColor='rgba(0, 0, 0, .2)' |
| 45 | + indicatorStyle={styles.indicator} |
| 46 | + style={styles.tabbar} |
| 47 | + /> |
| 48 | + ); |
| 49 | + }; |
| 50 | + |
| 51 | + _renderScene = ({ route }) => { |
| 52 | + switch (route.key) { |
| 53 | + case '1': |
| 54 | + return <ListViewExample style={{ backgroundColor: '#ff4081' }} />; |
| 55 | + case '2': |
| 56 | + return <ListViewExample style={{ backgroundColor: '#673ab7' }} />; |
| 57 | + case '3': |
| 58 | + return <ListViewExample style={{ backgroundColor: '#4caf50' }} />; |
| 59 | + default: |
| 60 | + return null; |
| 61 | + } |
| 62 | + }; |
| 63 | + |
| 64 | + _renderPage = (props) => { |
| 65 | + return <TabViewPage {...props} renderScene={this._renderScene} />; |
| 66 | + }; |
| 67 | + |
| 68 | + render() { |
| 69 | + return ( |
| 70 | + <TabViewAnimated |
| 71 | + style={[ styles.container, this.props.style ]} |
| 72 | + navigationState={this.state.navigation} |
| 73 | + renderScene={this._renderPage} |
| 74 | + renderHeader={this._renderHeader} |
| 75 | + onRequestChangeTab={this._handleChangeTab} |
| 76 | + /> |
| 77 | + ); |
| 78 | + } |
| 79 | +} |
0 commit comments