Skip to content

Commit 96d6680

Browse files
Robert Balickifacebook-github-bot
Robert Balicki
authored andcommitted
Add iOS + Android support for getting/setting reload-and-profile-related settings
Summary: @public * Add support for getting/setting reload-and-profile-related settings in iOS + Android ## Changelog: [General][Added] - Add support for getting/setting reload-and-profile-related settings in iOS + Android Reviewed By: NickGerleman Differential Revision: D41040611 fbshipit-source-id: df99fb0101dfdfc6808708a5a6ecd9cb96a357d5
1 parent 71399d0 commit 96d6680

File tree

5 files changed

+80
-9
lines changed

5 files changed

+80
-9
lines changed

Libraries/DevToolsSettings/DevToolsSettingsManager.android.js

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,32 @@
44
* This source code is licensed under the MIT license found in the
55
* LICENSE file in the root directory of this source tree.
66
*
7-
* @flow strict
7+
* @flow strict-local
88
* @format
99
*/
1010

11+
import DevSettings from '../Utilities/DevSettings';
1112
import NativeDevToolsSettingsManager from './NativeDevToolsSettingsManager';
1213

13-
module.exports = NativeDevToolsSettingsManager;
14+
module.exports = {
15+
setConsolePatchSettings(newSettings: string) {
16+
NativeDevToolsSettingsManager?.setConsolePatchSettings(newSettings);
17+
},
18+
getConsolePatchSettings(): ?string {
19+
return NativeDevToolsSettingsManager?.getConsolePatchSettings();
20+
},
21+
setProfilingSettings(newSettings: string) {
22+
if (NativeDevToolsSettingsManager?.setProfilingSettings != null) {
23+
NativeDevToolsSettingsManager.setProfilingSettings(newSettings);
24+
}
25+
},
26+
getProfilingSettings(): ?string {
27+
if (NativeDevToolsSettingsManager?.getProfilingSettings != null) {
28+
return NativeDevToolsSettingsManager.getProfilingSettings();
29+
}
30+
return null;
31+
},
32+
reload(): void {
33+
DevSettings?.reload();
34+
},
35+
};
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/**
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*
7+
* @flow strict
8+
* @format
9+
*/
10+
11+
export interface DevToolsSettingsManagerStatic {
12+
reload(): void;
13+
setConsolePatchSettings(newSettings: string): void;
14+
getConsolePatchSettings(): string | null;
15+
setProfilingSettings(newSettings: string): void;
16+
getProfilingSettings(): string | null;
17+
}
18+
19+
export const DevToolsSettingsManager: DevToolsSettingsManagerStatic;
20+
export type DevToolsSettingsManager = DevToolsSettingsManagerStatic;

Libraries/DevToolsSettings/DevToolsSettingsManager.ios.js

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,26 +8,42 @@
88
* @format
99
*/
1010

11-
import type {Spec} from './NativeDevToolsSettingsManager';
12-
1311
import Settings from '../Settings/Settings';
12+
import DevSettings from '../Utilities/DevSettings';
1413

1514
const CONSOLE_PATCH_SETTINGS_KEY = 'ReactDevTools::ConsolePatchSettings';
15+
const PROFILING_SETTINGS_KEY = 'ReactDevTools::ProfilingSettings';
1616

1717
const DevToolsSettingsManager = {
18-
setConsolePatchSettings: (newConsolePatchSettings: string) => {
18+
setConsolePatchSettings(newConsolePatchSettings: string): void {
1919
Settings.set({
2020
[CONSOLE_PATCH_SETTINGS_KEY]: newConsolePatchSettings,
2121
});
2222
},
23-
getConsolePatchSettings: () => {
23+
getConsolePatchSettings(): ?string {
2424
const value = Settings.get(CONSOLE_PATCH_SETTINGS_KEY);
2525
if (typeof value === 'string') {
26-
// $FlowFixMe[unclear-type]
27-
return ((value: any): string);
26+
return value;
2827
}
2928
return null;
3029
},
30+
31+
setProfilingSettings(newProfilingSettings: string): void {
32+
Settings.set({
33+
[PROFILING_SETTINGS_KEY]: newProfilingSettings,
34+
});
35+
},
36+
getProfilingSettings(): ?string {
37+
const value = Settings.get(PROFILING_SETTINGS_KEY);
38+
if (typeof value === 'string') {
39+
return value;
40+
}
41+
return null;
42+
},
43+
44+
reload(): void {
45+
DevSettings?.reload();
46+
},
3147
};
3248

33-
module.exports = (DevToolsSettingsManager: Spec);
49+
module.exports = DevToolsSettingsManager;

Libraries/DevToolsSettings/NativeDevToolsSettingsManager.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ import * as TurboModuleRegistry from '../TurboModule/TurboModuleRegistry';
1515
export interface Spec extends TurboModule {
1616
+setConsolePatchSettings: (newConsolePatchSettings: string) => void;
1717
+getConsolePatchSettings: () => ?string;
18+
+setProfilingSettings?: (newProfilingSettings: string) => void;
19+
+getProfilingSettings?: () => ?string;
1820
}
1921

2022
export default (TurboModuleRegistry.get<Spec>(

ReactAndroid/src/main/java/com/facebook/react/modules/devtoolssettings/DevToolsSettingsManagerModule.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ public class DevToolsSettingsManagerModule extends NativeDevToolsSettingsManager
2121

2222
private static final String SHARED_PREFERENCES_PREFIX = "ReactNative__DevToolsSettings";
2323
private static final String KEY_CONSOLE_PATCH_SETTINGS = "ConsolePatchSettings";
24+
private static final String KEY_PROFILING_SETTINGS = "ProfilingSettings";
2425

2526
private final SharedPreferences mSharedPreferences;
2627

@@ -46,4 +47,14 @@ public void setConsolePatchSettings(String newSettings) {
4647
editor.putString(KEY_CONSOLE_PATCH_SETTINGS, newSettings);
4748
editor.apply();
4849
}
50+
51+
@Override
52+
public @Nullable String getProfilingSettings() {
53+
return mSharedPreferences.getString(KEY_PROFILING_SETTINGS, null);
54+
}
55+
56+
@Override
57+
public void setProfilingSettings(String newSettings) {
58+
mSharedPreferences.edit().putString(KEY_PROFILING_SETTINGS, newSettings).apply();
59+
}
4960
}

0 commit comments

Comments
 (0)