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.
Fusebox reload-to-profile (facebook#46856)
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++ Reviewed By: hoxyq Differential Revision: D63233256
- Loading branch information
1 parent
768a1d8
commit 784c862
Showing
16 changed files
with
375 additions
and
0 deletions.
There are no files selected for viewing
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
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
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(react_devtoolsruntimesettingscxx INTERFACE) | ||
|
||
target_include_directories(react_devtoolsruntimesettingscxx INTERFACE .) | ||
|
||
target_link_libraries(react_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 |
56 changes: 56 additions & 0 deletions
56
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,56 @@ | ||
/* | ||
* 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() = default; | ||
DevToolsRuntimeSettings(const DevToolsRuntimeSettings&) = delete; | ||
DevToolsRuntimeSettings(DevToolsRuntimeSettings&&) = delete; | ||
void operator=(const DevToolsRuntimeSettings&) = delete; | ||
void operator=(DevToolsRuntimeSettings&&) = delete; | ||
|
||
void setReloadAndProfileConfig(NativePartialReloadAndProfileConfig config); | ||
NativeReloadAndProfileConfig getReloadAndProfileConfig() const; | ||
}; | ||
|
||
} // namespace facebook::react |
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
24 changes: 24 additions & 0 deletions
24
packages/react-native/ReactCommon/react/nativemodule/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,24 @@ | ||
# 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 | ||
-DLOG_TAG=\"ReactNative\") | ||
|
||
file(GLOB react_nativemodule_devtoolsruntimesettings_SRC CONFIGURE_DEPENDS *.cpp) | ||
add_library(react_nativemodule_devtoolsruntimesettings OBJECT ${react_nativemodule_devtoolsruntimesettings_SRC}) | ||
|
||
target_include_directories(react_nativemodule_devtoolsruntimesettings PUBLIC ${REACT_COMMON_DIR}) | ||
|
||
target_link_libraries(react_nativemodule_devtoolsruntimesettings | ||
react_devtoolsruntimesettingscxx | ||
) |
35 changes: 35 additions & 0 deletions
35
.../ReactCommon/react/nativemodule/devtoolsruntimesettings/DevToolsRuntimeSettingsModule.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,35 @@ | ||
/* | ||
* 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 "DevToolsRuntimeSettingsModule.h" | ||
#include "Plugins.h" | ||
|
||
std::shared_ptr<facebook::react::TurboModule> | ||
ReactDevToolsRuntimeSettingsModuleProvider( | ||
std::shared_ptr<facebook::react::CallInvoker> jsInvoker) { | ||
return std::make_shared<facebook::react::DevToolsRuntimeSettingsModule>( | ||
std::move(jsInvoker)); | ||
} | ||
|
||
namespace facebook::react { | ||
|
||
DevToolsRuntimeSettingsModule::DevToolsRuntimeSettingsModule( | ||
std::shared_ptr<CallInvoker> jsInvoker) | ||
: NativeReactDevToolsRuntimeSettingsModuleCxxSpec(std::move(jsInvoker)) {} | ||
|
||
void DevToolsRuntimeSettingsModule::setReloadAndProfileConfig( | ||
jsi::Runtime& /*rt*/, | ||
NativePartialReloadAndProfileConfig config) { | ||
DevToolsRuntimeSettings::getInstance().setReloadAndProfileConfig(config); | ||
}; | ||
|
||
NativeReloadAndProfileConfig | ||
DevToolsRuntimeSettingsModule::getReloadAndProfileConfig(jsi::Runtime& /*rt*/) { | ||
return DevToolsRuntimeSettings::getInstance().getReloadAndProfileConfig(); | ||
}; | ||
|
||
} // namespace facebook::react |
Oops, something went wrong.