|
| 1 | +import UIKit |
1 | 2 | import React
|
2 | 3 | import React_RCTAppDelegate
|
3 | 4 | import ReactAppDependencyProvider
|
4 |
| -import UIKit |
5 | 5 |
|
6 | 6 | @main
|
7 |
| -class AppDelegate: RCTAppDelegate { |
8 |
| - override func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? = nil) -> Bool { |
9 |
| - moduleName = "ReactNative" |
10 |
| - dependencyProvider = RCTAppDependencyProvider() |
11 |
| - |
12 |
| - // You can add your custom initial props in the dictionary below. |
13 |
| - // They will be passed down to the ViewController used by React Native. |
14 |
| - initialProps = [:] |
15 |
| - |
16 |
| - return super.application(application, didFinishLaunchingWithOptions: launchOptions) |
17 |
| - } |
18 |
| - |
19 |
| - override func sourceURL(for _: RCTBridge) -> URL? { |
20 |
| - bundleURL() |
21 |
| - } |
22 |
| - |
23 |
| - override func bundleURL() -> URL? { |
24 |
| - #if DEBUG |
25 |
| - RCTBundleURLProvider.sharedSettings().jsBundleURL(forBundleRoot: "index") |
26 |
| - #else |
27 |
| - Bundle.main.url(forResource: "main", withExtension: "jsbundle") |
28 |
| - #endif |
29 |
| - } |
| 7 | +class AppDelegate: UIResponder, UIApplicationDelegate { |
| 8 | + var window: UIWindow? |
| 9 | + |
| 10 | + var reactNativeDelegate: ReactNativeDelegate? |
| 11 | + var reactNativeFactory: RCTReactNativeFactory? |
| 12 | + |
| 13 | + func application( |
| 14 | + _ application: UIApplication, |
| 15 | + didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? = nil |
| 16 | + ) -> Bool { |
| 17 | + let delegate = ReactNativeDelegate() |
| 18 | + let factory = RCTReactNativeFactory(delegate: delegate) |
| 19 | + delegate.dependencyProvider = RCTAppDependencyProvider() |
| 20 | + |
| 21 | + reactNativeDelegate = delegate |
| 22 | + reactNativeFactory = factory |
| 23 | + |
| 24 | + window = UIWindow(frame: UIScreen.main.bounds) |
| 25 | + |
| 26 | + factory.startReactNative( |
| 27 | + withModuleName: "ReactNative", |
| 28 | + in: window, |
| 29 | + launchOptions: launchOptions |
| 30 | + ) |
| 31 | + |
| 32 | + return true |
| 33 | + } |
| 34 | +} |
| 35 | + |
| 36 | +class ReactNativeDelegate: RCTDefaultReactNativeFactoryDelegate { |
| 37 | + override func sourceURL(for bridge: RCTBridge) -> URL? { |
| 38 | + self.bundleURL() |
| 39 | + } |
| 40 | + |
| 41 | + override func bundleURL() -> URL? { |
| 42 | +#if DEBUG |
| 43 | + RCTBundleURLProvider.sharedSettings().jsBundleURL(forBundleRoot: "index") |
| 44 | +#else |
| 45 | + Bundle.main.url(forResource: "main", withExtension: "jsbundle") |
| 46 | +#endif |
| 47 | + } |
30 | 48 | }
|
0 commit comments