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.
Summary: Changelog: [General][Added] - Add support for reload-to-profile in Fusebox. CDT: facebookexperimental/rn-chrome-devtools-frontend#117 React: facebook/react#31021 This diff adds support for reload2profile under bridge and bridgeless for iOS, Android, and C++ Differential Revision: D63233256
- Loading branch information
1 parent
cc6d1eb
commit 39be9ec
Showing
19 changed files
with
416 additions
and
1 deletion.
There are no files selected for viewing
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
12 changes: 12 additions & 0 deletions
12
packages/react-native/React/CoreModules/RCTDevToolsRuntimeSettingsModule.h
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,12 @@ | ||
/* | ||
* 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> | ||
|
||
@interface RCTDevToolsRuntimeSettingsModule : NSObject | ||
|
||
@end |
58 changes: 58 additions & 0 deletions
58
packages/react-native/React/CoreModules/RCTDevToolsRuntimeSettingsModule.mm
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,58 @@ | ||
/* | ||
* 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 <FBReactNativeSpec/FBReactNativeSpec.h> | ||
#import <React/RCTDevToolsRuntimeSettingsModule.h> | ||
|
||
#import "CoreModulesPlugins.h" | ||
|
||
struct Config { | ||
bool shouldReloadAndProfile = false; | ||
bool recordChangeDescriptions = false; | ||
}; | ||
|
||
// static to persist across Turbo Module reloads | ||
static Config _config; | ||
|
||
@interface RCTDevToolsRuntimeSettingsModule () <NativeReactDevToolsRuntimeSettingsModuleSpec> { | ||
} | ||
@end | ||
|
||
@implementation RCTDevToolsRuntimeSettingsModule | ||
RCT_EXPORT_MODULE(ReactDevToolsRuntimeSettingsModule) | ||
|
||
RCT_EXPORT_METHOD(setReloadAndProfileConfig | ||
: (JS::NativeReactDevToolsRuntimeSettingsModule::PartialReloadAndProfileConfig &)config) | ||
{ | ||
if (config.shouldReloadAndProfile().has_value()) { | ||
_config.shouldReloadAndProfile = config.shouldReloadAndProfile().value(); | ||
} | ||
if (config.recordChangeDescriptions().has_value()) { | ||
_config.recordChangeDescriptions = config.recordChangeDescriptions().value(); | ||
} | ||
} | ||
|
||
RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(getReloadAndProfileConfig) | ||
{ | ||
return @{ | ||
@"shouldReloadAndProfile" : @(_config.shouldReloadAndProfile), | ||
@"recordChangeDescriptions" : @(_config.recordChangeDescriptions), | ||
}; | ||
} | ||
|
||
- (std::shared_ptr<facebook::react::TurboModule>)getTurboModule: | ||
(const facebook::react::ObjCTurboModule::InitParams &)params | ||
{ | ||
return std::make_shared<facebook::react::NativeReactDevToolsRuntimeSettingsModuleSpecJSI>(params); | ||
} | ||
|
||
@end | ||
|
||
Class RCTDevToolsRuntimeSettingsCls(void) | ||
{ | ||
return RCTDevToolsRuntimeSettingsModule.class; | ||
} |
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
48 changes: 48 additions & 0 deletions
48
.../com/facebook/react/modules/devtoolsruntimesettings/ReactDevToolsRuntimeSettingsModule.kt
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,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.devtoolsruntimesettings | ||
|
||
import com.facebook.fbreact.specs.NativeReactDevToolsRuntimeSettingsModuleSpec | ||
import com.facebook.jni.annotations.DoNotStripAny | ||
import com.facebook.react.bridge.Arguments | ||
import com.facebook.react.bridge.ReactApplicationContext | ||
import com.facebook.react.bridge.ReadableMap | ||
import com.facebook.react.bridge.WritableMap | ||
import com.facebook.react.module.annotations.ReactModule | ||
|
||
private class Settings { | ||
var shouldReloadAndProfile: Boolean = false | ||
var recordChangeDescriptions: Boolean = false | ||
} | ||
|
||
@DoNotStripAny | ||
@ReactModule(name = NativeReactDevToolsRuntimeSettingsModuleSpec.NAME) | ||
public class ReactDevToolsRuntimeSettingsModule(reactContext: ReactApplicationContext?) : | ||
NativeReactDevToolsRuntimeSettingsModuleSpec(reactContext) { | ||
|
||
// static to persist across Turbo Module reloads | ||
private companion object { | ||
private val settings = Settings() | ||
} | ||
|
||
override fun setReloadAndProfileConfig(map: ReadableMap) { | ||
if (map.hasKey("shouldReloadAndProfile")) { | ||
settings.shouldReloadAndProfile = map.getBoolean("shouldReloadAndProfile") | ||
} | ||
if (map.hasKey("recordChangeDescriptions")) { | ||
settings.recordChangeDescriptions = map.getBoolean("recordChangeDescriptions") | ||
} | ||
} | ||
|
||
override fun getReloadAndProfileConfig(): WritableMap { | ||
val map = Arguments.createMap() | ||
map.putBoolean("shouldReloadAndProfile", settings.shouldReloadAndProfile) | ||
map.putBoolean("recordChangeDescriptions", settings.recordChangeDescriptions) | ||
return map | ||
} | ||
} |
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
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
22 changes: 22 additions & 0 deletions
22
packages/react-native/ReactCommon/devtoolsruntimesettings/CMakeLists.txt
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. | ||
|
||
cmake_minimum_required(VERSION 3.13) | ||
set(CMAKE_VERBOSE_MAKEFILE on) | ||
|
||
add_compile_options( | ||
-fexceptions | ||
-frtti | ||
-std=c++20 | ||
-Wall | ||
-Wpedantic) | ||
|
||
add_library(devtoolsruntimesettingscxx INTERFACE) | ||
|
||
target_include_directories(devtoolsruntimesettingscxx INTERFACE .) | ||
|
||
target_link_libraries(devtoolsruntimesettingscxx | ||
jsi | ||
) |
27 changes: 27 additions & 0 deletions
27
packages/react-native/ReactCommon/devtoolsruntimesettings/DevToolsRuntimeSettings.cpp
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,27 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
#include "DevToolsRuntimeSettings.h" | ||
|
||
namespace facebook::react { | ||
|
||
void DevToolsRuntimeSettings::setReloadAndProfileConfig( | ||
NativePartialReloadAndProfileConfig config) { | ||
if (config.shouldReloadAndProfile.has_value()) { | ||
_config.shouldReloadAndProfile = config.shouldReloadAndProfile.value(); | ||
} | ||
if (config.shouldReloadAndProfile.has_value()) { | ||
_config.recordChangeDescriptions = config.recordChangeDescriptions.value(); | ||
} | ||
}; | ||
|
||
NativeReloadAndProfileConfig | ||
DevToolsRuntimeSettings::getReloadAndProfileConfig() const { | ||
return _config; | ||
}; | ||
|
||
} // namespace facebook::react |
53 changes: 53 additions & 0 deletions
53
packages/react-native/ReactCommon/devtoolsruntimesettings/DevToolsRuntimeSettings.h
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,53 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <FBReactNativeSpec/FBReactNativeSpecJSI.h> | ||
|
||
namespace facebook::react { | ||
|
||
using NativePartialReloadAndProfileConfig = | ||
NativeReactDevToolsRuntimeSettingsModulePartialReloadAndProfileConfig< | ||
std::optional<bool>, | ||
std::optional<bool>>; | ||
|
||
template <> | ||
struct Bridging<NativePartialReloadAndProfileConfig> | ||
: NativeReactDevToolsRuntimeSettingsModulePartialReloadAndProfileConfigBridging< | ||
NativePartialReloadAndProfileConfig> {}; | ||
|
||
using NativeReloadAndProfileConfig = | ||
NativeReactDevToolsRuntimeSettingsModuleReloadAndProfileConfig<bool, bool>; | ||
|
||
template <> | ||
struct Bridging<NativeReloadAndProfileConfig> | ||
: NativeReactDevToolsRuntimeSettingsModuleReloadAndProfileConfigBridging< | ||
NativeReloadAndProfileConfig> {}; | ||
|
||
class DevToolsRuntimeSettings { | ||
public: | ||
// static to persist across Turbo Module reloads | ||
static DevToolsRuntimeSettings& getInstance() { | ||
static DevToolsRuntimeSettings instance; | ||
return instance; | ||
} | ||
|
||
private: | ||
NativeReloadAndProfileConfig _config; | ||
|
||
DevToolsRuntimeSettings() : _config() {} | ||
|
||
public: | ||
DevToolsRuntimeSettings(const DevToolsRuntimeSettings&) = delete; | ||
void operator=(const DevToolsRuntimeSettings&) = delete; | ||
|
||
void setReloadAndProfileConfig(NativePartialReloadAndProfileConfig config); | ||
NativeReloadAndProfileConfig getReloadAndProfileConfig() const; | ||
}; | ||
|
||
} // namespace facebook::react |
Oops, something went wrong.