Skip to content

Commit 9a45934

Browse files
committed
wip
1 parent 31bedd9 commit 9a45934

File tree

10 files changed

+148
-1
lines changed

10 files changed

+148
-1
lines changed

Libraries/Core/setUpReactDevTools.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ if (__DEV__) {
6262
});
6363

6464
const ReactNativeStyleAttributes = require('../Components/View/ReactNativeStyleAttributes');
65+
const devToolsSettingsManager = require('../Settings/DevToolsSettingsManager');
6566

6667
reactDevTools.connectToDevTools({
6768
isAppActive,
@@ -70,6 +71,7 @@ if (__DEV__) {
7071
ReactNativeStyleAttributes,
7172
),
7273
websocket: ws,
74+
devToolsSettingsManager,
7375
});
7476
}
7577
};
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
8+
* @format
9+
*/
10+
11+
import NativeDevToolsSettingsManager from './NativeDevToolsSettingsManager';
12+
13+
module.exports = NativeDevToolsSettingsManager;
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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
8+
* @format
9+
*/
10+
11+
import type {Spec} from './NativeDevToolsSettingsManager';
12+
import Settings from './Settings';
13+
14+
const CONSOLE_PATCH_SETTINGS_KEY = 'ReactDevTools::ConsolePatchSettings';
15+
16+
const DevToolsSettingsManager = {
17+
setConsolePatchSettings: (newConsolePatchSettings: string) => {
18+
Settings.set({
19+
[CONSOLE_PATCH_SETTINGS_KEY]: newConsolePatchSettings,
20+
});
21+
},
22+
getConsolePatchSettings: () =>
23+
((Settings.get(CONSOLE_PATCH_SETTINGS_KEY): any): string),
24+
};
25+
26+
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
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);

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ rn_android_library(
4242
react_native_target("java/com/facebook/react/modules/appearance:appearance"),
4343
react_native_target("java/com/facebook/react/modules/bundleloader:bundleloader"),
4444
react_native_target("java/com/facebook/react/modules/debug:debug"),
45+
react_native_target("java/com/facebook/react/modules/devtoolssettings:devtoolssettings"),
4546
react_native_target("java/com/facebook/react/modules/fabric:fabric"),
4647
react_native_target("java/com/facebook/react/modules/debug:interfaces"),
4748
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+
visibility = [
13+
"PUBLIC",
14+
],
15+
provided_deps = [
16+
react_native_dep("third-party/android/androidx:annotation"),
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+
)
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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 com.facebook.fbreact.specs.NativeDevToolsSettingsManagerSpec;
11+
import com.facebook.react.bridge.ReactApplicationContext;
12+
import com.facebook.react.module.annotations.ReactModule;
13+
import android.content.SharedPreferences;
14+
import androidx.annotation.Nullable;
15+
import android.content.SharedPreferences.Editor;
16+
import android.content.Context;
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 sharedPreferences;
26+
27+
public DevToolsSettingsManagerModule(ReactApplicationContext reactContext) {
28+
super(reactContext);
29+
sharedPreferences = reactContext.getSharedPreferences(SHARED_PREFERENCES_PREFIX, Context.MODE_PRIVATE);
30+
}
31+
32+
@Override
33+
public String getName() {
34+
return NAME;
35+
}
36+
37+
@Override
38+
public @Nullable String getConsolePatchSettings() {
39+
return sharedPreferences.getString(KEY_CONSOLE_PATCH_SETTINGS, null);
40+
}
41+
42+
@Override
43+
public void setConsolePatchSettings(String newSettings) {
44+
Editor editor = sharedPreferences.edit();
45+
editor.putString(KEY_CONSOLE_PATCH_SETTINGS, newSettings);
46+
editor.apply();
47+
}
48+
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ rn_android_library(
3838
react_native_target("java/com/facebook/react/modules/clipboard:clipboard"),
3939
react_native_target("java/com/facebook/react/modules/core:core"),
4040
react_native_target("java/com/facebook/react/modules/debug:debug"),
41+
react_native_target("java/com/facebook/react/modules/devtoolssettings:devtoolssettings"),
4142
react_native_target("java/com/facebook/react/modules/dialog:dialog"),
4243
react_native_target("java/com/facebook/react/modules/fresco:fresco"),
4344
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
@@ -30,6 +30,7 @@
3030
import com.facebook.react.modules.intent.IntentModule;
3131
import com.facebook.react.modules.network.NetworkingModule;
3232
import com.facebook.react.modules.permissions.PermissionsModule;
33+
import com.facebook.react.modules.devtoolssettings.DevToolsSettingsManagerModule;
3334
import com.facebook.react.modules.share.ShareModule;
3435
import com.facebook.react.modules.sound.SoundManagerModule;
3536
import com.facebook.react.modules.statusbar.StatusBarModule;
@@ -145,6 +146,8 @@ public MainReactPackage(MainPackageConfig config) {
145146
return new VibrationModule(context);
146147
case WebSocketModule.NAME:
147148
return new WebSocketModule(context);
149+
case DevToolsSettingsManagerModule.NAME:
150+
return new DevToolsSettingsManagerModule(context);
148151
default:
149152
return null;
150153
}
@@ -185,7 +188,8 @@ public ReactModuleInfoProvider getReactModuleInfoProvider() {
185188
Class.forName("com.facebook.react.shell.MainReactPackage$$ReactModuleInfoProvider");
186189
return (ReactModuleInfoProvider) reactModuleInfoProviderClass.newInstance();
187190
} catch (ClassNotFoundException e) {
188-
// In OSS case, the annotation processor does not run. We fall back on creating this byhand
191+
// In the OSS case, the annotation processor does not run. We fall back to creating this by
192+
// hand
189193
Class<? extends NativeModule>[] moduleList =
190194
new Class[] {
191195
AccessibilityInfoModule.class,
@@ -204,6 +208,7 @@ public ReactModuleInfoProvider getReactModuleInfoProvider() {
204208
NativeAnimatedModule.class,
205209
NetworkingModule.class,
206210
PermissionsModule.class,
211+
DevToolsSettingsManagerModule.class,
207212
ShareModule.class,
208213
StatusBarModule.class,
209214
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)