Custom Tab Bar

Steps:-

1) Create two components/screens for two different tabs i.e. two main screens for tab navigation

Ex: –  First.js & Second.js

import React from 'react'

import { View, Text, StyleSheet } from 'react-native'

export const First = (props) => {

return(

 <View style={styles.container}>

   <Text>First</Text>

 </View>

 )

}

const styles = StyleSheet.create({

 container: {

  flex: 1justifyContent: 'center'alignItems: 'center',

 }

})
import React from 'react'

import { View, Text, StyleSheet } from 'react-native'




export const Second = (props) => {

return(

 <View style={styles.container}>

   <Text>Second</Text>

 </View>

 )

}

const styles = StyleSheet.create({

 container: {

  flex: 1, justifyContent: 'center', alignItems: 'center',

 }

})

2) Create Tabs component to warp above two screens in the tab bar 

Accept the props firstTab activeTab and secondTab and based on that write the conditions to change the tab and style for that imported from StyleTab File.

<View style={StyleTab.wrapper}>

     <TouchableOpacity

       style={

         props.activeTab === props.firstTab

           ? StyleTab.firstTabWrapperA

           : StyleTab.firstTabWrapperN

       }

       onPress={props.onPress}>

       <Text

         style={

           props.activeTab === props.firstTab

             ? StyleTab.activeTab

             : StyleTab.nonActiveTab

         }>

         {props.firstTab}

       </Text>

     </TouchableOpacity>

     <TouchableOpacity

       style={

         props.activeTab === props.secondTab

           ? StyleTab.secondTabWrapperA

           : StyleTab.secondTabWrapperN

       }

       onPress={props.onPress}>

       <Text

  style={

           props.activeTab === props.secondTab

             ? StyleTab.activeTab

             : StyleTab.nonActiveTab

         }>

         {props.secondTab}

       </Text>

     </TouchableOpacity>

   </View>

3) Styles for Tab change is imported from the StyletTab file

Here all styles for the wrapper and both tabs are defined for tab navigation 

4) Create one function to change the tabs on the main screen (Screen where the Tab bar needs to be shown)

const changeTab = () => {

   if (activeTab === 'First') {

     setactiveTab('Second');

   } else {

     setactiveTab('First');

   }

 };

5) Create another function to render the First and Second screens

Render the first and second screen component in a renderTab function according to activeTab conditions.

const renderTabs=()=> {

   if (activeTab === 'First') {

     return <First />;

   } else {

   return <Second />;

   }

 }

6) Import Tabs file render below function in necessary screen

 Pass the required props to the Tabs component i.e. activeTab firstTab and secondTab then call the changeTab function on on press. 

<View style={container}>

     <Tabs

       activeTab={activeTab}

       firstTab="First"

       secondTab="Second"

       onPress={changeTab}

     />

     {renderDashboard()}

   </View>

Content Team

This blog is from Mindbowser‘s content team – a group of individuals coming together to create pieces that you may like. If you have feedback, please drop us a message on contact@mindbowser.com

Get in touch for a detailed discussion.

Hear From Our 100+ Customers
coma

Mindbowser helped us build an awesome iOS app to bring balance to people’s lives.

author
ADDIE WOOTTEN
CEO, SMILINGMIND
coma

We had very close go live timeline and MindBowser team got us live a month before.

author
Shaz Khan
CEO, BuyNow WorldWide
coma

They were a very responsive team! Extremely easy to communicate and work with!

author
Kristen M.
Founder & CEO, TotTech
coma

We’ve had very little-to-no hiccups at all—it’s been a really pleasurable experience.

author
Chacko Thomas
Co-Founder, TEAM8s
coma

Mindbowser is one of the reasons that our app is successful. These guys have been a great team.

author
Dave Dubier
Founder & CEO, MangoMirror
coma

Mindbowser was very helpful with explaining the development process and started quickly on the project.

author
Hieu Le
Executive Director of Product Development, Innovation Lab
coma

The greatest benefit we got from Mindbowser is the expertise. Their team has developed apps in all different industries with all types of social proofs.

author
Alex Gobel
Co-Founder, Vesica
coma

Mindbowser is professional, efficient and thorough. 

author
MacKenzie R
Consultant at XPRIZE
coma

Very committed, they create beautiful apps and are very benevolent. They have brilliant Ideas.

author
Laurie Mastrogiani
Founder, S.T.A.R.S of Wellness
coma

MindBowser was great; they listened to us a lot and helped us hone in on the actual idea of the app.” “They had put together fantastic wireframes for us.

author
Bennet Gillogly
Co-Founder, Flat Earth
coma

They're very tech-savvy, yet humble.

author
Uma Nidmarty
CEO, GS Advisorate, Inc.
coma

Ayush was responsive and paired me with the best team member possible, to complete my complex vision and project. Could not be happier.

author
Katie Taylor
Founder, Child Life On Call
coma

As a founder of a budding start-up, it has been a great experience working with Mindbower Inc under Ayush's leadership for our online digital platform design and development activity.

author
Radhika Kotwal
Founder of Courtyardly
coma

The team from Mindbowser stayed on task, asked the right questions, and completed the required tasks in a timely fashion! Strong work team!

author
Michael Wright
Chief Executive Officer, SDOH2Health LLC
coma

They are focused, patient and; they are innovative. Please give them a shot if you are looking for someone to partner with, you can go along with Mindbowser.

author
David Cain
CEO, thirty2give
coma

We are a small non-profit on a budget and they were able to deliver their work at our prescribed budgets. Their team always met their objectives and I'm very happy with the end result. Thank you, Mindbowser team!!

author
Bart Mendel
Founder, Mindworks
coma

Mindbowser was easy to work with and hit the ground running, immediately feeling like part of our team.

author
George Hodulik
CEO, Stealth Startup, Ex-Google