React Native Tab View

 Run the following command with your project directory

    npm i react-native-tab-view
    npm i react-native-gesture-handler react-native-reanimated

code for tab view in react native

    open App.js in any code editor and replace the code with the following code

App.js

import React,{ Component } from 'react';
import {
    StyleSheet,
    View,
    Dimensions
} from 'react-native';
import { TabView, SceneMap } from 'react-native-tab-view';

export default class App extends Component {
    constructor(props) {
        super(props);
        this.state = {
            index: 0,
            routes: [
                { key: 'first' , title: 'First' },
                { key: 'second' , title: 'Second'}
            ]
        }
    }

    renderScene = ({ route }) => {
        switch (route.key) {
            case 'first':
                return <View style={[styles.scene, { backgroundColor: '#ff4081' }]} />;
            case 'second':
                return <View style={[styles.scene, { backgroundColor: '#673ab7' }]} />;
        }
    }
            
    render() {
        return(
            <TabView
                navigationState={{ index: this.state.index, routes: this.state.routes }}
                renderScene={this.renderScene}
                onIndexChange={index=>this.setState({index})}
                initialLayout={{width: Dimensions.get('window').width}}
            />
        );
    }
}

const styles = StyleSheet.create({
    scene: {
        flex: 1
    }
});

To Run the App

    react-native run-andriod




        








Comments

Post a Comment

Popular posts from this blog

React Native Floating Label Textinput

React Native Modal box