Last active
March 25, 2020 10:09
-
-
Save duytq94/14e08c30b1a94d9ebbfc67487c1f4681 to your computer and use it in GitHub Desktop.
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
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