Skip to content

Commit

Permalink
Add iOS + Android support for getting/setting reload-and-profile-rela…
Browse files Browse the repository at this point in the history
…ted 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
  • Loading branch information
Robert Balicki authored and facebook-github-bot committed Dec 6, 2022
1 parent 71399d0 commit 96d6680
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 9 deletions.
26 changes: 24 additions & 2 deletions Libraries/DevToolsSettings/DevToolsSettingsManager.android.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,32 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow strict
* @flow strict-local
* @format
*/

import DevSettings from '../Utilities/DevSettings';
import NativeDevToolsSettingsManager from './NativeDevToolsSettingsManager';

module.exports = NativeDevToolsSettingsManager;
module.exports = {
setConsolePatchSettings(newSettings: string) {
NativeDevToolsSettingsManager?.setConsolePatchSettings(newSettings);
},
getConsolePatchSettings(): ?string {
return NativeDevToolsSettingsManager?.getConsolePatchSettings();
},
setProfilingSettings(newSettings: string) {
if (NativeDevToolsSettingsManager?.setProfilingSettings != null) {
NativeDevToolsSettingsManager.setProfilingSettings(newSettings);
}
},
getProfilingSettings(): ?string {
if (NativeDevToolsSettingsManager?.getProfilingSettings != null) {
return NativeDevToolsSettingsManager.getProfilingSettings();
}
return null;
},
reload(): void {
DevSettings?.reload();
},
};
20 changes: 20 additions & 0 deletions Libraries/DevToolsSettings/DevToolsSettingsManager.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow strict
* @format
*/

export interface DevToolsSettingsManagerStatic {
reload(): void;
setConsolePatchSettings(newSettings: string): void;
getConsolePatchSettings(): string | null;
setProfilingSettings(newSettings: string): void;
getProfilingSettings(): string | null;
}

export const DevToolsSettingsManager: DevToolsSettingsManagerStatic;
export type DevToolsSettingsManager = DevToolsSettingsManagerStatic;
30 changes: 23 additions & 7 deletions Libraries/DevToolsSettings/DevToolsSettingsManager.ios.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,42 @@
* @format
*/

import type {Spec} from './NativeDevToolsSettingsManager';

import Settings from '../Settings/Settings';
import DevSettings from '../Utilities/DevSettings';

const CONSOLE_PATCH_SETTINGS_KEY = 'ReactDevTools::ConsolePatchSettings';
const PROFILING_SETTINGS_KEY = 'ReactDevTools::ProfilingSettings';

const DevToolsSettingsManager = {
setConsolePatchSettings: (newConsolePatchSettings: string) => {
setConsolePatchSettings(newConsolePatchSettings: string): void {
Settings.set({
[CONSOLE_PATCH_SETTINGS_KEY]: newConsolePatchSettings,
});
},
getConsolePatchSettings: () => {
getConsolePatchSettings(): ?string {
const value = Settings.get(CONSOLE_PATCH_SETTINGS_KEY);
if (typeof value === 'string') {
// $FlowFixMe[unclear-type]
return ((value: any): string);
return value;
}
return null;
},

setProfilingSettings(newProfilingSettings: string): void {
Settings.set({
[PROFILING_SETTINGS_KEY]: newProfilingSettings,
});
},
getProfilingSettings(): ?string {
const value = Settings.get(PROFILING_SETTINGS_KEY);
if (typeof value === 'string') {
return value;
}
return null;
},

reload(): void {
DevSettings?.reload();
},
};

module.exports = (DevToolsSettingsManager: Spec);
module.exports = DevToolsSettingsManager;
2 changes: 2 additions & 0 deletions Libraries/DevToolsSettings/NativeDevToolsSettingsManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import * as TurboModuleRegistry from '../TurboModule/TurboModuleRegistry';
export interface Spec extends TurboModule {
+setConsolePatchSettings: (newConsolePatchSettings: string) => void;
+getConsolePatchSettings: () => ?string;
+setProfilingSettings?: (newProfilingSettings: string) => void;
+getProfilingSettings?: () => ?string;
}

export default (TurboModuleRegistry.get<Spec>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public class DevToolsSettingsManagerModule extends NativeDevToolsSettingsManager

private static final String SHARED_PREFERENCES_PREFIX = "ReactNative__DevToolsSettings";
private static final String KEY_CONSOLE_PATCH_SETTINGS = "ConsolePatchSettings";
private static final String KEY_PROFILING_SETTINGS = "ProfilingSettings";

private final SharedPreferences mSharedPreferences;

Expand All @@ -46,4 +47,14 @@ public void setConsolePatchSettings(String newSettings) {
editor.putString(KEY_CONSOLE_PATCH_SETTINGS, newSettings);
editor.apply();
}

@Override
public @Nullable String getProfilingSettings() {
return mSharedPreferences.getString(KEY_PROFILING_SETTINGS, null);
}

@Override
public void setProfilingSettings(String newSettings) {
mSharedPreferences.edit().putString(KEY_PROFILING_SETTINGS, newSettings).apply();
}
}

0 comments on commit 96d6680

Please sign in to comment.