Skip to content

Commit 6152763

Browse files
Robert Balickifacebook-github-bot
Robert Balicki
authored andcommitted
Buck, etc. changes that enable persisted, sync settings for DevTools (#35163)
Summary: Pull Request resolved: #35163 # What This diff contains all the changes from D40333083 (0fac981) (aka #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
1 parent 7203187 commit 6152763

File tree

10 files changed

+155
-1
lines changed

10 files changed

+155
-1
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
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+
import NativeDevToolsSettingsManager from './NativeDevToolsSettingsManager';
12+
13+
module.exports = NativeDevToolsSettingsManager;
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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-local
8+
* @format
9+
*/
10+
11+
import type {Spec} from './NativeDevToolsSettingsManager';
12+
13+
import Settings from '../Settings/Settings';
14+
15+
const CONSOLE_PATCH_SETTINGS_KEY = 'ReactDevTools::ConsolePatchSettings';
16+
17+
const DevToolsSettingsManager = {
18+
setConsolePatchSettings: (newConsolePatchSettings: string) => {
19+
Settings.set({
20+
[CONSOLE_PATCH_SETTINGS_KEY]: newConsolePatchSettings,
21+
});
22+
},
23+
getConsolePatchSettings: () => {
24+
const value = Settings.get(CONSOLE_PATCH_SETTINGS_KEY);
25+
if (typeof value === 'string') {
26+
// $FlowFixMe[unclear-type]
27+
return ((value: any): string);
28+
}
29+
return null;
30+
},
31+
};
32+
33+
module.exports = (DevToolsSettingsManager: Spec);
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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+
import type {TurboModule} from '../TurboModule/RCTExport';
12+
13+
import * as TurboModuleRegistry from '../TurboModule/TurboModuleRegistry';
14+
15+
export interface Spec extends TurboModule {
16+
+setConsolePatchSettings: (newConsolePatchSettings: string) => void;
17+
+getConsolePatchSettings: () => ?string;
18+
}
19+
20+
export default (TurboModuleRegistry.get<Spec>(
21+
'DevToolsSettingsManager',
22+
): ?Spec);

React/CoreModules/BUCK

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ rn_apple_library(
134134
"//xplat/js/react-native-github:FBReactNativeSpecApple",
135135
"//xplat/js/react-native-github:RCTLinkingApple",
136136
"//xplat/js/react-native-github:RCTPushNotificationApple",
137+
"//xplat/js/react-native-github:RCTSettingsApple",
137138
"//xplat/js/react-native-github:ReactInternalApple",
138139
],
139140
)

ReactAndroid/src/main/java/com/facebook/react/BUCK

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ rn_android_library(
4141
react_native_target("java/com/facebook/react/modules/appearance:appearance"),
4242
react_native_target("java/com/facebook/react/modules/bundleloader:bundleloader"),
4343
react_native_target("java/com/facebook/react/modules/debug:debug"),
44+
react_native_target("java/com/facebook/react/modules/devtoolssettings:devtoolssettings"),
4445
react_native_target("java/com/facebook/react/modules/fabric:fabric"),
4546
react_native_target("java/com/facebook/react/modules/debug:interfaces"),
4647
react_native_target("java/com/facebook/react/modules/deviceinfo:deviceinfo"),
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
load("//tools/build_defs/oss:rn_defs.bzl", "react_native_dep", "react_native_root_target", "react_native_target", "rn_android_library")
2+
3+
rn_android_library(
4+
name = "devtoolssettings",
5+
srcs = glob(["**/*.java"]),
6+
autoglob = False,
7+
labels = [
8+
"pfh:ReactNative_CommonInfrastructurePlaceholder",
9+
"supermodule:xplat/default/public.react_native.infra",
10+
],
11+
language = "JAVA",
12+
provided_deps = [
13+
react_native_dep("third-party/android/androidx:annotation"),
14+
],
15+
visibility = [
16+
"PUBLIC",
17+
],
18+
deps = [
19+
react_native_dep("libraries/fbcore/src/main/java/com/facebook/common/logging:logging"),
20+
react_native_dep("third-party/java/infer-annotations:infer-annotations"),
21+
react_native_dep("third-party/java/jsr-305:jsr-305"),
22+
react_native_target("java/com/facebook/react/bridge:bridge"),
23+
react_native_target("java/com/facebook/react/common:common"),
24+
react_native_target("java/com/facebook/react/module/annotations:annotations"),
25+
react_native_target("java/com/facebook/react/modules/core:core"),
26+
],
27+
exported_deps = [react_native_root_target(":FBReactNativeSpec")],
28+
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
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+
8+
package com.facebook.react.modules.devtoolssettings;
9+
10+
import android.content.Context;
11+
import android.content.SharedPreferences;
12+
import android.content.SharedPreferences.Editor;
13+
import androidx.annotation.Nullable;
14+
import com.facebook.fbreact.specs.NativeDevToolsSettingsManagerSpec;
15+
import com.facebook.react.bridge.ReactApplicationContext;
16+
import com.facebook.react.module.annotations.ReactModule;
17+
18+
@ReactModule(name = DevToolsSettingsManagerModule.NAME)
19+
public class DevToolsSettingsManagerModule extends NativeDevToolsSettingsManagerSpec {
20+
public static final String NAME = "DevToolsSettingsManager";
21+
22+
private static final String SHARED_PREFERENCES_PREFIX = "ReactNative__DevToolsSettings";
23+
private static final String KEY_CONSOLE_PATCH_SETTINGS = "ConsolePatchSettings";
24+
25+
private final SharedPreferences mSharedPreferences;
26+
27+
public DevToolsSettingsManagerModule(ReactApplicationContext reactContext) {
28+
super(reactContext);
29+
mSharedPreferences =
30+
reactContext.getSharedPreferences(SHARED_PREFERENCES_PREFIX, Context.MODE_PRIVATE);
31+
}
32+
33+
@Override
34+
public String getName() {
35+
return NAME;
36+
}
37+
38+
@Override
39+
public @Nullable String getConsolePatchSettings() {
40+
return mSharedPreferences.getString(KEY_CONSOLE_PATCH_SETTINGS, null);
41+
}
42+
43+
@Override
44+
public void setConsolePatchSettings(String newSettings) {
45+
Editor editor = mSharedPreferences.edit();
46+
editor.putString(KEY_CONSOLE_PATCH_SETTINGS, newSettings);
47+
editor.apply();
48+
}
49+
}

ReactAndroid/src/main/java/com/facebook/react/shell/BUCK

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ rn_android_library(
3737
react_native_target("java/com/facebook/react/modules/clipboard:clipboard"),
3838
react_native_target("java/com/facebook/react/modules/core:core"),
3939
react_native_target("java/com/facebook/react/modules/debug:debug"),
40+
react_native_target("java/com/facebook/react/modules/devtoolssettings:devtoolssettings"),
4041
react_native_target("java/com/facebook/react/modules/dialog:dialog"),
4142
react_native_target("java/com/facebook/react/modules/fresco:fresco"),
4243
react_native_target("java/com/facebook/react/modules/i18nmanager:i18nmanager"),

ReactAndroid/src/main/java/com/facebook/react/shell/MainReactPackage.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import com.facebook.react.modules.blob.FileReaderModule;
2424
import com.facebook.react.modules.camera.ImageStoreManager;
2525
import com.facebook.react.modules.clipboard.ClipboardModule;
26+
import com.facebook.react.modules.devtoolssettings.DevToolsSettingsManagerModule;
2627
import com.facebook.react.modules.dialog.DialogModule;
2728
import com.facebook.react.modules.fresco.FrescoModule;
2829
import com.facebook.react.modules.i18nmanager.I18nManagerModule;
@@ -141,6 +142,8 @@ public MainReactPackage(MainPackageConfig config) {
141142
return new VibrationModule(context);
142143
case WebSocketModule.NAME:
143144
return new WebSocketModule(context);
145+
case DevToolsSettingsManagerModule.NAME:
146+
return new DevToolsSettingsManagerModule(context);
144147
default:
145148
return null;
146149
}
@@ -181,7 +184,8 @@ public ReactModuleInfoProvider getReactModuleInfoProvider() {
181184
Class.forName("com.facebook.react.shell.MainReactPackage$$ReactModuleInfoProvider");
182185
return (ReactModuleInfoProvider) reactModuleInfoProviderClass.newInstance();
183186
} catch (ClassNotFoundException e) {
184-
// In OSS case, the annotation processor does not run. We fall back on creating this byhand
187+
// In the OSS case, the annotation processor does not run. We fall back to creating this by
188+
// hand
185189
Class<? extends NativeModule>[] moduleList =
186190
new Class[] {
187191
AccessibilityInfoModule.class,
@@ -199,6 +203,7 @@ public ReactModuleInfoProvider getReactModuleInfoProvider() {
199203
NativeAnimatedModule.class,
200204
NetworkingModule.class,
201205
PermissionsModule.class,
206+
DevToolsSettingsManagerModule.class,
202207
ShareModule.class,
203208
StatusBarModule.class,
204209
SoundManagerModule.class,

ReactAndroid/src/test/java/com/facebook/react/modules/BUCK

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ rn_robolectric_test(
3434
react_native_target("java/com/facebook/react/modules/core:core"),
3535
react_native_target("java/com/facebook/react/modules/debug:debug"),
3636
react_native_target("java/com/facebook/react/modules/deviceinfo:deviceinfo"),
37+
react_native_target("java/com/facebook/react/modules/devtoolssettings:devtoolssettings"),
3738
react_native_target("java/com/facebook/react/modules/dialog:dialog"),
3839
react_native_target("java/com/facebook/react/modules/network:network"),
3940
react_native_target("java/com/facebook/react/modules/share:share"),

0 commit comments

Comments
 (0)