Created
June 27, 2017 15:02
-
-
Save mizchi/0d8672a756d6c5e50956c6fd21f68956 to your computer and use it in GitHub Desktop.
This file contains 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 Foundation | |
import UIKit | |
class MySampleView :UIView{ | |
override init(frame: CGRect) { | |
super.init(frame: frame) | |
self.backgroundColor = UIColor.blue | |
} | |
required init?(coder aDecoder: NSCoder) { | |
fatalError("init(coder:) has not been implemented") | |
} | |
} | |
func createRNView( | |
didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]? | |
) -> UIView { | |
let jsCodeLocation = RCTBundleURLProvider | |
.sharedSettings() | |
.jsBundleURL( | |
forBundleRoot: "index.ios", | |
fallbackResource:nil) | |
let rootView = RCTRootView( | |
bundleURL: jsCodeLocation, | |
moduleName: "mynativeejectapp", | |
initialProperties: nil, | |
launchOptions: launchOptions | |
) | |
return rootView! | |
} | |
func createUIView(frame: CGRect) -> UIView { | |
return MySampleView(frame: frame) | |
} | |
@UIApplicationMain | |
class AppDelegate: UIResponder, UIApplicationDelegate { | |
var window: UIWindow? | |
var bridge: RCTBridge! | |
func application( | |
_ application: UIApplication, | |
didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]? | |
) -> Bool { | |
let rootViewController = UIViewController() | |
// Create ReactNativeView as root | |
// let rootView = createRNView(didFinishLaunchingWithOptions: launchOptions) | |
// Create ReactNativeView under root UIView | |
let rootView = createUIView(frame: UIScreen.main.bounds) | |
let rnView = createRNView(didFinishLaunchingWithOptions: launchOptions) | |
rnView.frame = UIScreen.main.bounds | |
rootView.addSubview(rnView) | |
rootViewController.view = rootView | |
let window = UIWindow(frame: UIScreen.main.bounds) | |
window.rootViewController = rootViewController | |
window.makeKeyAndVisible() | |
self.window = window | |
return true | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment