Skip to content

Commit d181c65

Browse files
chore: refactor
1 parent 90dbf39 commit d181c65

30 files changed

Lines changed: 380 additions & 518 deletions

MendixNative.podspec

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

2020
s.dependency "SSZipArchive"
2121
s.dependency "RNCAsyncStorage"
22+
s.dependency "ReactCommon"
23+
s.dependency "ReactAppDependencyProvider"
24+
s.dependency 'React-Core'
25+
s.dependency 'React-RCTAppDelegate'
2226

2327
install_modules_dependencies(s)
2428
end
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
//
2+
// Use this file to import your target's public headers that you would like to expose to Swift.
3+
//

example/ios/MendixNativeExample.xcodeproj/project.pbxproj

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
objects = {
88

99
/* Begin PBXBuildFile section */
10-
0C80B921A6F3F58F76C31292 /* libPods-MendixNativeExample.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 5DCACB8F33CDC322A6C60F78 /* libPods-MendixNativeExample.a */; };
1110
13B07FBF1A68108700A75B9A /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 13B07FB51A68108700A75B9A /* Images.xcassets */; };
11+
1499ABBDB7935B67C3951198 /* libPods-MendixNativeExample.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 24A5FB93E78C6A91516539F4 /* libPods-MendixNativeExample.a */; };
1212
761780ED2CA45674006654EE /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 761780EC2CA45674006654EE /* AppDelegate.swift */; };
1313
81AB9BB82411601600AC10FF /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 81AB9BB72411601600AC10FF /* LaunchScreen.storyboard */; };
1414
E7824D7967CD7EE7C8E76686 /* PrivacyInfo.xcprivacy in Resources */ = {isa = PBXBuildFile; fileRef = 13B07FB81A68108700A75B9A /* PrivacyInfo.xcprivacy */; };
@@ -19,11 +19,12 @@
1919
13B07FB51A68108700A75B9A /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; name = Images.xcassets; path = MendixNativeExample/Images.xcassets; sourceTree = "<group>"; };
2020
13B07FB61A68108700A75B9A /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = Info.plist; path = MendixNativeExample/Info.plist; sourceTree = "<group>"; };
2121
13B07FB81A68108700A75B9A /* PrivacyInfo.xcprivacy */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = PrivacyInfo.xcprivacy; path = MendixNativeExample/PrivacyInfo.xcprivacy; sourceTree = "<group>"; };
22-
3B4392A12AC88292D35C810B /* Pods-MendixNativeExample.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-MendixNativeExample.debug.xcconfig"; path = "Target Support Files/Pods-MendixNativeExample/Pods-MendixNativeExample.debug.xcconfig"; sourceTree = "<group>"; };
23-
5709B34CF0A7D63546082F79 /* Pods-MendixNativeExample.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-MendixNativeExample.release.xcconfig"; path = "Target Support Files/Pods-MendixNativeExample/Pods-MendixNativeExample.release.xcconfig"; sourceTree = "<group>"; };
24-
5DCACB8F33CDC322A6C60F78 /* libPods-MendixNativeExample.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-MendixNativeExample.a"; sourceTree = BUILT_PRODUCTS_DIR; };
22+
24A5FB93E78C6A91516539F4 /* libPods-MendixNativeExample.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-MendixNativeExample.a"; sourceTree = BUILT_PRODUCTS_DIR; };
23+
503B3921D3702B3C7DF3D941 /* Pods-MendixNativeExample.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-MendixNativeExample.release.xcconfig"; path = "Target Support Files/Pods-MendixNativeExample/Pods-MendixNativeExample.release.xcconfig"; sourceTree = "<group>"; };
2524
761780EC2CA45674006654EE /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = AppDelegate.swift; path = MendixNativeExample/AppDelegate.swift; sourceTree = "<group>"; };
2625
81AB9BB72411601600AC10FF /* LaunchScreen.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; name = LaunchScreen.storyboard; path = MendixNativeExample/LaunchScreen.storyboard; sourceTree = "<group>"; };
26+
9EF6D8952E93D80B00BFE8AE /* MendixNativeExample-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "MendixNativeExample-Bridging-Header.h"; sourceTree = "<group>"; };
27+
DC6440C7A3C29FAC4633A591 /* Pods-MendixNativeExample.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-MendixNativeExample.debug.xcconfig"; path = "Target Support Files/Pods-MendixNativeExample/Pods-MendixNativeExample.debug.xcconfig"; sourceTree = "<group>"; };
2728
ED297162215061F000B7C4FE /* JavaScriptCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = JavaScriptCore.framework; path = System/Library/Frameworks/JavaScriptCore.framework; sourceTree = SDKROOT; };
2829
/* End PBXFileReference section */
2930

@@ -32,7 +33,7 @@
3233
isa = PBXFrameworksBuildPhase;
3334
buildActionMask = 2147483647;
3435
files = (
35-
0C80B921A6F3F58F76C31292 /* libPods-MendixNativeExample.a in Frameworks */,
36+
1499ABBDB7935B67C3951198 /* libPods-MendixNativeExample.a in Frameworks */,
3637
);
3738
runOnlyForDeploymentPostprocessing = 0;
3839
};
@@ -47,6 +48,7 @@
4748
13B07FB61A68108700A75B9A /* Info.plist */,
4849
81AB9BB72411601600AC10FF /* LaunchScreen.storyboard */,
4950
13B07FB81A68108700A75B9A /* PrivacyInfo.xcprivacy */,
51+
9EF6D8952E93D80B00BFE8AE /* MendixNativeExample-Bridging-Header.h */,
5052
);
5153
name = MendixNativeExample;
5254
sourceTree = "<group>";
@@ -55,7 +57,7 @@
5557
isa = PBXGroup;
5658
children = (
5759
ED297162215061F000B7C4FE /* JavaScriptCore.framework */,
58-
5DCACB8F33CDC322A6C60F78 /* libPods-MendixNativeExample.a */,
60+
24A5FB93E78C6A91516539F4 /* libPods-MendixNativeExample.a */,
5961
);
6062
name = Frameworks;
6163
sourceTree = "<group>";
@@ -92,8 +94,8 @@
9294
BBD78D7AC51CEA395F1C20DB /* Pods */ = {
9395
isa = PBXGroup;
9496
children = (
95-
3B4392A12AC88292D35C810B /* Pods-MendixNativeExample.debug.xcconfig */,
96-
5709B34CF0A7D63546082F79 /* Pods-MendixNativeExample.release.xcconfig */,
97+
DC6440C7A3C29FAC4633A591 /* Pods-MendixNativeExample.debug.xcconfig */,
98+
503B3921D3702B3C7DF3D941 /* Pods-MendixNativeExample.release.xcconfig */,
9799
);
98100
path = Pods;
99101
sourceTree = "<group>";
@@ -105,13 +107,13 @@
105107
isa = PBXNativeTarget;
106108
buildConfigurationList = 13B07F931A680F5B00A75B9A /* Build configuration list for PBXNativeTarget "MendixNativeExample" */;
107109
buildPhases = (
108-
C38B50BA6285516D6DCD4F65 /* [CP] Check Pods Manifest.lock */,
110+
6485E27ECADDCAC2E38CAB7F /* [CP] Check Pods Manifest.lock */,
109111
13B07F871A680F5B00A75B9A /* Sources */,
110112
13B07F8C1A680F5B00A75B9A /* Frameworks */,
111113
13B07F8E1A680F5B00A75B9A /* Resources */,
112114
00DD1BFF1BD5951E006B06BC /* Bundle React Native code and images */,
113-
00EEFC60759A1932668264C0 /* [CP] Embed Pods Frameworks */,
114-
E235C05ADACE081382539298 /* [CP] Copy Pods Resources */,
115+
438F33F76347F781AFF016DC /* [CP] Embed Pods Frameworks */,
116+
A55576AF4B0F3C02C0E7F7B4 /* [CP] Copy Pods Resources */,
115117
);
116118
buildRules = (
117119
);
@@ -183,7 +185,7 @@
183185
shellPath = /bin/sh;
184186
shellScript = "set -e\n\nWITH_ENVIRONMENT=\"$REACT_NATIVE_PATH/scripts/xcode/with-environment.sh\"\nREACT_NATIVE_XCODE=\"$REACT_NATIVE_PATH/scripts/react-native-xcode.sh\"\n\n/bin/sh -c \"$WITH_ENVIRONMENT $REACT_NATIVE_XCODE\"\n";
185187
};
186-
00EEFC60759A1932668264C0 /* [CP] Embed Pods Frameworks */ = {
188+
438F33F76347F781AFF016DC /* [CP] Embed Pods Frameworks */ = {
187189
isa = PBXShellScriptBuildPhase;
188190
buildActionMask = 2147483647;
189191
files = (
@@ -200,7 +202,7 @@
200202
shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-MendixNativeExample/Pods-MendixNativeExample-frameworks.sh\"\n";
201203
showEnvVarsInLog = 0;
202204
};
203-
C38B50BA6285516D6DCD4F65 /* [CP] Check Pods Manifest.lock */ = {
205+
6485E27ECADDCAC2E38CAB7F /* [CP] Check Pods Manifest.lock */ = {
204206
isa = PBXShellScriptBuildPhase;
205207
buildActionMask = 2147483647;
206208
files = (
@@ -222,7 +224,7 @@
222224
shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n";
223225
showEnvVarsInLog = 0;
224226
};
225-
E235C05ADACE081382539298 /* [CP] Copy Pods Resources */ = {
227+
A55576AF4B0F3C02C0E7F7B4 /* [CP] Copy Pods Resources */ = {
226228
isa = PBXShellScriptBuildPhase;
227229
buildActionMask = 2147483647;
228230
files = (
@@ -255,7 +257,7 @@
255257
/* Begin XCBuildConfiguration section */
256258
13B07F941A680F5B00A75B9A /* Debug */ = {
257259
isa = XCBuildConfiguration;
258-
baseConfigurationReference = 3B4392A12AC88292D35C810B /* Pods-MendixNativeExample.debug.xcconfig */;
260+
baseConfigurationReference = DC6440C7A3C29FAC4633A591 /* Pods-MendixNativeExample.debug.xcconfig */;
259261
buildSettings = {
260262
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
261263
CLANG_ENABLE_MODULES = YES;
@@ -275,6 +277,7 @@
275277
);
276278
PRODUCT_BUNDLE_IDENTIFIER = mendixnative.example;
277279
PRODUCT_NAME = MendixNativeExample;
280+
SWIFT_OBJC_BRIDGING_HEADER = "MendixNativeExample-Bridging-Header.h";
278281
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
279282
SWIFT_VERSION = 5.0;
280283
VERSIONING_SYSTEM = "apple-generic";
@@ -283,7 +286,7 @@
283286
};
284287
13B07F951A680F5B00A75B9A /* Release */ = {
285288
isa = XCBuildConfiguration;
286-
baseConfigurationReference = 5709B34CF0A7D63546082F79 /* Pods-MendixNativeExample.release.xcconfig */;
289+
baseConfigurationReference = 503B3921D3702B3C7DF3D941 /* Pods-MendixNativeExample.release.xcconfig */;
287290
buildSettings = {
288291
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
289292
CLANG_ENABLE_MODULES = YES;
@@ -302,6 +305,7 @@
302305
);
303306
PRODUCT_BUNDLE_IDENTIFIER = mendixnative.example;
304307
PRODUCT_NAME = MendixNativeExample;
308+
SWIFT_OBJC_BRIDGING_HEADER = "MendixNativeExample-Bridging-Header.h";
305309
SWIFT_VERSION = 5.0;
306310
VERSIONING_SYSTEM = "apple-generic";
307311
};
Lines changed: 37 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,43 @@
11
import UIKit
22
import React
3-
import React_RCTAppDelegate
4-
import ReactAppDependencyProvider
3+
import MendixNative
54

65
@main
7-
class AppDelegate: RCTAppDelegate {
8-
override func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
9-
self.moduleName = "MendixNativeExample"
10-
self.dependencyProvider = RCTAppDependencyProvider()
11-
12-
// You can add your custom initial props in the dictionary below.
13-
// They will be passed down to the ViewController used by React Native.
14-
self.initialProps = [:]
15-
16-
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
17-
}
18-
override func sourceURL(for bridge: RCTBridge) -> URL? {
19-
self.bundleURL()
20-
}
6+
class AppDelegate: ReactNative {
7+
override func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
8+
super.application(application, didFinishLaunchingWithOptions: launchOptions)
9+
changeRoot(to: Home())
10+
return true
11+
}
12+
}
2113

22-
override func bundleURL() -> URL? {
23-
#if DEBUG
24-
RCTBundleURLProvider.sharedSettings().jsBundleURL(forBundleRoot: "index")
25-
#else
26-
Bundle.main.url(forResource: "main", withExtension: "jsbundle")
27-
#endif
28-
}
14+
class Home: UIViewController {
15+
16+
lazy var button: UIButton = {
17+
let button = UIButton(type: .system)
18+
button.setTitle("Open React App", for: .normal)
19+
button.translatesAutoresizingMaskIntoConstraints = false
20+
button.addTarget(self, action: #selector(openApp), for: .touchUpInside)
21+
return button
22+
}()
23+
24+
override func viewDidLoad() {
25+
super.viewDidLoad()
26+
view.backgroundColor = .white
27+
view.addSubview(button)
28+
NSLayoutConstraint.activate([
29+
button.centerXAnchor.constraint(equalTo: view.centerXAnchor),
30+
button.centerYAnchor.constraint(equalTo: view.centerYAnchor)
31+
])
32+
}
33+
34+
@objc func openApp() {
35+
guard let appDelegate = UIApplication.shared.delegate as? AppDelegate else {
36+
return
37+
}
38+
let reactRootView = appDelegate.rootViewFactory.view(withModuleName: "MendixNativeExample")
39+
let controller = UIViewController()
40+
controller.view = reactRootView
41+
appDelegate.changeRoot(to: controller)
42+
}
2943
}

example/ios/Podfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ target 'MendixNativeExample' do
2222
use_react_native!(
2323
:path => config[:reactNativePath],
2424
# An absolute path to your application root.
25+
:hermes_enabled => true,
26+
:fabric_enabled => true,
2527
:app_path => "#{Pod::Config.instance.installation_root}/.."
2628
)
2729

example/ios/Podfile.lock

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,16 @@ PODS:
2222
- React-graphics
2323
- React-ImageManager
2424
- React-NativeModulesApple
25+
- React-RCTAppDelegate
2526
- React-RCTFabric
2627
- React-rendererdebug
2728
- React-utils
29+
- ReactAppDependencyProvider
2830
- ReactCodegen
31+
- ReactCommon
2932
- ReactCommon/turbomodule/bridging
3033
- ReactCommon/turbomodule/core
34+
- RNCAsyncStorage
3135
- SSZipArchive
3236
- Yoga
3337
- op-sqlite (12.0.2):
@@ -1823,7 +1827,7 @@ SPEC CHECKSUMS:
18231827
fmt: a40bb5bd0294ea969aaaba240a927bd33d878cdd
18241828
glog: eb93e2f488219332457c3c4eafd2738ddc7e80b8
18251829
hermes-engine: b2187dbe13edb0db8fcb2a93a69c1987a30d98a4
1826-
MendixNative: a5754dd55001ed5e15e2c9ff5442e9560faae14a
1830+
MendixNative: d76c461cfe93066190b9f1c21d01a4960e1f7ce2
18271831
op-sqlite: f364fb409143a1194b76909630c050c6e91245e9
18281832
OpenSSL-Universal: 6082b0bf950e5636fe0d78def171184e2b3899c2
18291833
RCT-Folly: e78785aa9ba2ed998ea4151e314036f6c49e6d82
@@ -1890,6 +1894,6 @@ SPEC CHECKSUMS:
18901894
SSZipArchive: fe6a26b2a54d5a0890f2567b5cc6de5caa600aef
18911895
Yoga: 92f3bb322c40a86b7233b815854730442e01b8c4
18921896

1893-
PODFILE CHECKSUM: efbfead38c8c78e490c24507177559908b58ea70
1897+
PODFILE CHECKSUM: 3b9697ad784d7513a2d48765f6c9260a3ca3a4ff
18941898

18951899
COCOAPODS: 1.15.2

example/src/App.tsx

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,6 @@
1-
import { Text, View, StyleSheet, Button, Alert } from 'react-native';
2-
import {
3-
NativeReloadHandler,
4-
NativeCookie,
5-
onReloadWithStateEvent,
6-
} from 'mendix-native';
7-
import { useEffect } from 'react';
1+
import { Text, View, StyleSheet } from 'react-native';
82

93
export default function App() {
10-
useEffect(() => {
11-
const subscription = onReloadWithStateEvent(() =>
12-
Alert.alert('Reload event received on JS end')
13-
);
14-
15-
return () => {
16-
subscription.remove();
17-
};
18-
}, []);
19-
204
const runtime = (global as any).nativeFabricUIManager
215
? 'New Architecture'
226
: 'Legacy Architecture';
@@ -26,9 +10,6 @@ export default function App() {
2610
<View style={styles.archContainer}>
2711
<Text style={styles.text}>{runtime}</Text>
2812
</View>
29-
<Button title="Exit App" onPress={() => NativeReloadHandler.exitApp()} />
30-
<Button title="Reload App" onPress={() => NativeReloadHandler.reload()} />
31-
<Button title="Clear Cookies" onPress={() => NativeCookie.clearAll()} />
3213
</View>
3314
);
3415
}
@@ -40,9 +21,6 @@ const styles = StyleSheet.create({
4021
justifyContent: 'center',
4122
},
4223
archContainer: {
43-
position: 'absolute',
44-
top: 65,
45-
right: 20,
4624
padding: 10,
4725
borderRadius: 8,
4826
backgroundColor: '#eee',

ios/MendixNative.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#import <MendixNativeSpec/MendixNativeSpec.h>
22
#import <React/RCTReloadCommand.h>
33
#import "RNCAsyncStorage.h"
4+
#import "RCTAppDelegate.h"
45

56
@interface MendixNative : NativeMendixNativeSpecBase <NativeMendixNativeSpec>
67
- (void)reloadClientWithState;

ios/MendixNative.mm

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ - (void)encryptedStorageRemoveItem:(nonnull NSString *)key resolve:(nonnull RCTP
2727
}
2828

2929
- (void)encryptedStorageClear:(nonnull RCTPromiseResolveBlock)resolve reject:(nonnull RCTPromiseRejectBlock)reject {
30-
[[[EncryptedStorage alloc] init] clearWithResolve:resolve reject:reject];
30+
Promise *promise = [[Promise alloc] initWithResolve:resolve reject:reject];
31+
[[[EncryptedStorage alloc] init] clearWithPromise:promise];
3132
}
3233

3334
- (nonnull NSNumber *)encryptedStorageIsEncrypted {
@@ -135,4 +136,9 @@ - (void)errorHandlerHandle:(nonnull NSString *)message stackTrace:(nonnull NSArr
135136
[[[NativeErrorHandler alloc] init] handleWithMessage:message stackTrace:stackTrace];
136137
}
137138

139+
- (void)fsReadAsText:(nonnull NSString *)filePath resolve:(nonnull RCTPromiseResolveBlock)resolve reject:(nonnull RCTPromiseRejectBlock)reject {
140+
reject(@"NOT_SPPORTED", @"Read as text is not supported on iOS", nil);
141+
}
142+
143+
138144
@end

ios/Modules/AppPreferences/AppPreferences.swift

Lines changed: 4 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -24,39 +24,15 @@ public class AppPreferences: NSObject {
2424
_packagerPort = newValue
2525
}
2626
}
27-
27+
2828
public static var appUrl = _appUrl
2929
public static var devModeEnabled = _devModeEnabled
3030
public static var remoteDebuggingEnabled = _remoteDebuggingEnabled
3131
public static var elementInspectorEnabled = _elementInspectorEnabled
32-
32+
3333
public static var safeAppUrl: String {
34-
return appUrl ?? ""
35-
}
36-
37-
}
38-
39-
//TODO: Move to separate file
40-
@propertyWrapper
41-
struct UserDefault<T> {
42-
let key: String
43-
let defaultValue: T
44-
let container: UserDefaults
45-
46-
init(key: String, defaultValue: T, container: UserDefaults = .standard) {
47-
self.key = key
48-
self.defaultValue = defaultValue
49-
self.container = container
50-
}
51-
52-
var wrappedValue: T {
53-
get {
54-
return container.object(forKey: key) as? T ?? defaultValue
55-
}
56-
set {
57-
container.set(newValue, forKey: key)
58-
}
34+
return appUrl ?? ""
5935
}
36+
6037
}
61-
6238
//Checked

0 commit comments

Comments
 (0)