Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How To Hide Tab Bar in Navigation Interface in React Native?

Tags:

react-native

In Native IOS, seems it's very easy to hide the tab bar in Navigation interface (http://www.appcoda.com/ios-programming-101-how-to-hide-tab-bar-navigation-controller/), but in React Native, seems it's not so easier to implement that. Even I override the hidesBottomBarWhenPushed method for RCTWrapperViewController:

- (BOOL) hidesBottomBarWhenPushed
{
  return YES;
}
like image 564
Yong Avatar asked May 16 '15 17:05

Yong


People also ask

How do I remove the tab bar border in react navigation?

Customize the TabBar To remove the border, add the tabBarOptions prop and inside it, add a style property called borderTopWidth with a value 0 . Do note that this property can also be used to increase the width of the top border.

How do I hide the tab navigator header in react native?

(React Nav ver6. x) add this code snipet "options={{headerShown: false}}" in "<Tab. Screen />". It will delete header of each tab you add into.

How do I customize tab navigation in react native?

Add icons to the tab bar To add icons to each tab, first import the Icon component from react-native-vector-icons library inside the navigation/TabNavigator/index. js file. For this example, let's use AntDesign based icons. // after other import statements import Icon from 'react-native-vector-icons/AntDesign';


1 Answers

This is a more in depth answer based on this issue in React-Native

In Xcode's lefthand sidebar, choose the 'Project Manger' (folder icon) to see the file structure.

The particular folder you are looking for is found at: [YourAppName] > Libraries > React.xcodeproj > React > Views

RCTNavItem.h

#import "RCTComponent.h"

@interface RCTNavItem : UIView

//add this line:
@property (nonatomic, assign) BOOL showTabBar;

RCTNavItemManager.m

@implementation RCTNavItemManager

RCT_EXPORT_MODULE()

- (UIView *)view
{
  return [RCTNavItem new];
}

// add this line:
RCT_EXPORT_VIEW_PROPERTY(showTabBar, BOOL)

RCTNavigator.m

- (void)navigationController:(UINavigationController *)navigationController
      willShowViewController:(__unused UIViewController *)viewController
                    animated:(__unused BOOL)animated
{

// Add these two lines:
        RCTWrapperViewController *thisController = (RCTWrapperViewController *)viewController;
        navigationController.tabBarController.tabBar.hidden = !thisController.navItem.showTabBar;

I did not need to add propTypes to NavigatorIOS.ios.js or TabBarIOS.ios.js

In order for this all to work, each tab seemingly needs to have its own NavigatorIOS component. When I had the tab simply present a screen the - (void)navigationController:(UINavigationController *)navigationController... method does not get called. This was not an issue for me, because hiding the navBar is easily done with navigationBarHidden: true.

In my case I had a TabNav > HomeNav > HomeScreen

Passing showTabBar prop in HomeNav:

render() {
    return (
      <NavigatorIOS
        style={styles.container}
        client={this.props.client}
        initialRoute={{
          title: 'Home',
          component: HomeScreen,
          navigationBarHidden: true,
          showTabBar: false,
          passProps: { ...},
        }}/>
      );
    }
  }

I hope this helps someone!

like image 168
Michael Campsall Avatar answered Sep 20 '22 14:09

Michael Campsall