1.0.8 • Published 7 years ago

react-native-simple-tab v1.0.8

Weekly downloads
11
License
MIT
Repository
github
Last release
7 years ago

react-native-simple-tab

A React Native Tab Navigation, made for simplicity, works on both Android and iOS.

demo

iOS (Left) | Android (right)

npm.io

onlyIcon props on Nav set to true

Features

  • worked with (react-native-router-flux) or any kind of navigation solutions
  • cross-platform icons by default
  • simple and clean UI

Inspiration

Salestock Indonesia

Installation

  • npm install --save react-native-simple-tab react-native-vector-icons

After Installation (this step is required)

  • react-native link

Basic Usage

import React, { Component } from 'react';
import {
  StyleSheet,
  Text,
  View,
} from 'react-native';
import { Nav, Tab } from 'react-native-simple-tab';

class MyExample extends Component {
  constructor() {
    super();

    this.state = {
      page: 0,
    };

    this._onTabChange = this._onTabChange.bind(this);
  }

  _onTabChange(tabIndex) {
    this.setState({ page: tabIndex });
  }
  
  render() {
    return (
      <View style={styles.container}>
        <Text style={styles.welcome}>
          Welcome to React Native!
        </Text>
        <Text style={styles.myPackage}>
          react-native-cross-platform-tab
        </Text>
        <View style={{ flex: 1 }}>
          <Text style={styles.myText}>
            Selected Tab Index
          </Text>
          <Text style={styles.myTabIndex}>
            {this.state.page}
          </Text>
        </View>
        <Nav
          selected={this.state.page}
          onTabChange={this._onTabChange}>
            <Tab name="home" label="Home" />
            <Tab name="heart" label="Favorite" />
            <Tab name="cart" label="Cart" />
            <Tab name="shirt" label="Custom" />
            <Tab name="menu" label="Menu" />
        </Nav>
      </View>
    );
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    backgroundColor: '#F5FCFF',
  },
  welcome: {
    flex: 1,
    fontSize: 20,
    textAlign: 'center',
    marginTop: 40,
  },
  myPackage: {
    flex: 1,
    textAlign: 'center',
    color: '#333333',
    marginBottom: 5,
  },
  myText: {
    textAlign: 'center',
  },
  myTabIndex: {
    fontSize: 20,
    textAlign: 'center',
    fontWeight: 'bold',
  },
});

export default MyExample;

More Icons

Check Out Here and use it's name into Tab name props.

Nav props

PropsTypeDefaultDescription
selectednumber-used to determine what tabIndex that currently selected
onTabChangefunction() => {}event onTabChange with param tabIndex
backgroundColorstring'white'Nav background color
borderTopColorstring'#DDDDDD'Nav border top color
heightnumber42Nav height
onlyIconbooleanfalsedisplay only icon or icon with label
pressOpacitynumber0.7opacity when Tab be pressed (min: 0, max: 1)
activeColorstring'black'active color on all Tabs
unActiveColorstring'gray'unactive color on all Tabs
iconSizenumber22icon size on all Tabs
fontSizenumber11font size on all Tabs
styleobject-your own custom style for Nav wrapper

Tab props

PropsTypeisRequired?Description
namestringRequiredused for icon name
labelstringOptionalTab label
fontStyleobjectOptionalyour own custom style for each Text on Tab
styleobjectOptionalyour own custom style for Tab wrapper

License

MIT