native-navigation icon indicating copy to clipboard operation
native-navigation copied to clipboard

how to push route without tab in tabs

Open taojoe opened this issue 7 years ago • 4 comments

I run the example code, all works great. I want the feature : the first screen is with tab, then push the 2nd screen, without tab showing, is this possible ? if possible how to do it ?

taojoe avatar Jul 28 '17 11:07 taojoe

I have no idea about Android. From iOS, it is supported from native code, using hidesBottomBarWhenPushed to the pushed view controller. To make it work when calling from JS however, you need to modify this method to be able to do what you want.

esam091 avatar Jul 29 '17 13:07 esam091

@esam091 thanks. that can solve it. if this library can make it like navigation like instagram click the comment icon, it would be better.

i guess it maybe hard to do it, because native-navigation use one global navigation?

taojoe avatar Jul 31 '17 00:07 taojoe

I've been using the library the last days, and i am really enjoying it, but it seems that the tabs API isn't that ready, and pushing or presenting screens doesn't do anything with tabs, and the mode ('screen' | 'tabs') property is not there yet.

A better solution to work around this, and not change the library itself, would be to write a small native module to extend the native navigation to your needs.

I have a similar working case, a Login screen that doesn't has tabs and pushes to a Dashboard screen that has tabs, and the Dashboard screen has a List that each item pushes a 2nd screen without showing the tabs.

DashboardController.swift


import NativeNavigation

@objc(DashboardController)
class DashboardController : NSObject {
  fileprivate let coordinator: ReactNavigationCoordinator
  
  override init() {
    coordinator = ReactNavigationCoordinator.sharedInstance
  }
  
  @objc func presentScreenWithTabs() -> Void {
    DispatchQueue.main.async {
      let nav = self.coordinator.topNavigationController()
      let screen = ReactTabBarController(moduleName: "ScreenName")
      nav?.presentReactViewController(screen, animated: true, completion: nil)
    }
  }
  
  @objc func pushScreenWithoutTabs(_ props: [String: AnyObject]) -> Void {
    DispatchQueue.main.async {
      let nav = self.coordinator.topNavigationController()
      let screen = ReactViewController(moduleName: "ScreenName", props: props)
      screen.hidesBottomBarWhenPushed = true
      nav?.pushViewController(screen, animated: true)
    }
  }
}

Link the functions with the bridge.

DashboardBridge.m


#import "React/RCTBridgeModule.h"

@interface RCT_EXTERN_MODULE(DashboardController, NSObject)

RCT_EXTERN_METHOD(presentScreenWithTabs)
RCT_EXTERN_METHOD(pushScreenWithoutTabs:(NSDictionary *) props)

@end

Then invoke it as follows


import { NativeModules } from 'react-native'

handlePress() {
  NativeModules.DashboardController.pushScreenWithoutTabs()
}

Note that this isn't actually the best solution, but just a way to extend the native-navigation to our needs, until we don't have a full tabs API, which may take some time.

I will try to update my answer for android when i get there.

cesardeazevedo avatar Jul 31 '17 14:07 cesardeazevedo

fwiw, I've implemented this over on our fork: https://github.com/taxfix/native-navigation/pull/9 (amongst some other things, ymmv)

notjosh avatar Oct 25 '17 15:10 notjosh