DEV Community

Let's Create A Custom Animated Tab Bar With React Native

Mateo Hrastnik on January 06, 2019

If you've ever felt like the default tab bar component you get from React Navigation looks too bland, or just wanted to create something a bit more...
Collapse
 
kashifudk profile image
kashifudk

Help Needed, Using your example i have build a custom tab bar but for some reason the text on the android is hiding behind the spotlight view. Works if on the ios but on android its not displaying the text of the selected tab.

Here is my tabbar.js





{routes.map((route, routeIndex) => {
const isRouteActive = routeIndex === activeRouteIndex;
const tintColor = isRouteActive ? activeTintColor : inactiveTintColor;
return (
key={routeIndex}
style={S.tabButton}
onPress={() => {
onTabPress({ route });
}}
onLongPress={() => {
onTabLongPress({ route });
}}
accessibilityLabel={getAccessibilityLabel({ route })}
>


{/* {renderIcon({ route, focused: isRouteActive, tintColor })} */}
{getLabelText({ route })}



);
})}


EN


AR


Collapse
 
hrastnik profile image
Mateo Hrastnik

Try setting a high zIndex on your text, or a negative zIndex on the spotlight component.

Cant really help you out there. If you provide a reproducible issue in a snack (snack.expo.io) I can take a look at the code.

Collapse
 
kashifudk profile image
kashifudk

Tried this... I didn't help will provide you an expo link.

Thread Thread
 
kashifudk profile image
kashifudk • Edited

Here is an Expo Link... The problem still exists in the expo.

Custom TabBar Expo Link

Please check and let me know

Thread Thread
 
kashifudk profile image
kashifudk

@hrastnik Please check the expo and let me know if there is something that i'm missing. Really appreciate any help...

Thread Thread
 
hrastnik profile image
Mateo Hrastnik

Hey @kashifudk sorry for the late reply. For some reason I didn't get any notifications when you replied.
I went over the code, and as I said it's an issue with zIndex.

You should change the style off the View wrapping the Spotlight and add zIndex: 0

Change this:

<View style={StyleSheet.absoluteFillObject}>
    <SpotLight style={S.spotLight} pose={`route${activeRouteIndex}`}/>
</View>

to this:

<View style={{...StyleSheet.absoluteFillObject, zIndex: 0}}>
    <SpotLight style={S.spotLight} pose={`route${activeRouteIndex}`}/>
</View>
Collapse
 
alisherakb profile image
Alisher Akbarov • Edited

Help wanted, please!

How can I make a draggable tab? So that on dragging to certain x,y it opens another screen?

Screenshot

Collapse
 
hrastnik profile image
Mateo Hrastnik

Not sure I understand what you mean. I think you can use the MaterialTabNavigator if you want to be able to use the swipe gesture to change tabs.

Collapse
 
alisherakb profile image
Alisher Akbarov • Edited

I have three tabs, one of them is draggable from its initial position.

InitialPosition of centerTab = x: 0, y: 250:

Screenshot 1

SnapPoint of CenterTab = x: 0, y: 72 , i.e can be dragged to this Y value and open new screen:

Screenshot 2

Thread Thread
 
hrastnik profile image
Mateo Hrastnik

No idea how to help you. Perhaps Reanimated / Animatable or something like that.

Collapse
 
petarprok profile image
Petar Prokopenko

Maybe you can use draggable and then detect if div passes certain y position to redirect to state?

Collapse
 
lalitgvp2 profile image
The third deadly sin⚡️

The component for route 'tabBarOptions' must be a React component. For example:

import MyScreen from './MyScreen';
...
tabBarOptions: MyScreen,
}

You can also use a navigator:

import MyNavigator from './MyNavigator';
...
tabBarOptions: MyNavigator,
}

This is the error that I got trying to run this code. Any ideas?

Collapse
 
anujcrsdb04 profile image
Anuj Sharma

You are not implementing the class that you are using or the name and location of the class must be wrong.

Collapse
 
hrastnik profile image
Mateo Hrastnik

You probably missed something. Check the code I provided for more info.

Collapse
 
fr3fou profile image
fr3fou

could you update this for react navigation 5?

Collapse
 
hrastnik profile image
Mateo Hrastnik

Will update soon, when I find the time.

Collapse
 
fr3fou profile image
fr3fou

github.com/torgeadelin/react-nativ...

i fixed a library that presumably followed this tutorial

Collapse
 
guptavishesh143 profile image
Vishesh Gupta

Hey Guys,
I need help as I am getting error of you are using react-navigation 5 but it seem the component using 4v,
can anyone help me to upgrade the same tabbar

Collapse
 
wiredmatrix profile image
Benjamin Ikwuagwu

Thanks Mateo for this tutorial. In my case I only want to make homeScreen tab bar background "transparent", and other tab bar screens background to "white". I need your on it please.

Collapse
 
jgecen profile image
Gécen

Best article I read until the memento about navigation, in addition it teaches about project organization. Congratulations!!!

Collapse
 
mateusrlima profile image
MateusRLima

Hello Mateo, could you pls tell how to change the label too ?

Collapse
 
hrastnik profile image
Mateo Hrastnik

You can set tabBarLabel on the tabs navigationOptions. Not sure if you'll need to add something to actually render the label.

Collapse
 
thatcharles profile image
Charles Chung

Thank you for this awesome and complete tutorial! Keep it up!!!

Collapse
 
muhammadrafeh profile image
Muhammad Rafeh Atique

play.google.com/store/apps/details...

Can you plz guide how to implement these search functionality in this app above?