Skip to content

Commit 987bed3

Browse files
committed
Update example README to reflect RN 0.75 changes
Also cleanup AppDelegate.
1 parent 2820ed8 commit 987bed3

File tree

6 files changed

+44
-59
lines changed

6 files changed

+44
-59
lines changed

apps/example/README.md

Lines changed: 29 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -13,41 +13,42 @@ The Project name in this example is `Example`, which you should replace with you
1313

1414
Create a new `AppDelegate.swift` file, once prompted, click *Create bridging headers for Swift*.
1515

16-
Paste the following code to the `AppDelegate.swift`, it includes Flipper code.
16+
Paste the following code to the `AppDelegate.swift`.
1717

1818
```swift
1919
// ios/AppDelegate.swift
2020
import UIKit
2121
import CarPlay
2222
import React
23-
#if DEBUG
24-
#if FB_SONARKIT_ENABLED
25-
import FlipperKit
26-
#endif
27-
#endif
2823

2924
@main
3025
class AppDelegate: UIResponder, UIApplicationDelegate, RCTBridgeDelegate {
3126

32-
var window: UIWindow?
33-
var bridge: RCTBridge?;
34-
var rootView: RCTRootView?;
27+
var rootView: UIView?
28+
29+
override func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
30+
moduleName = "RNCarPlayScene"
31+
initialProps = [:]
3532

36-
static var shared: AppDelegate { return UIApplication.shared.delegate as! AppDelegate }
33+
let app = super.application(application, didFinishLaunchingWithOptions: launchOptions)
34+
self.rootView = self.createRootView(
35+
with: self.bridge!,
36+
moduleName: self.moduleName!,
37+
initProps: self.initialProps!
38+
)
39+
return app
40+
}
3741

38-
func sourceURL(for bridge: RCTBridge!) -> URL! {
42+
override func bundleURL() -> URL? {
3943
#if DEBUG
40-
return RCTBundleURLProvider.sharedSettings().jsBundleURL(forBundleRoot: "index");
44+
return RCTBundleURLProvider.sharedSettings().jsBundleURL(forBundleRoot: "index")
4145
#else
4246
return Bundle.main.url(forResource:"main", withExtension:"jsbundle")
4347
#endif
4448
}
4549

46-
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
47-
initializeFlipper(with: application)
48-
self.bridge = RCTBridge.init(delegate: self, launchOptions: launchOptions)
49-
self.rootView = RCTRootView.init(bridge: self.bridge!, moduleName: "Example", initialProperties: nil)
50-
return true
50+
override func sourceURL(for bridge: RCTBridge) -> URL? {
51+
return bundleURL()
5152
}
5253

5354
func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration {
@@ -64,47 +65,22 @@ class AppDelegate: UIResponder, UIApplicationDelegate, RCTBridgeDelegate {
6465

6566
func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: Set<UISceneSession>) {
6667
}
67-
68-
private func initializeFlipper(with application: UIApplication) {
69-
#if DEBUG
70-
#if FB_SONARKIT_ENABLED
71-
let client = FlipperClient.shared()
72-
let layoutDescriptorMapper = SKDescriptorMapper(defaults: ())
73-
client?.add(FlipperKitLayoutPlugin(rootNode: application, with: layoutDescriptorMapper!))
74-
client?.add(FKUserDefaultsPlugin(suiteName: nil))
75-
client?.add(FlipperKitReactPlugin())
76-
client?.add(FlipperKitNetworkPlugin(networkAdapter: SKIOSNetworkAdapter()))
77-
client?.start()
78-
#endif
79-
#endif
80-
}
8168
}
8269
```
8370

8471
Paste the following to your bridging header file `Example-Bridging-Header.h`:
8572

8673
```objc
8774
// ios/Example-Bridging-Header.h
75+
#import <RCTAppDelegate.h>
8876
#import "RNCarPlay.h"
89-
90-
#ifdef DEBUG
91-
#ifdef FB_SONARKIT_ENABLED
92-
#import <FlipperKit/FlipperClient.h>
93-
#import <FlipperKitLayoutPlugin/FlipperKitLayoutPlugin.h>
94-
#import <FlipperKitUserDefaultsPlugin/FKUserDefaultsPlugin.h>
95-
#import <FlipperKitNetworkPlugin/FlipperKitNetworkPlugin.h>
96-
#import <SKIOSNetworkPlugin/SKIOSNetworkAdapter.h>
97-
#import <FlipperKitReactPlugin/FlipperKitReactPlugin.h>
98-
#endif
99-
#endif
10077
```
10178

102-
### 3. Add flags for Swift compiler in debug mode
79+
### 3. Add flag for Swift compiler in debug mode
10380

104-
Go to XCode project, hit `Build Settings`, search for `Swift Compiler - Custom Flags` and then under `Active Compilation Conditions`, add the following flags to `Debug` only:
81+
Go to XCode project, hit `Build Settings`, search for `Swift Compiler - Custom Flags` and then under `Active Compilation Conditions`, add the following flag to `Debug` only:
10582

10683
- DEBUG
107-
- FB_SONARKIT_ENABLED
10884

10985
### 4. Create Phone Scene
11086

@@ -119,11 +95,16 @@ import SwiftUI
11995
class PhoneSceneDelegate: UIResponder, UIWindowSceneDelegate {
12096
var window: UIWindow?
12197
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
98+
99+
if session.role != .windowApplication {
100+
return
101+
}
102+
122103
guard let appDelegate = (UIApplication.shared.delegate as? AppDelegate) else { return }
123104
guard let windowScene = (scene as? UIWindowScene) else { return }
124105

125106
let rootViewController = UIViewController()
126-
rootViewController.view = appDelegate.rootView;
107+
rootViewController.view = appDelegate.rootView
127108

128109
let window = UIWindow(windowScene: windowScene)
129110
window.rootViewController = rootViewController
@@ -146,14 +127,15 @@ import CarPlay
146127
class CarSceneDelegate: UIResponder, CPTemplateApplicationSceneDelegate {
147128
func templateApplicationScene(_ templateApplicationScene: CPTemplateApplicationScene,
148129
didConnect interfaceController: CPInterfaceController) {
149-
RNCarPlay.connect(with: interfaceController, window: templateApplicationScene.carWindow);
130+
RNCarPlay.connect(with: interfaceController, window: templateApplicationScene.carWindow)
150131
}
151132

152133
func templateApplicationScene(_ templateApplicationScene: CPTemplateApplicationScene, didDisconnectInterfaceController interfaceController: CPInterfaceController) {
153134
RNCarPlay.disconnect()
154135
}
155136
}
156137

138+
157139
```
158140

159141
### 6. Update the manifest in Info.plist

apps/example/ios/AppDelegate.swift

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,21 @@ import React
55
@main
66
class AppDelegate: RCTAppDelegate {
77

8-
var rootView: UIView?;
9-
var concurrentRootEnabled = true;
10-
11-
static var shared: AppDelegate { return UIApplication.shared.delegate as! AppDelegate }
8+
var rootView: UIView?
129

1310
override func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
1411
moduleName = "RNCarPlayScene"
1512
initialProps = [:]
1613

17-
return super.application(application, didFinishLaunchingWithOptions: launchOptions);
14+
let app = super.application(application, didFinishLaunchingWithOptions: launchOptions)
15+
self.rootView = self.createRootView(
16+
with: self.bridge!,
17+
moduleName: self.moduleName!,
18+
initProps: self.initialProps!
19+
)
20+
return app
1821
}
19-
22+
2023
override func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration {
2124
if (connectingSceneSession.role == UISceneSession.Role.carTemplateApplication) {
2225
let scene = UISceneConfiguration(name: "CarPlay", sessionRole: connectingSceneSession.role)
@@ -31,9 +34,9 @@ class AppDelegate: RCTAppDelegate {
3134

3235
override func bundleURL() -> URL? {
3336
#if DEBUG
34-
return RCTBundleURLProvider.sharedSettings().jsBundleURL(forBundleRoot: "index");
37+
return RCTBundleURLProvider.sharedSettings().jsBundleURL(forBundleRoot: "index")
3538
#else
36-
return Bundle.main.url(forResource:"main", withExtension:"jsbundle")
39+
return Bundle.main.url(forResource:"main", withExtension:"jsbundle")
3740
#endif
3841
}
3942

apps/example/ios/CarScene.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import CarPlay
44
class CarSceneDelegate: UIResponder, CPTemplateApplicationSceneDelegate {
55
func templateApplicationScene(_ templateApplicationScene: CPTemplateApplicationScene,
66
didConnect interfaceController: CPInterfaceController) {
7-
RNCarPlay.connect(with: interfaceController, window: templateApplicationScene.carWindow);
7+
RNCarPlay.connect(with: interfaceController, window: templateApplicationScene.carWindow)
88
}
99

1010
func templateApplicationScene(_ templateApplicationScene: CPTemplateApplicationScene, didDisconnectInterfaceController interfaceController: CPInterfaceController) {

apps/example/ios/PhoneScene.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class PhoneSceneDelegate: UIResponder, UIWindowSceneDelegate {
1414
guard let windowScene = (scene as? UIWindowScene) else { return }
1515

1616
let rootViewController = UIViewController()
17-
rootViewController.view = appDelegate.rootView;
17+
rootViewController.view = appDelegate.rootView
1818

1919
let window = UIWindow(windowScene: windowScene)
2020
window.rootViewController = rootViewController
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
#import "RNCarPlay.h"
21
#import <RCTAppDelegate.h>
2+
#import "RNCarPlay.h"

apps/example/ios/RNCarPlayScene.xcodeproj/project.pbxproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,7 @@
495495
);
496496
PRODUCT_BUNDLE_IDENTIFIER = "org.reactjs.native.example.$(PRODUCT_NAME:rfc1034identifier)";
497497
PRODUCT_NAME = RNCarPlayScene;
498-
SWIFT_ACTIVE_COMPILATION_CONDITIONS = "DEBUG FB_SONARKIT_ENABLED";
498+
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
499499
SWIFT_OBJC_BRIDGING_HEADER = "RNCarPlayScene-Bridging-Header.h";
500500
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
501501
SWIFT_VERSION = 5.0;

0 commit comments

Comments
 (0)