@callstack/react-native-brownfield 1.0.0-rc.1 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/ReactBrownfield.podspec
CHANGED
|
@@ -15,8 +15,13 @@ Pod::Spec.new do |spec|
|
|
|
15
15
|
spec.module_name = "ReactBrownfield"
|
|
16
16
|
spec.source = { :git => "git@github.com:callstack/react-native-brownfield.git", :tag => "#{spec.version}" }
|
|
17
17
|
spec.source_files = "ios/**/*.{h,m,mm,swift}"
|
|
18
|
-
spec.pod_target_xcconfig = {
|
|
18
|
+
spec.pod_target_xcconfig = {
|
|
19
|
+
'DEFINES_MODULE' => 'YES',
|
|
20
|
+
'OTHER_SWIFT_FLAGS' => "-enable-experimental-feature AccessLevelOnImport"
|
|
21
|
+
}
|
|
19
22
|
|
|
20
23
|
spec.dependency 'ReactAppDependencyProvider'
|
|
24
|
+
add_dependency(spec, "React-RCTAppDelegate")
|
|
25
|
+
|
|
21
26
|
install_modules_dependencies(spec)
|
|
22
27
|
end
|
|
@@ -1,16 +1,44 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
1
|
+
import UIKit
|
|
2
|
+
internal import React
|
|
3
|
+
internal import React_RCTAppDelegate
|
|
4
|
+
internal import ReactAppDependencyProvider
|
|
4
5
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
class ReactNativeBrownfieldDelegate: RCTDefaultReactNativeFactoryDelegate {
|
|
7
|
+
var entryFile = "index"
|
|
8
|
+
// MARK: - RCTReactNativeFactoryDelegate Methods
|
|
9
|
+
|
|
10
|
+
override func sourceURL(for bridge: RCTBridge) -> URL? {
|
|
11
|
+
return bundleURL()
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
public override func bundleURL() -> URL? {
|
|
15
|
+
#if DEBUG
|
|
16
|
+
return RCTBundleURLProvider.sharedSettings().jsBundleURL(forBundleRoot: entryFile)
|
|
17
|
+
#else
|
|
18
|
+
let resourceURLComponents = bundlePath.components(separatedBy: ".")
|
|
19
|
+
let withoutLast = resourceURLComponents[..<(resourceURLComponents.count - 1)]
|
|
20
|
+
let resourceName = withoutLast.joined()
|
|
21
|
+
let fileExtension = resourceURLComponents.last ?? ""
|
|
22
|
+
|
|
23
|
+
return Bundle.main.url(forResource: resourceName, withExtension: fileExtension)
|
|
24
|
+
#endif
|
|
25
|
+
}
|
|
26
|
+
}
|
|
8
27
|
|
|
28
|
+
@objc public class ReactNativeBrownfield: NSObject {
|
|
29
|
+
public static let shared = ReactNativeBrownfield()
|
|
30
|
+
private var onBundleLoaded: (() -> Void)?
|
|
31
|
+
private var delegate = ReactNativeBrownfieldDelegate()
|
|
32
|
+
|
|
9
33
|
/**
|
|
10
34
|
* Path to JavaScript root.
|
|
11
35
|
* Default value: "index"
|
|
12
36
|
*/
|
|
13
|
-
@objc public var entryFile: String = "index"
|
|
37
|
+
@objc public var entryFile: String = "index" {
|
|
38
|
+
didSet {
|
|
39
|
+
delegate.entryFile = entryFile
|
|
40
|
+
}
|
|
41
|
+
}
|
|
14
42
|
/**
|
|
15
43
|
* Path to bundle fallback resource.
|
|
16
44
|
* Default value: nil
|
|
@@ -25,14 +53,14 @@ import ReactAppDependencyProvider
|
|
|
25
53
|
* React Native factory instance created when starting React Native.
|
|
26
54
|
* Default value: nil
|
|
27
55
|
*/
|
|
28
|
-
|
|
56
|
+
private var reactNativeFactory: RCTReactNativeFactory? = nil
|
|
29
57
|
/**
|
|
30
58
|
* Root view factory used to create React Native views.
|
|
31
59
|
*/
|
|
32
|
-
|
|
60
|
+
lazy private var rootViewFactory: RCTRootViewFactory? = {
|
|
33
61
|
return reactNativeFactory?.rootViewFactory
|
|
34
62
|
}()
|
|
35
|
-
|
|
63
|
+
|
|
36
64
|
/**
|
|
37
65
|
* Starts React Native with default parameters.
|
|
38
66
|
*/
|
|
@@ -40,9 +68,21 @@ import ReactAppDependencyProvider
|
|
|
40
68
|
startReactNative(onBundleLoaded: nil)
|
|
41
69
|
}
|
|
42
70
|
|
|
71
|
+
@objc public func view(
|
|
72
|
+
moduleName: String,
|
|
73
|
+
initialProps: [AnyHashable: Any]?,
|
|
74
|
+
launchOptions: [AnyHashable: Any]? = nil
|
|
75
|
+
) -> UIView? {
|
|
76
|
+
reactNativeFactory?.rootViewFactory.view(
|
|
77
|
+
withModuleName: moduleName,
|
|
78
|
+
initialProperties: initialProps,
|
|
79
|
+
launchOptions: launchOptions
|
|
80
|
+
)
|
|
81
|
+
}
|
|
82
|
+
|
|
43
83
|
/**
|
|
44
84
|
* Starts React Native with optional callback when bundle is loaded.
|
|
45
|
-
*
|
|
85
|
+
*
|
|
46
86
|
* @param onBundleLoaded Optional callback invoked after JS bundle is fully loaded.
|
|
47
87
|
*/
|
|
48
88
|
@objc public func startReactNative(onBundleLoaded: (() -> Void)?) {
|
|
@@ -51,15 +91,15 @@ import ReactAppDependencyProvider
|
|
|
51
91
|
|
|
52
92
|
/**
|
|
53
93
|
* Starts React Native with optional callback and launch options.
|
|
54
|
-
*
|
|
94
|
+
*
|
|
55
95
|
* @param onBundleLoaded Optional callback invoked after JS bundle is fully loaded.
|
|
56
96
|
* @param launchOptions Launch options, typically passed from AppDelegate.
|
|
57
97
|
*/
|
|
58
98
|
@objc public func startReactNative(onBundleLoaded: (() -> Void)?, launchOptions: [AnyHashable: Any]?) {
|
|
59
99
|
guard reactNativeFactory == nil else { return }
|
|
60
100
|
|
|
61
|
-
|
|
62
|
-
self.reactNativeFactory = RCTReactNativeFactory(delegate:
|
|
101
|
+
delegate.dependencyProvider = RCTAppDependencyProvider()
|
|
102
|
+
self.reactNativeFactory = RCTReactNativeFactory(delegate: delegate)
|
|
63
103
|
|
|
64
104
|
if let onBundleLoaded {
|
|
65
105
|
self.onBundleLoaded = onBundleLoaded
|
|
@@ -86,25 +126,6 @@ import ReactAppDependencyProvider
|
|
|
86
126
|
onBundleLoaded = nil
|
|
87
127
|
NotificationCenter.default.removeObserver(self)
|
|
88
128
|
}
|
|
89
|
-
|
|
90
|
-
// MARK: - RCTReactNativeFactoryDelegate Methods
|
|
91
|
-
|
|
92
|
-
@objc public override func sourceURL(for bridge: RCTBridge) -> URL? {
|
|
93
|
-
return bundleURL()
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
public override func bundleURL() -> URL? {
|
|
97
|
-
#if DEBUG
|
|
98
|
-
return RCTBundleURLProvider.sharedSettings().jsBundleURL(forBundleRoot: entryFile)
|
|
99
|
-
#else
|
|
100
|
-
let resourceURLComponents = bundlePath.components(separatedBy: ".")
|
|
101
|
-
let withoutLast = resourceURLComponents[..<(resourceURLComponents.count - 1)]
|
|
102
|
-
let resourceName = withoutLast.joined()
|
|
103
|
-
let fileExtension = resourceURLComponents.last ?? ""
|
|
104
|
-
|
|
105
|
-
return Bundle.main.url(forResource: resourceName, withExtension: fileExtension)
|
|
106
|
-
#endif
|
|
107
|
-
}
|
|
108
129
|
}
|
|
109
130
|
|
|
110
131
|
extension Notification.Name {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React
|
|
1
|
+
internal import React
|
|
2
2
|
|
|
3
3
|
@objcMembers
|
|
4
4
|
public class ReactNativeBrownfieldModuleImpl: NSObject {
|
|
@@ -8,7 +8,7 @@ public class ReactNativeBrownfieldModuleImpl: NSObject {
|
|
|
8
8
|
NotificationCenter.default.post(name: Notification.Name.togglePopGestureRecognizer, object: nil, userInfo: userInfo)
|
|
9
9
|
}
|
|
10
10
|
}
|
|
11
|
-
|
|
11
|
+
|
|
12
12
|
static public func popToNative(animated: Bool) {
|
|
13
13
|
let userInfo = ["animated": animated]
|
|
14
14
|
DispatchQueue.main.async {
|
|
@@ -1,38 +1,37 @@
|
|
|
1
1
|
import UIKit
|
|
2
|
-
import React
|
|
2
|
+
internal import React
|
|
3
3
|
|
|
4
4
|
@objc public class ReactNativeViewController: UIViewController {
|
|
5
5
|
private var moduleName: String
|
|
6
6
|
private var initialProperties: [String: Any]?
|
|
7
|
-
|
|
7
|
+
|
|
8
8
|
@objc public init(moduleName: String, initialProperties: [String: Any]? = nil) {
|
|
9
9
|
self.moduleName = moduleName
|
|
10
10
|
self.initialProperties = initialProperties
|
|
11
11
|
super.init(nibName: nil, bundle: nil)
|
|
12
12
|
}
|
|
13
|
-
|
|
13
|
+
|
|
14
14
|
required init?(coder: NSCoder) {
|
|
15
15
|
fatalError("init(coder:) has not been implemented")
|
|
16
16
|
}
|
|
17
|
-
|
|
17
|
+
|
|
18
18
|
public override func viewDidLoad() {
|
|
19
19
|
super.viewDidLoad()
|
|
20
|
-
|
|
21
|
-
guard let factory = ReactNativeBrownfield.shared.rootViewFactory else {
|
|
22
|
-
print("Error: You need to start React Native in order to use ReactNativeViewController, make sure to run BridgeManager.shared.startReactNative() before instantiating it.")
|
|
23
|
-
return
|
|
24
|
-
}
|
|
25
|
-
|
|
20
|
+
|
|
26
21
|
if !moduleName.isEmpty {
|
|
27
|
-
view =
|
|
28
|
-
|
|
22
|
+
view = ReactNativeBrownfield.shared.view(
|
|
23
|
+
moduleName: moduleName,
|
|
24
|
+
initialProps: initialProperties,
|
|
25
|
+
launchOptions: nil
|
|
26
|
+
)
|
|
27
|
+
|
|
29
28
|
NotificationCenter.default.addObserver(
|
|
30
29
|
self,
|
|
31
30
|
selector: #selector(togglePopGestureRecognizer(_:)),
|
|
32
31
|
name: NSNotification.Name.togglePopGestureRecognizer,
|
|
33
32
|
object: nil
|
|
34
33
|
)
|
|
35
|
-
|
|
34
|
+
|
|
36
35
|
NotificationCenter.default.addObserver(
|
|
37
36
|
self,
|
|
38
37
|
selector: #selector(popToNative(_:)),
|
|
@@ -41,24 +40,24 @@ import React
|
|
|
41
40
|
)
|
|
42
41
|
}
|
|
43
42
|
}
|
|
44
|
-
|
|
43
|
+
|
|
45
44
|
deinit {
|
|
46
45
|
NotificationCenter.default.removeObserver(self)
|
|
47
46
|
}
|
|
48
|
-
|
|
47
|
+
|
|
49
48
|
@objc private func togglePopGestureRecognizer(_ notification: Notification) {
|
|
50
49
|
guard let userInfo = notification.userInfo,
|
|
51
50
|
let enabled = userInfo["enabled"] as? Bool else { return }
|
|
52
|
-
|
|
51
|
+
|
|
53
52
|
DispatchQueue.main.async { [weak self] in
|
|
54
53
|
self?.navigationController?.interactivePopGestureRecognizer?.isEnabled = enabled
|
|
55
54
|
}
|
|
56
55
|
}
|
|
57
|
-
|
|
56
|
+
|
|
58
57
|
@objc private func popToNative(_ notification: Notification) {
|
|
59
58
|
guard let userInfo = notification.userInfo,
|
|
60
59
|
let animated = userInfo["animated"] as? Bool else { return }
|
|
61
|
-
|
|
60
|
+
|
|
62
61
|
DispatchQueue.main.async { [weak self] in
|
|
63
62
|
self?.navigationController?.popViewController(animated: animated)
|
|
64
63
|
}
|