Skip to content

Instantly share code, notes, and snippets.

@hpstuff
Created August 12, 2017 10:49
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hpstuff/e190ac160355a15a02eea6fd4c60c0b7 to your computer and use it in GitHub Desktop.
Save hpstuff/e190ac160355a15a02eea6fd4c60c0b7 to your computer and use it in GitHub Desktop.
ReactNative - Airbnb Navigation
import UIKit
import NativeNavigation
import React
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate, RCTBridgeDelegate, ReactNavigationCoordinatorDelegate {
/*...*/
func flowCoordinatorForId(_ name: String) -> ReactFlowCoordinator? {
if name == "MyNative" { // now we can use `Navigator.push('MyNative')` to introduce our native controller
return MyViewController();
}
return nil
}
/*...*/
}
import UIKit
import NativeNavigation
class MyViewController: UIViewController {
var reactFlowId: String?
@IBAction func openDetail(_ sender: UIButton) {
//push other controllers as usual
navigationController?.pushViewController(DetailViewController(), animated: true)
}
}
extension MyViewController: ReactFlowCoordinator {
@objc public func finish(_ resultCode: ReactFlowResultCode, payload: [String:AnyObject]?) { /* Not sure that this is needed */
let nc = ReactNavigationCoordinator.sharedInstance.topNavigationController()
nc?.popViewController(animated: true)
}
/* add start method to push our controller in ReactNavigationConordinator NavigationController */
public func start(_ props: [String:AnyObject]?) {
let nc = ReactNavigationCoordinator.sharedInstance.topNavigationController()
nc?.pushViewController(self, animated: true)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment