Skip to content

Commit bc47041

Browse files
authored
feat: migrate off RCTAppDelegate (#106)
1 parent 364dd5a commit bc47041

File tree

1 file changed

+26
-8
lines changed

1 file changed

+26
-8
lines changed

template/ios/HelloWorld/AppDelegate.swift

+26-8
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,36 @@ import React_RCTAppDelegate
44
import ReactAppDependencyProvider
55

66
@main
7-
class AppDelegate: RCTAppDelegate {
8-
override func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
9-
self.moduleName = "HelloWorld"
10-
self.dependencyProvider = RCTAppDependencyProvider()
7+
class AppDelegate: UIResponder, UIApplicationDelegate {
8+
var window: UIWindow?
119

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-
self.initialProps = [:]
10+
var reactNativeDelegate: ReactNativeDelegate?
11+
var reactNativeFactory: RCTReactNativeFactory?
1512

16-
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
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: "HelloWorld",
28+
in: window,
29+
launchOptions: launchOptions
30+
)
31+
32+
return true
1733
}
34+
}
1835

36+
class ReactNativeDelegate: RCTDefaultReactNativeFactoryDelegate {
1937
override func sourceURL(for bridge: RCTBridge) -> URL? {
2038
self.bundleURL()
2139
}

0 commit comments

Comments
 (0)