Skip to content

Commit 7335246

Browse files
refactor: update DevHelper and ReactHostHelper for improved module access and remove unused code
1 parent e2f48cc commit 7335246

8 files changed

Lines changed: 33 additions & 81 deletions

File tree

ios/Modules/Helper/DevHelper.swift

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,17 @@ public class DevHelper {
77
}
88

99
public static func setShakeToShowDevMenuEnabled(enabled: Bool) {
10-
ReactHostHelper().emitEvent("mendixSetShakeToShowDevMenu", payload: enabled)
10+
getModule(type: RCTDevSettings.self)?.isShakeToShowDevMenuEnabled = enabled
11+
12+
// This event can be triggered to facilitate communication with the DevSettings JS module. Please refer to dev-settings.ts for further details.
13+
// ReactHostHelper().emitEvent("mendixSetShakeToShowDevMenu", payload: enabled)
14+
}
15+
16+
public static func hideDevLoadingView() {
17+
getModule(type: RCTDevLoadingView.self)?.hide()
18+
}
19+
20+
public static func getModule<T: NSObject>(type: T.Type) -> T? {
21+
return ReactHostHelper().module(for: T.self) as? T
1122
}
1223
}

ios/Modules/Helper/ReactAppProvider.swift

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,6 @@ open class ReactAppProvider: UIResponder, UIApplicationDelegate {
7070
public static func isReactAppActive() -> Bool {
7171
return ReactHostHelper().isReactAppActive()
7272
}
73-
74-
public static func getModule<T: NSObject>(name:String, type: T.Type) -> T? {
75-
return ReactHostHelper().module(forName: name) as? T
76-
}
7773
}
7874

7975

ios/Modules/Helper/ReactHostHelper.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ NS_ASSUME_NONNULL_BEGIN
1111

1212
@interface ReactHostHelper : NSObject
1313

14-
- (nullable id) moduleForName: (NSString *) name;
14+
- (nullable id) moduleForClass: (Class) clazz;
1515
- (void) reloadClientWithState;
1616
- (BOOL) isReactAppActive;
1717
- (void) emitEvent: (nonnull NSString*) eventName payload: (nullable id) payload;

ios/Modules/Helper/ReactHostHelper.mm

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,22 @@
1717

1818
@implementation ReactHostHelper
1919

20-
- (nullable id)moduleForName:(nonnull NSString*)name {
20+
- (nullable id) moduleForClass: (Class) clazz {
2121
if ([NSThread isMainThread]) {
22-
return [self getModuleForName: name];
22+
return [self getModuleForClass: clazz];
2323
} else {
2424
__block id result;
2525
dispatch_sync(dispatch_get_main_queue(), ^{
26-
result = [self getModuleForName: name];
26+
result = [self getModuleForClass: clazz];
2727
});
2828
return result;
2929
}
3030
}
3131

32-
- (nullable id) getModuleForName:(nonnull NSString*)name {
32+
- (nullable id) getModuleForClass: (Class) clazz {
3333
RCTHost *reactHost = [self currentHost];
3434
RCTModuleRegistry *moduleRegistry = [reactHost moduleRegistry];
35-
id nativeModule = [moduleRegistry moduleForName: name.UTF8String];
35+
id nativeModule = [moduleRegistry moduleForClass: clazz];
3636
return nativeModule;
3737
}
3838

@@ -46,7 +46,7 @@ - (RCTHost *) currentHost {
4646

4747

4848
- (void) reloadClientWithState {
49-
MxReload *mxReload = [self moduleForName: MxReload.moduleName];
49+
MxReload *mxReload = [self moduleForClass: MxReload.class];
5050
[mxReload emitOnReloadWithState];
5151
}
5252

ios/Modules/NativeFsModule/NativeFsModule.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public class NativeFsModule: NSObject {
2525
}
2626

2727
private func getBlobManager() -> RCTBlobManager? {
28-
guard let blobManager: RCTBlobManager = ReactAppProvider.getModule(name: RCTBlobManager.moduleName(), type: RCTBlobManager.self) else {
28+
guard let blobManager: RCTBlobManager = DevHelper.getModule(type: RCTBlobManager.self) else {
2929
NSLog("NativeFsModule: Failed to get RCTBlobManager")
3030
return nil
3131
}

ios/Modules/ReactNative.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ open class ReactNative: NSObject, RCTReloadListener {
7575

7676
public func hideSplashScreen() {
7777
mendixApp?.splashScreenPresenter?.hide()
78+
DevHelper.hideDevLoadingView()
7879
}
7980

8081
// MARK: - Reload Methods

src/dev-settings.ts

Lines changed: 12 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,12 @@
1-
import { DeviceEventEmitter, NativeModules, Platform } from 'react-native';
2-
3-
const NativeDevSettings = NativeModules.DevSettings;
4-
5-
// Listen for native-to-JS calls to control shake gesture.
6-
// In RN 0.84+ bridgeless mode, native cannot directly set this on RCTDevSettings
7-
// because the TurboModule instance isn't accessible via moduleForName. Instead,
8-
// native uses RCTHost.callFunctionOnJSModule to emit this event.
9-
if (__DEV__ && Platform.OS === 'ios') {
10-
DeviceEventEmitter.addListener(
11-
'mendixSetShakeToShowDevMenu',
12-
(enabled: boolean) => {
13-
NativeDevSettings?.setIsShakeToShowDevMenuEnabled?.(enabled);
14-
}
15-
);
16-
}
17-
18-
export const DevSettings = {
19-
openDebugger(): void {
20-
if (!__DEV__) return;
21-
NativeDevSettings?.openDebugger?.();
22-
},
23-
24-
toggleElementInspector(): void {
25-
if (!__DEV__) return;
26-
27-
NativeDevSettings?.toggleElementInspector?.();
28-
},
29-
30-
reload(reason?: string): void {
31-
if (!__DEV__) return;
32-
if (NativeDevSettings?.reloadWithReason) {
33-
NativeDevSettings.reloadWithReason(reason ?? 'Manual reload from JS');
34-
} else if (NativeDevSettings?.reload) {
35-
NativeDevSettings.reload();
36-
}
37-
},
38-
39-
setHotLoadingEnabled(enabled: boolean): void {
40-
if (__DEV__ && NativeDevSettings?.setHotLoadingEnabled) {
41-
NativeDevSettings.setHotLoadingEnabled(enabled);
42-
}
43-
},
44-
45-
setProfilingEnabled(enabled: boolean): void {
46-
if (__DEV__ && NativeDevSettings?.setProfilingEnabled) {
47-
NativeDevSettings.setProfilingEnabled(enabled);
48-
}
49-
},
50-
51-
setShakeToShowDevMenuEnabled(enabled: boolean): void {
52-
if (
53-
__DEV__ &&
54-
Platform.OS === 'ios' &&
55-
NativeDevSettings?.setIsShakeToShowDevMenuEnabled
56-
) {
57-
NativeDevSettings.setIsShakeToShowDevMenuEnabled(enabled);
58-
}
59-
},
60-
61-
addMenuItem(title: string, _handler: () => void): void {
62-
if (__DEV__ && NativeDevSettings?.addMenuItem) {
63-
NativeDevSettings.addMenuItem(title);
64-
// Note: Event listener setup would need NativeEventEmitter
65-
}
66-
},
67-
};
1+
// Listen for native-to-JS calls to control the shake gesture.
2+
// If the native layer cannot update RCTDevSettings directly,
3+
// enable a listener and use RCTHost.callFunctionOnJSModule to emit the event.
4+
// This pattern can also apply to other methods.
5+
// if (__DEV__ && Platform.OS === 'ios') {
6+
// DeviceEventEmitter.addListener(
7+
// 'mendixSetShakeToShowDevMenu',
8+
// (enabled: boolean) => {
9+
// NativeDevSettings?.setIsShakeToShowDevMenuEnabled?.(enabled);
10+
// }
11+
// );
12+
// }

src/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,3 @@ export * from './encrypted-storage';
1010
export * from './error';
1111
export * from './file-system';
1212
export * from './navigation-mode';
13-
export * from './dev-settings';

0 commit comments

Comments
 (0)