Coder Social home page Coder Social logo

hhy5277 / react-native-tabs Goto Github PK

View Code? Open in Web Editor NEW

This project forked from aksonov/react-native-tabs

0.0 1.0 0.0 260 KB

React Native platform-independent tabs. Could be used for bottom tab bars as well as sectioned views (with tab buttons)

License: Apache License 2.0

Java 17.21% JavaScript 44.51% Objective-C 38.28%

react-native-tabs's Introduction

react-native-tabs

React Native platform-independent tabs. Could be used for bottom tab bars as well as sectioned views (with tab buttons)

Why I need to use it?

  • Decouple content views from tab bar
  • Platform-indepedent
  • Possibility to use Flux actions with react-native-router-flux to switch between content views
  • Suitable for both bottom tab bar as well as upper sectioned buttons (you just need to define style properly)
  • Custom views for each tab icon

How it works?

Component just iterates over all its children and makes them touchable ('name' is only required attribute of each child). selectedStyle property represents style should be applied for selected tabs. This property could be set for all tabs or for individual tab. selectedIconStyle represents style applied for selected tab. The same, onSelect handler could be set globally for all tabs or/and for individual tab. You can lock tab buttons (require user to use long press to actuate the button) by passing prop {locked: true}.

Example

Example makes selected icon color red and change the state of example view. To switch to other views you may use react-native-router-flux component or own navigation controller demo-2

import React, { Component } from 'react';
import {
  AppRegistry,
  StyleSheet,
  Text,
  View,
} from 'react-native';

import Tabs from 'react-native-tabs';

class Example extends Component {
  constructor(props){
    super(props);
    this.state = {page:'second'};
  }
  render() {
    return (
      <View style={styles.container}>
        <Tabs selected={this.state.page} style={{backgroundColor:'white'}}
              selectedStyle={{color:'red'}} onSelect={el=>this.setState({page:el.props.name})}>
            <Text name="first">First</Text>
            <Text name="second" selectedIconStyle={{borderTopWidth:2,borderTopColor:'red'}}>Second</Text>
            <Text name="third">Third</Text>
            <Text name="fourth" selectedStyle={{color:'green'}}>Fourth</Text>
            <Text name="fifth">Fifth</Text>
        </Tabs>
          <Text style={styles.welcome}>
              Welcome to React Native
          </Text>
          <Text style={styles.instructions}>
              Selected page: {this.state.page}
          </Text>
      </View>
    );
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: '#F5FCFF',
  },
  welcome: {
    fontSize: 20,
    textAlign: 'center',
    margin: 10,
  },
  instructions: {
    textAlign: 'center',
    color: '#333333',
    marginBottom: 5,
  },
});

AppRegistry.registerComponent('Example', () => Example);

react-native-tabs's People

Contributors

aksonov avatar andrew avatar arneson avatar chetstone avatar froelund avatar gilesb2 avatar jondot avatar karlosq avatar nadeesha avatar ruskid avatar shakarang avatar sondremare avatar ultragtx avatar webwelten avatar zebulgar avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.