|
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 | +// } |
0 commit comments