Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
rbalicki2 committed Oct 17, 2022
1 parent 31bedd9 commit 97fd1a9
Show file tree
Hide file tree
Showing 8 changed files with 191 additions and 1 deletion.
6 changes: 6 additions & 0 deletions Libraries/Core/setUpReactDevTools.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ if (__DEV__) {
});

const ReactNativeStyleAttributes = require('../Components/View/ReactNativeStyleAttributes');
const devToolsSettingsManager = require('../Settings/NativeDevToolsSettingsManager').default;
setTimeout(() => {

console.log('hello from RN', devToolsSettingsManager)
}, 1000)

reactDevTools.connectToDevTools({
isAppActive,
Expand All @@ -70,6 +75,7 @@ if (__DEV__) {
ReactNativeStyleAttributes,
),
websocket: ws,
devToolsSettingsManager,
});
}
};
Expand Down
7 changes: 7 additions & 0 deletions Libraries/NewAppScreen/components/ReloadInstructions.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ const styles = StyleSheet.create({
},
});

function Foo() {
const [state, setState] = React.useState();
console.warn('hello from foo');
return <Text onPress={() => setState({})}>FOOOO</Text>
}

const ReloadInstructions: () => Node = Platform.select({
ios: () => (
<Text>
Expand All @@ -30,6 +36,7 @@ const ReloadInstructions: () => Node = Platform.select({
),
default: () => (
<Text>
<Foo />
Double tap <Text style={styles.highlight}>R</Text> on your keyboard to
reload your app's code.
</Text>
Expand Down
22 changes: 22 additions & 0 deletions Libraries/Settings/NativeDevToolsSettingsManager.js
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
* @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);
16 changes: 16 additions & 0 deletions Libraries/Settings/RCTDevToolsSettingsManager.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
* 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.
*/

#import <Foundation/Foundation.h>

#import <React/RCTBridgeModule.h>

@interface RCTDevToolsSettingsManager : NSObject <RCTBridgeModule>

- (instancetype)initWithUserDefaults:(NSUserDefaults *)defaults NS_DESIGNATED_INITIALIZER;

@end
61 changes: 61 additions & 0 deletions Libraries/Settings/RCTDevToolsSettingsManager.mm
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* 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.
*/

#import <React/RCTDevToolsSettingsManager.h>

#import <FBReactNativeSpec/FBReactNativeSpec.h>
#import <React/RCTBridge.h>
#import <React/RCTConvert.h>
#import <React/RCTEventDispatcherProtocol.h>
#import <React/RCTUtils.h>

#import "RCTDevToolsSettingsPlugins.h"

@interface RCTDevToolsSettingsManager() <NativeDevToolsSettingsManagerSpec>
@end

@implementation RCTDevToolsSettingsManager
{
NSUserDefaults *_defaults;
}

RCT_EXPORT_MODULE(DevToolsSettingsManager)

- (instancetype)init
{
return [self initWithUserDefaults:[NSUserDefaults standardUserDefaults]];
}

- (instancetype)initWithUserDefaults:(NSUserDefaults *)defaults
{
if ((self = [super init])) {
_defaults = defaults;
}
return self;
}

RCT_EXPORT_METHOD(setConsolePatchSettings:(NSString *)newConsolePatchSettings)
{
[self->_defaults setObject:newConsolePatchSettings forKey:@"ReactDevTools::ConsolePatchSettings"];
}

RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(getConsolePatchSettings)
{
return [self->_defaults stringForKey:@"ReactDevTools::ConsolePatchSettings"];
}

- (std::shared_ptr<facebook::react::TurboModule>)getTurboModule:(const facebook::react::ObjCTurboModule::InitParams &)params
{
return std::make_shared<facebook::react::NativeDevToolsSettingsManagerSpecJSI>(params);
}

@end

Class RCTDevToolsSettingsManagerCls(void)
{
return RCTDevToolsSettingsManager.class;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
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 = "settings",
srcs = glob(["**/*.java"]),
autoglob = False,
labels = [
"pfh:ReactNative_CommonInfrastructurePlaceholder",
"supermodule:xplat/default/public.react_native.infra",
],
language = "JAVA",
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")],
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* 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 com.facebook.fbreact.specs.NativeDevToolsSettingsManagerSpec;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.module.annotations.ReactModule;
import android.content.SharedPreferences;
import androidx.annotation.Nullable;
import android.content.SharedPreferences.Editor;
import android.content.Context;

@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 sharedPreferences;

public DevToolsSettingsManagerModule(ReactApplicationContext reactContext) {
super(reactContext);
sharedPreferences = reactContext.getSharedPreferences(SHARED_PREFERENCES_PREFIX, Context.MODE_PRIVATE);
}

@Override
public String getName() {
return NAME;
}

@Override
public @Nullable String getConsolePatchSettings() {
return sharedPreferences.getString(KEY_CONSOLE_PATCH_SETTINGS, null);
}

@Override
public void setConsolePatchSettings(String newSettings) {
Editor editor = sharedPreferences.edit();
editor.putString(KEY_CONSOLE_PATCH_SETTINGS, newSettings);
editor.apply();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import com.facebook.react.modules.intent.IntentModule;
import com.facebook.react.modules.network.NetworkingModule;
import com.facebook.react.modules.permissions.PermissionsModule;
import com.facebook.react.modules.devtoolssettings.DevToolsSettingsManagerModule;
import com.facebook.react.modules.share.ShareModule;
import com.facebook.react.modules.sound.SoundManagerModule;
import com.facebook.react.modules.statusbar.StatusBarModule;
Expand Down Expand Up @@ -145,6 +146,8 @@ public MainReactPackage(MainPackageConfig config) {
return new VibrationModule(context);
case WebSocketModule.NAME:
return new WebSocketModule(context);
case DevToolsSettingsManagerModule.NAME:
return new DevToolsSettingsManagerModule(context);
default:
return null;
}
Expand Down Expand Up @@ -185,7 +188,8 @@ public ReactModuleInfoProvider getReactModuleInfoProvider() {
Class.forName("com.facebook.react.shell.MainReactPackage$$ReactModuleInfoProvider");
return (ReactModuleInfoProvider) reactModuleInfoProviderClass.newInstance();
} catch (ClassNotFoundException e) {
// In OSS case, the annotation processor does not run. We fall back on creating this byhand
// In the OSS case, the annotation processor does not run. We fall back to creating this by
// hand
Class<? extends NativeModule>[] moduleList =
new Class[] {
AccessibilityInfoModule.class,
Expand All @@ -204,6 +208,7 @@ public ReactModuleInfoProvider getReactModuleInfoProvider() {
NativeAnimatedModule.class,
NetworkingModule.class,
PermissionsModule.class,
DevToolsSettingsManagerModule.class,
ShareModule.class,
StatusBarModule.class,
SoundManagerModule.class,
Expand Down

0 comments on commit 97fd1a9

Please sign in to comment.