Created
August 12, 2017 10:49
-
-
Save hpstuff/e190ac160355a15a02eea6fd4c60c0b7 to your computer and use it in GitHub Desktop.
ReactNative - Airbnb Navigation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
} | |
/*...*/ | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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