Skip to content

Commit f98697d

Browse files
authored
feat: rewrite to Swift (#95)
* feat: rewrite to Swift * docs: reflect api changes * fix: remove bridging header * fix: properly call onBundleLoaded for new arch
1 parent eed1607 commit f98697d

18 files changed

+216
-315
lines changed

ReactNativeBrownfield.podspec

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ Pod::Spec.new do |spec|
2020
spec.source = { :path => "." }
2121
spec.source_files = "ios/**/*.{h,m,mm,swift}"
2222
spec.compiler_flags = new_arch_enabled_flag
23-
spec.pod_target_xcconfig = { 'OTHER_CPLUSPLUSFLAGS' => other_cflags }
23+
spec.pod_target_xcconfig = { 'OTHER_CPLUSPLUSFLAGS' => other_cflags, 'DEFINES_MODULE' => 'YES' }
2424

2525
install_modules_dependencies(spec)
26+
spec.dependency 'ReactAppDependencyProvider'
2627
end

docs/OBJECTIVE_C.md

+9-9
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,12 @@ Examples:
6868

6969
**Properties:**
7070

71-
| Property | Type | Default | Description |
72-
| -------------------- | --------- | -------------- | -------------------------------------------------- |
73-
| bridge | RCTBridge | nil | Launch options, typically passed from AppDelegate. |
74-
| entryFile | NSString | index | Path to JavaScript root. |
75-
| fallbackResource | NSString | nil | Path to bundle fallback resource. |
76-
| bundlePath | NSString | main.jsbundle | Path to bundle fallback resource. |
71+
| Property | Type | Default | Description |
72+
| -------------------------- | ----------------------- | -------------- | -------------------------------------------------- |
73+
| entryFile | NSString | index | Path to JavaScript root. |
74+
| fallbackResource | NSString | nil | Path to bundle fallback resource. |
75+
| bundlePath | NSString | main.jsbundle | Path to bundle fallback resource. |
76+
| reactNativeFactory | RCTReactNativeFactory | nil | React Native factory instance. |
7777

7878
---
7979

@@ -112,7 +112,7 @@ Examples:
112112

113113
#### ReactNativeViewController
114114

115-
A view controller that's rendering `RCTRootView` within its bounds. It automatically uses an instance of a bridge created in `startReactNative` method. It works well with exposed JavaScript module. It's the simplest way to embed React Native into your navigation stack.
115+
A view controller that's rendering React Native view within its bounds. It automatically uses an instance of a factory created in `startReactNative` method. It works well with exposed JavaScript module. It's the simplest way to embed React Native into your navigation stack.
116116

117117
You can import it from:
118118

@@ -129,7 +129,7 @@ You can import it from:
129129
| Param | Required | Type | Description |
130130
| ------------------ | --------- | ------------- | ------------------------------------------------------------- |
131131
| moduleName | Yes | NSString | Name of React Native component registered to `AppRegistry`. |
132-
| initialProperties | No | NSString | Initial properties to be passed to React Native component. |
132+
| initialProperties | No | NSDictionary | Initial properties to be passed to React Native component. |
133133

134134
Examples:
135135

@@ -138,7 +138,7 @@ Examples:
138138
```
139139
140140
```objc
141-
[[ReactNativeViewController alloc] initWithModuleName:@"ReactNative" andInitialProperties:@{@"score": 12}]
141+
[[ReactNativeViewController alloc] initWithModuleName:@"ReactNative" andInitialProperties:@{@"score": @12}]
142142
```
143143

144144
---

docs/SWIFT.md

+20-20
Original file line numberDiff line numberDiff line change
@@ -68,26 +68,26 @@ You can import the object from:
6868

6969
**Statics:**
7070

71-
`shared()`
71+
`shared`
7272

7373
A singleton that keeps an instance of ReactNativeBrownfield object.
7474

7575
Examples:
7676

7777
```swift
78-
ReactNativeBrownfield.shared()
78+
ReactNativeBrownfield.shared
7979
```
8080

8181
---
8282

8383
**Properties:**
8484

85-
| Property | Type | Default | Description |
86-
| -------------------- | --------- | -------------- | -------------------------------------------------- |
87-
| bridge | RCTBridge | nil | Launch options, typically passed from AppDelegate. |
88-
| entryFile | NSString | index | Path to JavaScript root. |
89-
| fallbackResource | NSString | nil | Path to bundle fallback resource. |
90-
| bundlePath | NSString | main.jsbundle | Path to bundle fallback resource. |
85+
| Property | Type | Default | Description |
86+
| -------------------------- | ----------------------- | -------------- | -------------------------------------------------- |
87+
| entryFile | String | index | Path to JavaScript root. |
88+
| fallbackResource | String? | nil | Path to bundle fallback resource. |
89+
| bundlePath | String | main.jsbundle | Path to bundle fallback resource. |
90+
| reactNativeFactory | RCTReactNativeFactory? | nil | React Native factory instance. |
9191

9292
---
9393

@@ -101,32 +101,32 @@ Params:
101101

102102
| Param | Required | Type | Description |
103103
| ----------------------- | -------- | ------------- | ----------------------------------------------------- |
104-
| onBundleLoaded | No | () -> void | Callback invoked after JS bundle is fully loaded. |
105-
| launchOptions | No | NSDictionary | Launch options, typically passed from AppDelegate. |
104+
| onBundleLoaded | No | (() -> Void)? | Callback invoked after JS bundle is fully loaded. |
105+
| launchOptions | No | [AnyHashable: Any]? | Launch options, typically passed from AppDelegate. |
106106

107107
Examples:
108108

109109
```swift
110-
ReactNativeBrownfield.shared().startReactNative()
110+
ReactNativeBrownfield.shared.startReactNative()
111111
```
112112

113113
```swift
114-
ReactNativeBrownfield.shared().startReactNative {
114+
ReactNativeBrownfield.shared.startReactNative(onBundleLoaded: {
115115
print("React Native started")
116-
}
116+
})
117117
```
118118

119119
```swift
120-
ReactNativeBrownfield.shared().startReactNative({
120+
ReactNativeBrownfield.shared.startReactNative(onBundleLoaded: {
121121
print("React Native started")
122-
}, launchOptions)
122+
}, launchOptions: launchOptions)
123123
```
124124

125125
---
126126

127127
#### ReactNativeViewController
128128

129-
A view controller that's rendering `RCTRootView` within its bounds. It automatically uses an instance of a bridge created in `startReactNative` method. It works well with exposed JavaScript module. It's the simplest way to embed React Native into your navigation stack.
129+
A view controller that's rendering React Native view within its bounds. It automatically uses an instance of a factory created in `startReactNative` method. It works well with exposed JavaScript module. It's the simplest way to embed React Native into your navigation stack.
130130

131131
You can import it from:
132132

@@ -138,12 +138,12 @@ You can import it from:
138138

139139
**Constructors:**
140140

141-
`ReactNativeViewController(moduleName: moduleName, initialProperites:initialProperties)`
141+
`ReactNativeViewController(moduleName: moduleName, initialProperties: initialProperties)`
142142

143143
| Param | Required | Type | Description |
144144
| ------------------ | --------- | ------------- | ------------------------------------------------------------- |
145-
| moduleName | Yes | NSString | Name of React Native component registered to `AppRegistry`. |
146-
| initialProperties | No | NSString | Initial properties to be passed to React Native component. |
145+
| moduleName | Yes | String | Name of React Native component registered to `AppRegistry`. |
146+
| initialProperties | No | [String: Any]? | Initial properties to be passed to React Native component. |
147147

148148
Examples:
149149

@@ -152,7 +152,7 @@ Examples:
152152
```
153153

154154
```swift
155-
ReactNativeViewController(moduleName: "ReactNative", initialProperites:["score": 12])
155+
ReactNativeViewController(moduleName: "ReactNative", initialProperties: ["score": 12])
156156
```
157157

158158
---

example/swift/AppDelegate.swift

+9-45
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,15 @@
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 ReactNativeBrownfield
103

114
@UIApplicationMain
125
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.
35-
}
36-
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-
}
40-
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.
43-
}
44-
45-
func applicationWillTerminate(_ application: UIApplication) {
46-
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
47-
}
48-
49-
6+
var window: UIWindow?
7+
8+
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
9+
ReactNativeBrownfield.shared.startReactNative {
10+
print("loaded")
11+
}
12+
return true
13+
}
5014
}
5115

example/swift/BridgingHeader.h

-10
This file was deleted.

example/swift/Podfile.lock

+2-1
Original file line numberDiff line numberDiff line change
@@ -1608,6 +1608,7 @@ PODS:
16081608
- React-RCTFabric
16091609
- React-rendererdebug
16101610
- React-utils
1611+
- ReactAppDependencyProvider
16111612
- ReactCodegen
16121613
- ReactCommon/turbomodule/bridging
16131614
- ReactCommon/turbomodule/core
@@ -1945,7 +1946,7 @@ SPEC CHECKSUMS:
19451946
ReactAppDependencyProvider: a1fb08dfdc7ebc387b2e54cfc9decd283ed821d8
19461947
ReactCodegen: 008c319179d681a6a00966edfc67fda68f9fbb2e
19471948
ReactCommon: 0c097b53f03d6bf166edbcd0915da32f3015dd90
1948-
ReactNativeBrownfield: f76cefbba610e3c1d2c48d07da33fc1ef52be259
1949+
ReactNativeBrownfield: 4cbb58bb8076bf4e4c4a9769ada50f6c6db1f6a7
19491950
RNScreens: 0d4cb9afe052607ad0aa71f645a88bb7c7f2e64c
19501951
SocketRocket: d4aabe649be1e368d1318fdf28a022d714d65748
19511952
Yoga: afd04ff05ebe0121a00c468a8a3c8080221cb14c

example/swift/SwiftExample.xcodeproj/project.pbxproj

+6-14
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 */
@@ -24,8 +24,7 @@
2424
2869186223129ED100458242 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
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>"; };
27-
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>"; };
27+
33BE347ABB4EE17F7F99D32D /* PrivacyInfo.xcprivacy */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xml; path = PrivacyInfo.xcprivacy; sourceTree = "<group>"; };
2928
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>"; };
3029
CF9653D1882655DA02862F71 /* libPods-SwiftExample.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-SwiftExample.a"; sourceTree = BUILT_PRODUCTS_DIR; };
3130
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>"; };
@@ -48,7 +47,6 @@
4847
children = (
4948
2869185B23129ECF00458242 /* AppDelegate.swift */,
5049
2869185D23129ECF00458242 /* ViewController.swift */,
51-
28C192112315C4D50049A702 /* BridgingHeader.h */,
5250
2869185F23129ECF00458242 /* Main.storyboard */,
5351
2869186223129ED100458242 /* Assets.xcassets */,
5452
2869186423129ED100458242 /* LaunchScreen.storyboard */,
@@ -346,10 +344,7 @@
346344
ONLY_ACTIVE_ARCH = YES;
347345
OTHER_CFLAGS = "$(inherited)";
348346
OTHER_CPLUSPLUSFLAGS = "$(inherited)";
349-
OTHER_LDFLAGS = (
350-
"$(inherited)",
351-
" ",
352-
);
347+
OTHER_LDFLAGS = "$(inherited) ";
353348
REACT_NATIVE_PATH = "${PODS_ROOT}/../../node_modules/react-native";
354349
SDKROOT = iphoneos;
355350
SWIFT_ACTIVE_COMPILATION_CONDITIONS = "$(inherited) DEBUG";
@@ -413,10 +408,7 @@
413408
MTL_FAST_MATH = YES;
414409
OTHER_CFLAGS = "$(inherited)";
415410
OTHER_CPLUSPLUSFLAGS = "$(inherited)";
416-
OTHER_LDFLAGS = (
417-
"$(inherited)",
418-
" ",
419-
);
411+
OTHER_LDFLAGS = "$(inherited) ";
420412
REACT_NATIVE_PATH = "${PODS_ROOT}/../../node_modules/react-native";
421413
SDKROOT = iphoneos;
422414
SWIFT_COMPILATION_MODE = wholemodule;
@@ -434,13 +426,13 @@
434426
CODE_SIGN_STYLE = Automatic;
435427
DEVELOPMENT_TEAM = PJL7DA2X5F;
436428
INFOPLIST_FILE = Info.plist;
429+
IPHONEOS_DEPLOYMENT_TARGET = 15.6;
437430
LD_RUNPATH_SEARCH_PATHS = (
438431
"$(inherited)",
439432
"@executable_path/Frameworks",
440433
);
441434
PRODUCT_BUNDLE_IDENTIFIER = com.callstack.reactnativebrownfield.SwiftExample;
442435
PRODUCT_NAME = "$(TARGET_NAME)";
443-
SWIFT_OBJC_BRIDGING_HEADER = BridgingHeader.h;
444436
SWIFT_VERSION = 5.0;
445437
TARGETED_DEVICE_FAMILY = "1,2";
446438
};
@@ -454,13 +446,13 @@
454446
CODE_SIGN_STYLE = Automatic;
455447
DEVELOPMENT_TEAM = PJL7DA2X5F;
456448
INFOPLIST_FILE = Info.plist;
449+
IPHONEOS_DEPLOYMENT_TARGET = 15.6;
457450
LD_RUNPATH_SEARCH_PATHS = (
458451
"$(inherited)",
459452
"@executable_path/Frameworks",
460453
);
461454
PRODUCT_BUNDLE_IDENTIFIER = com.callstack.reactnativebrownfield.SwiftExample;
462455
PRODUCT_NAME = "$(TARGET_NAME)";
463-
SWIFT_OBJC_BRIDGING_HEADER = BridgingHeader.h;
464456
SWIFT_VERSION = 5.0;
465457
TARGETED_DEVICE_FAMILY = "1,2";
466458
};

example/swift/ViewController.swift

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
//
88

99
import UIKit
10+
import ReactNativeBrownfield
1011

1112
class ViewController: UIViewController {
1213
override func viewDidLoad() {

ios/ReactNativeBrownfield.h

-29
This file was deleted.

0 commit comments

Comments
 (0)