Skip to content

Instantly share code, notes, and snippets.

@duytq94
Last active March 25, 2020 10:09
Show Gist options
  • Save duytq94/14e08c30b1a94d9ebbfc67487c1f4681 to your computer and use it in GitHub Desktop.
Save duytq94/14e08c30b1a94d9ebbfc67487c1f4681 to your computer and use it in GitHub Desktop.
class RNViewManager: NSObject {
var bridge: RCTBridge?
static let sharedInstance = RNViewManager()
func createBridgeIfNeeded() -> RCTBridge {
if bridge == nil {
bridge = RCTBridge.init(delegate: self, launchOptions: nil)
}
return bridge!
}
func viewForModule(_ moduleName: String, initialProperties: [String : Any]?) -> RCTRootView {
let viewBridge = createBridgeIfNeeded()
let rootView: RCTRootView = RCTRootView(
bridge: viewBridge,
moduleName: moduleName,
initialProperties: initialProperties)
return rootView
}
}
extension RNViewManager: RCTBridgeDelegate {
func sourceURL(for bridge: RCTBridge!) -> URL! {
#if DEBUG
return URL(string: "http://localhost:8081/index.bundle?platform=ios")
#else
return Bundle.main.url(forResource: "main", withExtension: "jsbundle")
#endif
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment