Skip to content

Instantly share code, notes, and snippets.

@topherPedersen
Created August 4, 2022 01:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save topherPedersen/f7d98b01e847c06469248344bfc6d01d to your computer and use it in GitHub Desktop.
Save topherPedersen/f7d98b01e847c06469248344bfc6d01d to your computer and use it in GitHub Desktop.
Register React Native Navigation External Component in Swift
//#import "AppDelegate.h"
//#import <React/RCTBridge.h>
//#import <React/RCTBundleURLProvider.h>
//#import "RNNCustomViewController.h"
//#import <ReactNativeNavigation/ReactNativeNavigation.h>
class AppDelegate : RCTBridgeDelegate {
func application(application:UIApplication!, didFinishLaunchingWithOptions launchOptions:NSDictionary!) -> Bool {
self.window = UIWindow(frame:UIScreen.mainScreen().bounds)
if #available(iOS 13.0, *) {
self.window.backgroundColor = UIColor.systemBackgroundColor()
} else {
self.window.backgroundColor = UIColor.whiteColor()
}
self.window.makeKeyWindow()
let bridge:RCTBridge! = RCTBridge(delegate:self, launchOptions:launchOptions)
ReactNativeNavigation.bootstrapWithBridge(bridge)
ReactNativeNavigation.registerExternalComponent("RNNCustomComponent",
callback:{ (props:NSDictionary!,bridge:RCTBridge!) in
return RNNCustomViewController(props:props)
})
return true
}
// MARK: - RCTBridgeDelegate
func sourceURLForBridge(bridge:RCTBridge!) -> NSURL! {
#if DEBUG
return RCTBundleURLProvider.sharedSettings().jsBundleURLForBundleRoot("index",
fallbackResource:nil)
#else
return NSBundle.mainBundle().URLForResource("main", withExtension:"jsbundle")
#endif
}
func extraModulesForBridge(bridge:RCTBridge!) -> [AnyObject]! {
return ReactNativeNavigation.extraModulesForBridge(bridge)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment