Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const React = require('react');
- const ReactNative = require('react-native');
- const {
- StyleSheet,
- Text,
- View,
- Animated,
- } = ReactNative;
- const Button = require('./Button');
- const DefaultTabBar = React.createClass({
- propTypes: {
- goToPage: React.PropTypes.func,
- activeTab: React.PropTypes.number,
- tabs: React.PropTypes.array,
- backgroundColor: React.PropTypes.string,
- activeTextColor: React.PropTypes.string,
- inactiveTextColor: React.PropTypes.string,
- textStyle: Text.propTypes.style,
- tabStyle: View.propTypes.style,
- renderTab: React.PropTypes.func,
- underlineStyle: View.propTypes.style,
- },
- getDefaultProps() {
- return {
- activeTextColor: 'navy',
- inactiveTextColor: 'black',
- backgroundColor: null,
- activeBackgroundColor: null,
- };
- },
- renderTabOption(name, page) {
- },
- renderTab(name, page, isTabActive, onPressHandler) {
- const { activeTextColor, inactiveTextColor, textStyle, activeBackgroundColor } = this.props;
- const textColor = isTabActive ? activeTextColor : inactiveTextColor;
- const fontWeight = isTabActive ? 'bold' : 'normal';
- const backgroundColor = isTabActive ? activeBackgroundColor : backgroundColor;
- return <Button
- style={styles.flexOne}
- key={name}
- accessible={true}
- accessibilityLabel={name}
- accessibilityTraits='button'
- onPress={() => onPressHandler(page)}
- >
- <View style={[styles.tab, this.props.tabStyle, { backgroundColor } ]}>
- <Text style={[{color: textColor, fontWeight }, textStyle, ]}>
- {name}
- </Text>
- </View>
- </Button>;
- },
- render() {
- const containerWidth = this.props.containerWidth;
- const numberOfTabs = this.props.tabs.length;
- const tabUnderlineStyle = {
- position: 'absolute',
- width: containerWidth / numberOfTabs,
- height: 4,
- backgroundColor: 'navy',
- bottom: 0,
- };
- const left = this.props.scrollValue.interpolate({
- inputRange: [0, 1, ], outputRange: [0, containerWidth / numberOfTabs, ],
- });
- return (
- <View style={[styles.tabs, {backgroundColor: this.props.backgroundColor, }, this.props.style, ]}>
- {this.props.tabs.map((name, page) => {
- const isTabActive = this.props.activeTab === page;
- const renderTab = this.props.renderTab || this.renderTab;
- return renderTab(name, page, isTabActive, this.props.goToPage);
- })}
- <Animated.View style={[tabUnderlineStyle, { left, }, this.props.underlineStyle, ]} />
- </View>
- );
- },
- });
- const styles = StyleSheet.create({
- tab: {
- flex: 1,
- alignItems: 'center',
- justifyContent: 'center',
- paddingBottom: 10,
- },
- flexOne: {
- flex: 1,
- },
- tabs: {
- height: 50,
- flexDirection: 'row',
- justifyContent: 'space-around',
- borderWidth: 1,
- borderTopWidth: 0,
- borderLeftWidth: 0,
- borderRightWidth: 0,
- borderColor: '#ccc',
- },
- });
- module.exports = DefaultTabBar;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement