mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
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
This commit is contained in:
committed by
Facebook GitHub Bot
parent
71399d0891
commit
96d6680e00
@@ -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();
|
||||
},
|
||||
};
|
||||
|
||||
@@ -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;
|
||||
@@ -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;
|
||||
|
||||
@@ -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>(
|
||||
|
||||
+11
@@ -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;
|
||||
|
||||
@@ -46,4 +47,14 @@ public class DevToolsSettingsManagerModule extends NativeDevToolsSettingsManager
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user