forked from facebook/react-native
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Buck, etc. changes that enable persisted, sync settings for DevTools (f…
…acebook#35163) Summary: Pull Request resolved: facebook#35163 # What This diff contains all the changes from D40333083 (facebook@0fac981) (aka facebook#34964), **except** the change to `setUpReactDevTools.js`, which actually uses the new files. # Why * We want to ship the Buck, C++, etc. changes before the JavaScript changes that depend on those files. * Otherwise, apps can fail at startup with the message: ``` `TurboModuleRegistry.getEnforcing(...): '${name}' could not be found. ` + 'Verify that a module by this name is registered in the native binary.', ``` * Note that this only occurs if you are using a previously-built version of the C++, Obj C, etc. files in RN, but a more recent version of the JavaScript files. If you are building from matching sources, this does not occur. * After a few days, we can land the JS files. ## Changelog Changelog [General][Added] Add, but don't use, DevTools Settings Manager. Reviewed By: NickGerleman Differential Revision: D40873390 fbshipit-source-id: c7bac6ae65f85666b8616443db278ebb175b691b
- Loading branch information
1 parent
ee1fb6f
commit 55657c1
Showing
10 changed files
with
155 additions
and
1 deletion.
There are no files selected for viewing
13 changes: 13 additions & 0 deletions
13
Libraries/DevToolsSettings/DevToolsSettingsManager.android.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/** | ||
* 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 | ||
*/ | ||
|
||
import NativeDevToolsSettingsManager from './NativeDevToolsSettingsManager'; | ||
|
||
module.exports = NativeDevToolsSettingsManager; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/** | ||
* 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-local | ||
* @format | ||
*/ | ||
|
||
import type {Spec} from './NativeDevToolsSettingsManager'; | ||
|
||
import Settings from '../Settings/Settings'; | ||
|
||
const CONSOLE_PATCH_SETTINGS_KEY = 'ReactDevTools::ConsolePatchSettings'; | ||
|
||
const DevToolsSettingsManager = { | ||
setConsolePatchSettings: (newConsolePatchSettings: string) => { | ||
Settings.set({ | ||
[CONSOLE_PATCH_SETTINGS_KEY]: newConsolePatchSettings, | ||
}); | ||
}, | ||
getConsolePatchSettings: () => { | ||
const value = Settings.get(CONSOLE_PATCH_SETTINGS_KEY); | ||
if (typeof value === 'string') { | ||
// $FlowFixMe[unclear-type] | ||
return ((value: any): string); | ||
} | ||
return null; | ||
}, | ||
}; | ||
|
||
module.exports = (DevToolsSettingsManager: Spec); |
22 changes: 22 additions & 0 deletions
22
Libraries/DevToolsSettings/NativeDevToolsSettingsManager.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/** | ||
* 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 | ||
*/ | ||
|
||
import type {TurboModule} from '../TurboModule/RCTExport'; | ||
|
||
import * as TurboModuleRegistry from '../TurboModule/TurboModuleRegistry'; | ||
|
||
export interface Spec extends TurboModule { | ||
+setConsolePatchSettings: (newConsolePatchSettings: string) => void; | ||
+getConsolePatchSettings: () => ?string; | ||
} | ||
|
||
export default (TurboModuleRegistry.get<Spec>( | ||
'DevToolsSettingsManager', | ||
): ?Spec); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
ReactAndroid/src/main/java/com/facebook/react/modules/devtoolssettings/BUCK
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
load("//tools/build_defs/oss:rn_defs.bzl", "react_native_dep", "react_native_root_target", "react_native_target", "rn_android_library") | ||
|
||
rn_android_library( | ||
name = "devtoolssettings", | ||
srcs = glob(["**/*.java"]), | ||
autoglob = False, | ||
labels = [ | ||
"pfh:ReactNative_CommonInfrastructurePlaceholder", | ||
"supermodule:xplat/default/public.react_native.infra", | ||
], | ||
language = "JAVA", | ||
provided_deps = [ | ||
react_native_dep("third-party/android/androidx:annotation"), | ||
], | ||
visibility = [ | ||
"PUBLIC", | ||
], | ||
deps = [ | ||
react_native_dep("libraries/fbcore/src/main/java/com/facebook/common/logging:logging"), | ||
react_native_dep("third-party/java/infer-annotations:infer-annotations"), | ||
react_native_dep("third-party/java/jsr-305:jsr-305"), | ||
react_native_target("java/com/facebook/react/bridge:bridge"), | ||
react_native_target("java/com/facebook/react/common:common"), | ||
react_native_target("java/com/facebook/react/module/annotations:annotations"), | ||
react_native_target("java/com/facebook/react/modules/core:core"), | ||
], | ||
exported_deps = [react_native_root_target(":FBReactNativeSpec")], | ||
) |
49 changes: 49 additions & 0 deletions
49
.../main/java/com/facebook/react/modules/devtoolssettings/DevToolsSettingsManagerModule.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
package com.facebook.react.modules.devtoolssettings; | ||
|
||
import android.content.Context; | ||
import android.content.SharedPreferences; | ||
import android.content.SharedPreferences.Editor; | ||
import androidx.annotation.Nullable; | ||
import com.facebook.fbreact.specs.NativeDevToolsSettingsManagerSpec; | ||
import com.facebook.react.bridge.ReactApplicationContext; | ||
import com.facebook.react.module.annotations.ReactModule; | ||
|
||
@ReactModule(name = DevToolsSettingsManagerModule.NAME) | ||
public class DevToolsSettingsManagerModule extends NativeDevToolsSettingsManagerSpec { | ||
public static final String NAME = "DevToolsSettingsManager"; | ||
|
||
private static final String SHARED_PREFERENCES_PREFIX = "ReactNative__DevToolsSettings"; | ||
private static final String KEY_CONSOLE_PATCH_SETTINGS = "ConsolePatchSettings"; | ||
|
||
private final SharedPreferences mSharedPreferences; | ||
|
||
public DevToolsSettingsManagerModule(ReactApplicationContext reactContext) { | ||
super(reactContext); | ||
mSharedPreferences = | ||
reactContext.getSharedPreferences(SHARED_PREFERENCES_PREFIX, Context.MODE_PRIVATE); | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return NAME; | ||
} | ||
|
||
@Override | ||
public @Nullable String getConsolePatchSettings() { | ||
return mSharedPreferences.getString(KEY_CONSOLE_PATCH_SETTINGS, null); | ||
} | ||
|
||
@Override | ||
public void setConsolePatchSettings(String newSettings) { | ||
Editor editor = mSharedPreferences.edit(); | ||
editor.putString(KEY_CONSOLE_PATCH_SETTINGS, newSettings); | ||
editor.apply(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters