Skip to content

Commit 883df38

Browse files
committed
feat: better code documentation
1 parent 00fea6e commit 883df38

File tree

3 files changed

+55
-15
lines changed

3 files changed

+55
-15
lines changed

ios/ReactNativeBrownfield.swift

Lines changed: 49 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,57 @@ import ReactAppDependencyProvider
44

55
@objc public class ReactNativeBrownfield: RCTDefaultReactNativeFactoryDelegate {
66
@objc public static let shared = ReactNativeBrownfield()
7-
8-
@objc public var entryFile: String
9-
@objc public var fallbackResource: String?
10-
@objc public var bundlePath: String
11-
@objc public var reactNativeFactory: RCTReactNativeFactory?
127
private var onBundleLoaded: (() -> Void)?
13-
14-
private override init() {
15-
self.entryFile = "index"
16-
self.fallbackResource = nil
17-
self.bundlePath = "main.jsbundle"
18-
super.init()
19-
}
20-
8+
9+
/**
10+
* Path to JavaScript root.
11+
* Default value: "index"
12+
*/
13+
@objc public var entryFile: String = "index"
14+
/**
15+
* Path to bundle fallback resource.
16+
* Default value: nil
17+
*/
18+
@objc public var fallbackResource: String? = nil
19+
/**
20+
* Path to JavaScript bundle file.
21+
* Default value: "main.jsbundle"
22+
*/
23+
@objc public var bundlePath: String = "main.jsbundle"
24+
/**
25+
* React Native factory instance created when starting React Native.
26+
* Default value: nil
27+
*/
28+
@objc public var reactNativeFactory: RCTReactNativeFactory? = nil
29+
/**
30+
* Root view factory used to create React Native views.
31+
*/
32+
@objc lazy public var rootViewFactory: RCTRootViewFactory? = {
33+
return reactNativeFactory?.rootViewFactory
34+
}()
35+
36+
/**
37+
* Starts React Native with default parameters.
38+
*/
2139
@objc public func startReactNative() {
2240
startReactNative(onBundleLoaded: nil)
2341
}
2442

43+
/**
44+
* Starts React Native with optional callback when bundle is loaded.
45+
*
46+
* @param onBundleLoaded Optional callback invoked after JS bundle is fully loaded.
47+
*/
2548
@objc public func startReactNative(onBundleLoaded: (() -> Void)?) {
2649
startReactNative(onBundleLoaded: onBundleLoaded, launchOptions: nil)
2750
}
2851

52+
/**
53+
* Starts React Native with optional callback and launch options.
54+
*
55+
* @param onBundleLoaded Optional callback invoked after JS bundle is fully loaded.
56+
* @param launchOptions Launch options, typically passed from AppDelegate.
57+
*/
2958
@objc public func startReactNative(onBundleLoaded: (() -> Void)?, launchOptions: [AnyHashable: Any]?) {
3059
guard reactNativeFactory == nil else { return }
3160

@@ -58,7 +87,7 @@ import ReactAppDependencyProvider
5887
NotificationCenter.default.removeObserver(self)
5988
}
6089

61-
// MARK: - RCTBridgeDelegate Methods
90+
// MARK: - RCTReactNativeFactoryDelegate Methods
6291

6392
@objc public override func sourceURL(for bridge: RCTBridge) -> URL? {
6493
return bundleURL()
@@ -79,6 +108,12 @@ import ReactAppDependencyProvider
79108
}
80109

81110
extension Notification.Name {
111+
/**
112+
* Notification sent when React Native wants to navigate back to native screen.
113+
*/
82114
public static let popToNative = Notification.Name("PopToNativeNotification")
115+
/**
116+
* Notification sent to enable/disable the pop gesture recognizer.
117+
*/
83118
public static let togglePopGestureRecognizer = Notification.Name("TogglePopGestureRecognizerNotification")
84119
}

ios/ReactNativeBrownfieldModule.m

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
#import "ReactNativeBrownfieldModule.h"
2+
3+
#if __has_include("ReactNativeBrownfield/ReactNativeBrownfield-Swift.h")
4+
#import "ReactNativeBrownfield/ReactNativeBrownfield-Swift.h"
5+
#else
26
#import "ReactNativeBrownfield-Swift.h"
7+
#endif
38

49
@implementation ReactNativeBrownfieldModule
510

ios/ReactNativeViewController.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import React
1818
public override func viewDidLoad() {
1919
super.viewDidLoad()
2020

21-
guard let factory = ReactNativeBrownfield.shared.reactNativeFactory?.rootViewFactory else {
21+
guard let factory = ReactNativeBrownfield.shared.rootViewFactory else {
2222
print("Error: You need to start React Native in order to use ReactNativeViewController, make sure to run BridgeManager.shared.startReactNative() before instantiating it.")
2323
return
2424
}

0 commit comments

Comments
 (0)