Skip to content

Commit 3e3e4d3

Browse files
committed
feat: adopt SceneDelegate
1 parent 56b77ae commit 3e3e4d3

4 files changed

Lines changed: 80 additions & 38 deletions

File tree

template/ios/HelloWorld.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
0C80B921A6F3F58F76C31292 /* libPods-HelloWorld.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 5DCACB8F33CDC322A6C60F78 /* libPods-HelloWorld.a */; };
1111
13B07FBF1A68108700A75B9A /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 13B07FB51A68108700A75B9A /* Images.xcassets */; };
1212
761780ED2CA45674006654EE /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 761780EC2CA45674006654EE /* AppDelegate.swift */; };
13+
761780EF2CA45674006654EF /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 761780EE2CA45674006654EF /* SceneDelegate.swift */; };
1314
81AB9BB82411601600AC10FF /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 81AB9BB72411601600AC10FF /* LaunchScreen.storyboard */; };
1415
/* End PBXBuildFile section */
1516

@@ -22,6 +23,7 @@
2223
5709B34CF0A7D63546082F79 /* Pods-HelloWorld.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-HelloWorld.release.xcconfig"; path = "Target Support Files/Pods-HelloWorld/Pods-HelloWorld.release.xcconfig"; sourceTree = "<group>"; };
2324
5DCACB8F33CDC322A6C60F78 /* libPods-HelloWorld.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-HelloWorld.a"; sourceTree = BUILT_PRODUCTS_DIR; };
2425
761780EC2CA45674006654EE /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = AppDelegate.swift; path = HelloWorld/AppDelegate.swift; sourceTree = "<group>"; };
26+
761780EE2CA45674006654EF /* SceneDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = SceneDelegate.swift; path = HelloWorld/SceneDelegate.swift; sourceTree = "<group>"; };
2527
81AB9BB72411601600AC10FF /* LaunchScreen.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; name = LaunchScreen.storyboard; path = HelloWorld/LaunchScreen.storyboard; sourceTree = "<group>"; };
2628
ED297162215061F000B7C4FE /* JavaScriptCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = JavaScriptCore.framework; path = System/Library/Frameworks/JavaScriptCore.framework; sourceTree = SDKROOT; };
2729
/* End PBXFileReference section */
@@ -43,6 +45,7 @@
4345
children = (
4446
13B07FB51A68108700A75B9A /* Images.xcassets */,
4547
761780EC2CA45674006654EE /* AppDelegate.swift */,
48+
761780EE2CA45674006654EF /* SceneDelegate.swift */,
4649
13B07FB61A68108700A75B9A /* Info.plist */,
4750
81AB9BB72411601600AC10FF /* LaunchScreen.storyboard */,
4851
13B07FB81A68108700A75B9A /* PrivacyInfo.xcprivacy */,
@@ -245,6 +248,7 @@
245248
buildActionMask = 2147483647;
246249
files = (
247250
761780ED2CA45674006654EE /* AppDelegate.swift in Sources */,
251+
761780EF2CA45674006654EF /* SceneDelegate.swift in Sources */,
248252
);
249253
runOnlyForDeploymentPostprocessing = 0;
250254
};
Lines changed: 1 addition & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,11 @@
11
import UIKit
2-
import React
3-
import React_RCTAppDelegate
4-
import ReactAppDependencyProvider
52

63
@main
74
class AppDelegate: UIResponder, UIApplicationDelegate {
8-
var window: UIWindow?
9-
10-
var reactNativeDelegate: ReactNativeDelegate?
11-
var reactNativeFactory: RCTReactNativeFactory?
12-
135
func application(
146
_ application: UIApplication,
157
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? = nil
168
) -> 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
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
9+
true
4710
}
4811
}

template/ios/HelloWorld/Info.plist

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,27 @@
3636
</dict>
3737
<key>NSLocationWhenInUseUsageDescription</key>
3838
<string></string>
39+
<key>RCTNewArchEnabled</key>
40+
<true/>
41+
<key>UIApplicationSceneManifest</key>
42+
<dict>
43+
<key>UIApplicationSupportsMultipleScenes</key>
44+
<false/>
45+
<key>UISceneConfigurations</key>
46+
<dict>
47+
<key>UIWindowSceneSessionRoleApplication</key>
48+
<array>
49+
<dict>
50+
<key>UISceneConfigurationName</key>
51+
<string>Default Configuration</string>
52+
<key>UISceneDelegateClassName</key>
53+
<string>$(PRODUCT_MODULE_NAME).SceneDelegate</string>
54+
</dict>
55+
</array>
56+
</dict>
57+
</dict>
58+
<key>RCTUseAssetCatalog</key>
59+
<true/>
3960
<key>UILaunchStoryboardName</key>
4061
<string>LaunchScreen</string>
4162
<key>UIRequiredDeviceCapabilities</key>
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import React
2+
import React_RCTAppDelegate
3+
import ReactAppDependencyProvider
4+
import UIKit
5+
6+
class SceneDelegate: RCTDefaultReactNativeFactoryDelegate, UIWindowSceneDelegate {
7+
var window: UIWindow?
8+
var reactNativeFactory: RCTReactNativeFactory?
9+
10+
func scene(
11+
_ scene: UIScene,
12+
willConnectTo session: UISceneSession,
13+
options connectionOptions: UIScene.ConnectionOptions
14+
) {
15+
guard let windowScene = scene as? UIWindowScene else {
16+
return
17+
}
18+
19+
dependencyProvider = RCTAppDependencyProvider()
20+
reactNativeFactory = RCTReactNativeFactory(delegate: self)
21+
window = UIWindow(windowScene: windowScene)
22+
23+
reactNativeFactory?.startReactNative(
24+
withModuleName: "HelloWorld",
25+
in: window,
26+
connectionOptions: connectionOptions
27+
)
28+
29+
#if DEBUG
30+
let devMenuConfiguration = RCTDevMenuConfiguration(
31+
devMenuEnabled: true,
32+
shakeGestureEnabled: true,
33+
keyboardShortcutsEnabled: true
34+
)
35+
reactNativeFactory?.devMenuConfiguration = devMenuConfiguration
36+
#endif
37+
}
38+
39+
func scene(_ scene: UIScene, openURLContexts URLContexts: Set<UIOpenURLContext>) {
40+
RCTLinkingManager.scene(scene, openURLContexts: URLContexts)
41+
}
42+
43+
func scene(_ scene: UIScene, continue userActivity: NSUserActivity) {
44+
RCTLinkingManager.scene(scene, continue: userActivity)
45+
}
46+
47+
override func bundleURL() -> URL? {
48+
#if DEBUG
49+
RCTBundleURLProvider.sharedSettings().jsBundleURL(forBundleRoot: "index")
50+
#else
51+
Bundle.main.url(forResource: "main", withExtension: "jsbundle")
52+
#endif
53+
}
54+
}

0 commit comments

Comments
 (0)