Skip to content

Commit 18a417f

Browse files
feat: integrate ReactAppDependencyProvider and refactor ReactNativeDelegate
1 parent 4886110 commit 18a417f

6 files changed

Lines changed: 31 additions & 43 deletions

File tree

MendixNative.podspec

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ Pod::Spec.new do |s|
1919

2020
s.dependency "SSZipArchive"
2121
s.dependency "RNCAsyncStorage"
22+
s.dependency "ReactAppDependencyProvider"
2223

2324
install_modules_dependencies(s)
2425
end
Lines changed: 2 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,13 @@
11
import UIKit
22
import React
33
import MendixNative
4-
import React_RCTAppDelegate
5-
import ReactAppDependencyProvider
64

75
@main
86
class AppDelegate: ReactAppProvider {
97

10-
var reactNativeDelegate: ReactNativeDelegate?
11-
128
override func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
13-
14-
15-
let delegate = ReactNativeDelegate()
16-
let factory = RCTReactNativeFactory(delegate: delegate)
17-
delegate.dependencyProvider = RCTAppDependencyProvider()
18-
19-
reactNativeDelegate = delegate
20-
21-
setUpProvider(reactNativeFactory: factory)
22-
guard let bundleUrl = bundleUrl else {
9+
setUpProvider()
10+
guard let bundleUrl = reactNativeDelegate?.bundleURL() else {
2311
fatalError("Unable to find index.js")
2412
}
2513
let mendixApp = MendixApp.init(
@@ -37,27 +25,4 @@ class AppDelegate: ReactAppProvider {
3725
ReactNative.shared.start()
3826
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
3927
}
40-
//
41-
var bundleUrl: URL? {
42-
#if DEBUG
43-
RCTBundleURLProvider.sharedSettings().jsBundleURL(forBundleRoot: "index")
44-
#else
45-
Bundle.main.url(forResource: "main", withExtension: "jsbundle")
46-
#endif
47-
}
48-
}
49-
50-
51-
class ReactNativeDelegate: RCTDefaultReactNativeFactoryDelegate {
52-
override func sourceURL(for bridge: RCTBridge) -> URL? {
53-
self.bundleURL()
54-
}
55-
56-
override func bundleURL() -> URL? {
57-
#if DEBUG
58-
RCTBundleURLProvider.sharedSettings().jsBundleURL(forBundleRoot: "index")
59-
#else
60-
Bundle.main.url(forResource: "main", withExtension: "jsbundle")
61-
#endif
62-
}
6328
}

example/ios/Podfile.lock

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ PODS:
2020
- React-renderercss
2121
- React-rendererdebug
2222
- React-utils
23+
- ReactAppDependencyProvider
2324
- ReactCodegen
2425
- ReactCommon/turbomodule/bridging
2526
- ReactCommon/turbomodule/core
@@ -2125,7 +2126,7 @@ EXTERNAL SOURCES:
21252126
SPEC CHECKSUMS:
21262127
FBLazyVector: e97c19a5a442429d1988f182a1940fb08df514da
21272128
hermes-engine: a7179a4cd45fa3f8143712e52bd3c2d20b5274a0
2128-
MendixNative: a9d1f912d97cf141eaa5fc8aedf04ef45108dbbc
2129+
MendixNative: 0014d648c1ad67c7da144e99603ad636b017b424
21292130
op-sqlite: e9ef65bcf95a97863874cee87841425bb71c8396
21302131
OpenSSL-Universal: 9110d21982bb7e8b22a962b6db56a8aa805afde7
21312132
RCTDeprecation: af44b104091a34482596cd9bd7e8d90c4e9b4bd7

ios/Modules/Helper/ReactAppProvider.swift

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import UIKit
22
import React
33
import React_RCTAppDelegate
4+
import ReactAppDependencyProvider
45

56
@objcMembers
67
open class ReactAppProvider: UIResponder, UIApplicationDelegate {
@@ -9,18 +10,22 @@ open class ReactAppProvider: UIResponder, UIApplicationDelegate {
910

1011
public var window: UIWindow?
1112
public var reactNativeFactory: RCTReactNativeFactory?
13+
public var reactNativeDelegate: ReactNativeDelegate?
1214
public var moduleName: String = defaultName
1315

1416
var reactRootViewName: String = defaultName
1517

1618
public func setUpProvider(
1719
moduleName: String = ReactAppProvider.defaultName,
18-
reactRootViewName: String = ReactAppProvider.defaultName,
19-
reactNativeFactory: RCTReactNativeFactory?
20+
reactRootViewName: String = ReactAppProvider.defaultName
2021
) {
2122
self.moduleName = moduleName
2223
self.reactRootViewName = reactRootViewName
23-
self.reactNativeFactory = reactNativeFactory
24+
let delegate = ReactNativeDelegate()
25+
let factory = RCTReactNativeFactory(delegate: delegate)
26+
delegate.dependencyProvider = RCTAppDependencyProvider()
27+
reactNativeDelegate = delegate
28+
reactNativeFactory = factory
2429
window = MendixReactWindow(frame: UIScreen.main.bounds)
2530
}
2631

@@ -64,3 +69,18 @@ open class ReactAppProvider: UIResponder, UIApplicationDelegate {
6469
return ReactHostHelper().module(forName: name) as? T
6570
}
6671
}
72+
73+
74+
public class ReactNativeDelegate: RCTDefaultReactNativeFactoryDelegate {
75+
public override func sourceURL(for bridge: RCTBridge) -> URL? {
76+
self.bundleURL()
77+
}
78+
79+
public override func bundleURL() -> URL? {
80+
#if DEBUG
81+
RCTBundleURLProvider.sharedSettings().jsBundleURL(forBundleRoot: "index")
82+
#else
83+
Bundle.main.url(forResource: "main", withExtension: "jsbundle")
84+
#endif
85+
}
86+
}

ios/Modules/Helper/ReactHostHelper.mm

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#import "ReactHostHelper.h"
99
#import <ReactCommon/RCTHost.h>
1010
#import <React/RCTReloadCommand.h>
11+
#import "RCTDefaultReactNativeFactoryDelegate.h"
1112
#import "RCTReactNativeFactory.h"
1213
#import "MendixNative-Swift.h"
1314
#import "MxReload.h"

ios/Modules/ReactNative.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import UIKit
22
import React
33

4-
public protocol ReactNativeDelegate: AnyObject {
4+
public protocol ReactNativeDelegateInternal: AnyObject {
55
func onAppClosed()
66
}
77

@@ -13,7 +13,7 @@ open class ReactNative: NSObject, RCTReloadListener {
1313
private var mendixOTAEnabled: Bool = false
1414
private var tapGestureHelper: TapGestureRecognizerHelper?
1515

16-
public weak var delegate: ReactNativeDelegate?
16+
public weak var delegate: ReactNativeDelegateInternal?
1717

1818
// MARK: - Singleton
1919
public static let shared = ReactNative()

0 commit comments

Comments
 (0)