Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
January 19, 2021 06:11 am GMT

How to remove tab bar border in React Navigation

Navigation plays an important role in mobile applications and the React Navigation library does an awesome job in providing a completely customizable interface for utilizing different navigation patterns to React Native apps.

Having the liberty to customize tab bars with React Navigation, one of my favorite customizable options (depending on the UI design of an app) is to remove the border from the Tab bar.

Here is an example of the border that is the default when the React Navigation Bottom Tabs library is utilized to create a tab bar.

ss1

For the demonstration purpose, I am using an Expo project created using the expo-cli command-line tool. To create a similar new Expo project, you can execute the command and choose the tabs option.

expo init yourProjectName# when prompted, choose the tabs option# in managed workflow
Enter fullscreen mode Exit fullscreen mode

This expo project comes with a default bottom tab navigator whose configuration can be found in the file navigation/BottomTabNavigator.tsx.

Customize the TabBar

The Bottom Tab Bar React Navigation library gives an object called tabBarOptions to customize a tab bar. This object contains props that can be used to apply custom styles and one of the generic property it has is called style. This property is commonly used to change the styles of the tab bar, for example, by applying the backgroundColor styles' property.

To remove the border, add the tabBarOptions prop and inside it, add a style property called borderTopWidth with a value 0.

<BottomTab.Navigator  initialRouteName='TabOne'  tabBarOptions={{    // ...    style: { borderTopWidth: 0 }  }}>
Enter fullscreen mode Exit fullscreen mode

Here is the output:

ss2

Do note that this property can also be used to increase the width of the top border.

Removing shadow on Android Device

After applying this style property, the width of the top border is removed from an Android device. However, there is a shadow at the top border of the tab bar that remains.

ss3

To remove this shadow, set the elevation to 0:

style: {  borderTopWidth: 0,  elevation: 0}
Enter fullscreen mode Exit fullscreen mode

ss4

More React Native posts | Twitter | Weekly Newsletter


Original Link: https://dev.to/amanhimself/how-to-remove-tab-bar-border-in-react-navigation-1mm5

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To