Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.