在Native IOS中,似乎很容易隐藏导航界面中的标签栏( http://www.appcoda.com/ios-programming-101-how-to-hide-tab-bar-navigation-controller/ ),但是在React Native中,似乎实现它并不那么容易。 即使我重写了RCTWrapperViewControllerhidesBottomBarWhenPushed方法:

- (BOOL) hidesBottomBarWhenPushed
{
  return YES;
}

===============>>#1 票数:6

基于React-Native中的这个问题,这是一个更深入的答案

在Xcode的左侧边栏中,选择“Project Manger”(文件夹图标)以查看文件结构。

您正在寻找的特定文件夹位于:[YourAppName]>库> 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;

我不需要将propTypes添加到NavigatorIOS.ios.js或TabBarIOS.ios.js

为了使这一切都能正常工作,每个标签看起来都需要有自己的NavigatorIOS组件。 当我让选项卡只显示一个屏幕 - (void)navigationController:(UINavigationController *)navigationController ...方法不会被调用。 这对我来说不是问题,因为使用navigationBarHidden:true可以轻松隐藏navBar。

在我的情况下,我有一个TabNav> HomeNav> HomeScreen

在HomeNav中传递showTabBar道具:

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

我希望这可以帮助别人!

===============>>#2 票数:0

React native中有两个主要的Navigator组件: NavigatorNavigatorIOS


隐藏NavigatorIOS组件的导航栏

navigationBarHidden属性设置为true以隐藏导航栏:

<NavigatorIOS navigationBarHidden={true}>
    <View>
    ...
    </View>
</NavigatorIOS>

请参阅React本机文档

隐藏Navigator组件的导航栏

由于navbar是为Navigator组件显式提供的 ,因此默认情况下不会呈现它。

===============>>#3 票数:0

您可以尝试使用下面的包,它有一个很好的解决方案

反应天然-的TabBar导航仪

在此输入图像描述

===============>>#4 票数:0

我为此问题更改了ReactNative 0.11源代码。如果您需要它:在RCTNavigationController中,添加代码:

- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated{
  if (self.viewControllers.count >= 1) {
    [self hideTabBarIfExist:YES];
  }

  [super pushViewController:viewController animated:animated];
}
- (UIViewController *)popViewControllerAnimated:(BOOL)animated {

  if (self.viewControllers.count <= 2) {
    [self hideTabBarIfExist:NO];
  }
  return [super popViewControllerAnimated:animated];
}
- (NSArray *)popToViewController:(UIViewController *)viewController animated:(BOOL)animated {
  if ([self.viewControllers indexOfObject:viewController] == 0) {
    [self hideTabBarIfExist:NO];
  }

  return [super popToViewController:viewController animated:animated];
}
- (NSArray *)popToRootViewControllerAnimated:(BOOL)animated{
  [self hideTabBarIfExist:NO];
  return [super popToRootViewControllerAnimated:animated];
}



- (void)hideTabBarIfExist:(BOOL)flag {
  UIWindow *keyWindow = [[[UIApplication sharedApplication]delegate]window];
  UIView *tabView = [self getTabBarView:keyWindow];
  if (tabView) {
    // you can use other animations
    [UIView animateWithDuration:0.3 animations:^{
      tabView.hidden = flag;
    }];

  }
}
- (UIView *)getTabBarView:(UIView *)pView {
  if (pView == nil) {
    return nil;
  }
  for (UIView *sView in [pView subviews]) {
    if ([sView isKindOfClass:[UITabBar class]]) {
      return sView;
    }
    UIView *t = [self getTabBarView:sView];
    if (t) {
      return t;
    }
  }
  return nil;
}

===============>>#5 票数:0

如果您使用的是react-navigation包,则非常简单:

class ScreenWhereTabbarIsHidden extends React.Component {
  static navigationOptions = {
    tabBarVisible: false,
  }
}

===============>>#6 票数:-1

RCTWrapperViewController.m

- (BOOL)hidesBottomBarWhenPushed
{
  return self.navigationController.viewControllers.count != 1;
}

RCTTabBar.m

- (void)reactBridgeDidFinishTransaction
{
  ...

  if (_tabsChanged) {

    NSMutableArray<UIViewController *> *viewControllers = [NSMutableArray array];
    for (RCTTabBarItem *tab in [self reactSubviews]) {
      UIViewController *controller = tab.reactViewController;
      if (!controller) {
        NSArray *tabSubViews = [[[tab reactSubviews] firstObject] reactSubviews];
        RCTNavigator *navigator = [tabSubViews firstObject];
        if (!tabSubViews.count) {
          tab.onPress(nil);
          return;
        }
        else if ([navigator isKindOfClass:[RCTNavigator class]]) {
          controller = navigator.reactViewController;
        }
        else {
          controller = [[RCTWrapperViewController alloc] initWithContentView:tab];
        }
      }
      [viewControllers addObject:controller];
    }

    _tabController.viewControllers = viewControllers;
    _tabsChanged = NO;
    RCTTabBarItem *tab = (RCTTabBarItem *)[[self reactSubviews] firstObject];
    tab.onPress(nil);
  }

  ...

}

  ask by Yong translate from so

未解决问题?本站智能推荐: