Skip to content

Commit c5ce25d

Browse files
committed
feat: SwiftUI support
1 parent eed1607 commit c5ce25d

File tree

3 files changed

+63
-71
lines changed

3 files changed

+63
-71
lines changed

example/swift/AppDelegate.swift

Lines changed: 44 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,55 @@
1-
//
2-
// AppDelegate.swift
3-
// SwiftExample
4-
//
5-
// Created by Michal Chudziak on 25/08/2019.
6-
// Copyright © 2019 Callstack. All rights reserved.
7-
//
8-
91
import UIKit
2+
import SwiftUI
103

11-
@UIApplicationMain
124
class AppDelegate: UIResponder, UIApplicationDelegate {
13-
14-
var window: UIWindow?
15-
16-
17-
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
18-
// Override point for customization after application launch.
19-
ReactNativeBrownfield.shared().entryFile = "index"
20-
ReactNativeBrownfield.shared().startReactNative {
21-
print("loaded")
22-
}
23-
24-
return true
25-
}
26-
27-
func applicationWillResignActive(_ application: UIApplication) {
28-
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
29-
// Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
30-
}
31-
32-
func applicationDidEnterBackground(_ application: UIApplication) {
33-
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
34-
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
5+
var window: UIWindow?
6+
7+
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
8+
// Override point for customization after application launch.
9+
ReactNativeBrownfield.shared().entryFile = "index"
10+
ReactNativeBrownfield.shared().startReactNative {
11+
print("loaded")
3512
}
13+
14+
return true
15+
}
16+
}
3617

37-
func applicationWillEnterForeground(_ application: UIApplication) {
38-
// Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
39-
}
18+
struct UIViewControllerWrapper: UIViewControllerRepresentable {
19+
let viewController: UIViewController
20+
21+
func makeUIViewController(context: Context) -> UIViewController {
22+
return viewController
23+
}
24+
25+
func updateUIViewController(_ uiViewController: UIViewController, context: Context) {}
26+
}
4027

41-
func applicationDidBecomeActive(_ application: UIApplication) {
42-
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
28+
@main
29+
struct MyApp: App {
30+
@UIApplicationDelegateAdaptor(AppDelegate.self) var appDelegate
31+
32+
var body: some Scene {
33+
WindowGroup {
34+
ContentView()
4335
}
36+
}
37+
}
4438

45-
func applicationWillTerminate(_ application: UIApplication) {
46-
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
39+
// Main content view
40+
struct ContentView: View {
41+
var body: some View {
42+
NavigationView {
43+
VStack {
44+
Text("React Native Brownfield App")
45+
.font(.title)
46+
.bold()
47+
.padding()
48+
NavigationLink("Push React Native Screen") {
49+
UIViewControllerWrapper(viewController: ReactNativeViewController(moduleName: "ReactNative"))
50+
}
51+
}
4752
}
48-
49-
53+
}
5054
}
5155

example/swift/SwiftExample.xcodeproj/project.pbxproj

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
archiveVersion = 1;
44
classes = {
55
};
6-
objectVersion = 50;
6+
objectVersion = 54;
77
objects = {
88

99
/* Begin PBXBuildFile section */
@@ -25,7 +25,7 @@
2525
2869186523129ED100458242 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; };
2626
2869186723129ED100458242 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
2727
28C192112315C4D50049A702 /* BridgingHeader.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = BridgingHeader.h; sourceTree = "<group>"; };
28-
33BE347ABB4EE17F7F99D32D /* PrivacyInfo.xcprivacy */ = {isa = PBXFileReference; includeInIndex = 1; path = PrivacyInfo.xcprivacy; sourceTree = "<group>"; };
28+
33BE347ABB4EE17F7F99D32D /* PrivacyInfo.xcprivacy */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xml; path = PrivacyInfo.xcprivacy; sourceTree = "<group>"; };
2929
5BE9069F7C8AF5853F650B68 /* Pods-SwiftExample.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-SwiftExample.debug.xcconfig"; path = "Target Support Files/Pods-SwiftExample/Pods-SwiftExample.debug.xcconfig"; sourceTree = "<group>"; };
3030
CF9653D1882655DA02862F71 /* libPods-SwiftExample.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-SwiftExample.a"; sourceTree = BUILT_PRODUCTS_DIR; };
3131
E74DC3AFAC0967529ED1C063 /* Pods-SwiftExample.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-SwiftExample.release.xcconfig"; path = "Target Support Files/Pods-SwiftExample/Pods-SwiftExample.release.xcconfig"; sourceTree = "<group>"; };
@@ -338,18 +338,15 @@
338338
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
339339
GCC_WARN_UNUSED_FUNCTION = YES;
340340
GCC_WARN_UNUSED_VARIABLE = YES;
341-
IPHONEOS_DEPLOYMENT_TARGET = 12.2;
341+
IPHONEOS_DEPLOYMENT_TARGET = 15.6;
342342
LD = "";
343343
LDPLUSPLUS = "";
344344
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
345345
MTL_FAST_MATH = YES;
346346
ONLY_ACTIVE_ARCH = YES;
347347
OTHER_CFLAGS = "$(inherited)";
348348
OTHER_CPLUSPLUSFLAGS = "$(inherited)";
349-
OTHER_LDFLAGS = (
350-
"$(inherited)",
351-
" ",
352-
);
349+
OTHER_LDFLAGS = "$(inherited) ";
353350
REACT_NATIVE_PATH = "${PODS_ROOT}/../../node_modules/react-native";
354351
SDKROOT = iphoneos;
355352
SWIFT_ACTIVE_COMPILATION_CONDITIONS = "$(inherited) DEBUG";
@@ -406,17 +403,14 @@
406403
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
407404
GCC_WARN_UNUSED_FUNCTION = YES;
408405
GCC_WARN_UNUSED_VARIABLE = YES;
409-
IPHONEOS_DEPLOYMENT_TARGET = 12.2;
406+
IPHONEOS_DEPLOYMENT_TARGET = 15.6;
410407
LD = "";
411408
LDPLUSPLUS = "";
412409
MTL_ENABLE_DEBUG_INFO = NO;
413410
MTL_FAST_MATH = YES;
414411
OTHER_CFLAGS = "$(inherited)";
415412
OTHER_CPLUSPLUSFLAGS = "$(inherited)";
416-
OTHER_LDFLAGS = (
417-
"$(inherited)",
418-
" ",
419-
);
413+
OTHER_LDFLAGS = "$(inherited) ";
420414
REACT_NATIVE_PATH = "${PODS_ROOT}/../../node_modules/react-native";
421415
SDKROOT = iphoneos;
422416
SWIFT_COMPILATION_MODE = wholemodule;
@@ -434,6 +428,7 @@
434428
CODE_SIGN_STYLE = Automatic;
435429
DEVELOPMENT_TEAM = PJL7DA2X5F;
436430
INFOPLIST_FILE = Info.plist;
431+
IPHONEOS_DEPLOYMENT_TARGET = 15.0;
437432
LD_RUNPATH_SEARCH_PATHS = (
438433
"$(inherited)",
439434
"@executable_path/Frameworks",
@@ -454,6 +449,7 @@
454449
CODE_SIGN_STYLE = Automatic;
455450
DEVELOPMENT_TEAM = PJL7DA2X5F;
456451
INFOPLIST_FILE = Info.plist;
452+
IPHONEOS_DEPLOYMENT_TARGET = 15.0;
457453
LD_RUNPATH_SEARCH_PATHS = (
458454
"$(inherited)",
459455
"@executable_path/Frameworks",

example/swift/ViewController.swift

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,16 @@
1-
//
2-
// ViewController.swift
3-
// SwiftExample
4-
//
5-
// Created by Michal Chudziak on 25/08/2019.
6-
// Copyright © 2019 Callstack. All rights reserved.
7-
//
8-
91
import UIKit
102

113
class ViewController: UIViewController {
12-
override func viewDidLoad() {
13-
super.viewDidLoad()
14-
}
15-
16-
17-
@IBAction func openReactNative(_ sender: UIButton) {
18-
self.navigationController?.pushViewController(
19-
ReactNativeViewController(moduleName: "ReactNative"),
20-
animated: true
21-
)
22-
}
4+
override func viewDidLoad() {
5+
super.viewDidLoad()
6+
}
7+
8+
9+
@IBAction func openReactNative(_ sender: UIButton) {
10+
self.navigationController?.pushViewController(
11+
ReactNativeViewController(moduleName: "ReactNative"),
12+
animated: true
13+
)
14+
}
2315
}
2416

0 commit comments

Comments
 (0)