Make RCTDevMenu and RCTDevSettings TurboModule-compatible
Summary: Changelog: [iOS][Added] - Make RCTDevMenu and RCTDevSettings TurboModule-compatible Reviewed By: shergin Differential Revision: D18148890 fbshipit-source-id: bd4f0b2797e299cd963e34fa47044a9e1232efe0
This commit is contained in:
Родитель
686ab49107
Коммит
fe3ae9dce8
|
@ -766,6 +766,54 @@ namespace facebook {
|
|||
|
||||
|
||||
|
||||
}
|
||||
|
||||
} // namespace react
|
||||
} // namespace facebook
|
||||
namespace facebook {
|
||||
namespace react {
|
||||
|
||||
|
||||
static facebook::jsi::Value __hostFunction_NativeDevMenuSpecJSI_show(facebook::jsi::Runtime& rt, TurboModule &turboModule, const facebook::jsi::Value* args, size_t count) {
|
||||
return static_cast<ObjCTurboModule&>(turboModule).invokeObjCMethod(rt, VoidKind, "show", @selector(show), args, count);
|
||||
}
|
||||
|
||||
static facebook::jsi::Value __hostFunction_NativeDevMenuSpecJSI_reload(facebook::jsi::Runtime& rt, TurboModule &turboModule, const facebook::jsi::Value* args, size_t count) {
|
||||
return static_cast<ObjCTurboModule&>(turboModule).invokeObjCMethod(rt, VoidKind, "reload", @selector(reload), args, count);
|
||||
}
|
||||
|
||||
static facebook::jsi::Value __hostFunction_NativeDevMenuSpecJSI_debugRemotely(facebook::jsi::Runtime& rt, TurboModule &turboModule, const facebook::jsi::Value* args, size_t count) {
|
||||
return static_cast<ObjCTurboModule&>(turboModule).invokeObjCMethod(rt, VoidKind, "debugRemotely", @selector(debugRemotely:), args, count);
|
||||
}
|
||||
|
||||
static facebook::jsi::Value __hostFunction_NativeDevMenuSpecJSI_setProfilingEnabled(facebook::jsi::Runtime& rt, TurboModule &turboModule, const facebook::jsi::Value* args, size_t count) {
|
||||
return static_cast<ObjCTurboModule&>(turboModule).invokeObjCMethod(rt, VoidKind, "setProfilingEnabled", @selector(setProfilingEnabled:), args, count);
|
||||
}
|
||||
|
||||
static facebook::jsi::Value __hostFunction_NativeDevMenuSpecJSI_setHotLoadingEnabled(facebook::jsi::Runtime& rt, TurboModule &turboModule, const facebook::jsi::Value* args, size_t count) {
|
||||
return static_cast<ObjCTurboModule&>(turboModule).invokeObjCMethod(rt, VoidKind, "setHotLoadingEnabled", @selector(setHotLoadingEnabled:), args, count);
|
||||
}
|
||||
|
||||
|
||||
NativeDevMenuSpecJSI::NativeDevMenuSpecJSI(id<RCTTurboModule> instance, std::shared_ptr<CallInvoker> jsInvoker)
|
||||
: ObjCTurboModule("DevMenu", instance, jsInvoker) {
|
||||
|
||||
methodMap_["show"] = MethodMetadata {0, __hostFunction_NativeDevMenuSpecJSI_show};
|
||||
|
||||
|
||||
methodMap_["reload"] = MethodMetadata {0, __hostFunction_NativeDevMenuSpecJSI_reload};
|
||||
|
||||
|
||||
methodMap_["debugRemotely"] = MethodMetadata {1, __hostFunction_NativeDevMenuSpecJSI_debugRemotely};
|
||||
|
||||
|
||||
methodMap_["setProfilingEnabled"] = MethodMetadata {1, __hostFunction_NativeDevMenuSpecJSI_setProfilingEnabled};
|
||||
|
||||
|
||||
methodMap_["setHotLoadingEnabled"] = MethodMetadata {1, __hostFunction_NativeDevMenuSpecJSI_setHotLoadingEnabled};
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
} // namespace react
|
||||
|
|
|
@ -705,6 +705,28 @@ namespace facebook {
|
|||
};
|
||||
} // namespace react
|
||||
} // namespace facebook
|
||||
@protocol NativeDevMenuSpec <RCTBridgeModule, RCTTurboModule>
|
||||
|
||||
- (void)show;
|
||||
- (void)reload;
|
||||
- (void)debugRemotely:(BOOL)enableDebug;
|
||||
- (void)setProfilingEnabled:(BOOL)enabled;
|
||||
- (void)setHotLoadingEnabled:(BOOL)enabled;
|
||||
|
||||
@end
|
||||
namespace facebook {
|
||||
namespace react {
|
||||
/**
|
||||
* ObjC++ class for module 'DevMenu'
|
||||
*/
|
||||
|
||||
class JSI_EXPORT NativeDevMenuSpecJSI : public ObjCTurboModule {
|
||||
public:
|
||||
NativeDevMenuSpecJSI(id<RCTTurboModule> instance, std::shared_ptr<CallInvoker> jsInvoker);
|
||||
|
||||
};
|
||||
} // namespace react
|
||||
} // namespace facebook
|
||||
@protocol NativeDevSettingsSpec <RCTBridgeModule, RCTTurboModule>
|
||||
|
||||
- (void)reload;
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @flow strict-local
|
||||
* @format
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
import type {TurboModule} from '../../TurboModule/RCTExport';
|
||||
import * as TurboModuleRegistry from '../../TurboModule/TurboModuleRegistry';
|
||||
|
||||
export interface Spec extends TurboModule {
|
||||
+show: () => void;
|
||||
+reload: () => void;
|
||||
+debugRemotely: (enableDebug: boolean) => void;
|
||||
+setProfilingEnabled: (enabled: boolean) => void;
|
||||
+setHotLoadingEnabled: (enabled: boolean) => void;
|
||||
}
|
||||
|
||||
export default (TurboModuleRegistry.getEnforcing<Spec>('DevMenu'): Spec);
|
|
@ -237,6 +237,7 @@ PODS:
|
|||
- ReactCommon/turbomodule/core (= 1000.0.0)
|
||||
- React-RCTTest (1000.0.0):
|
||||
- React-Core (= 1000.0.0)
|
||||
- React-CoreModules (= 1000.0.0)
|
||||
- React-RCTText (1000.0.0):
|
||||
- React-Core/RCTTextHeaders (= 1000.0.0)
|
||||
- React-RCTVibration (1000.0.0):
|
||||
|
@ -389,7 +390,7 @@ SPEC CHECKSUMS:
|
|||
React-RCTNetwork: c8f9d40297f35ea3792ea81866f33e8b45c25935
|
||||
React-RCTPushNotification: acffa8af6a20e6d41b041a8c4cb4bea0de9df0dd
|
||||
React-RCTSettings: 8138286da8de74839cb436dd37704ed64d4bfe78
|
||||
React-RCTTest: 73df09ec226fcad6e7e058a313e5dd16cccf86a8
|
||||
React-RCTTest: d148e0657ce77ffd43a10325c284f47f25fb0532
|
||||
React-RCTText: 9078167d3bc011162326f2d8ef4dd580ec1eca17
|
||||
React-RCTVibration: e3269787c533de8c4f54f489202d848fdef33e1d
|
||||
ReactCommon: 9d212865526209dc2d01be40340c8d27b53e6bea
|
||||
|
|
|
@ -29,6 +29,7 @@ Pod::Spec.new do |s|
|
|||
s.preserve_paths = "package.json", "LICENSE", "LICENSE-docs"
|
||||
s.framework = "XCTest"
|
||||
s.header_dir = "RCTTest"
|
||||
|
||||
|
||||
s.dependency "React-Core", version
|
||||
s.dependency "React-CoreModules", version
|
||||
end
|
||||
|
|
|
@ -87,6 +87,12 @@ rn_apple_library(
|
|||
) + react_module_plugin_providers(
|
||||
name = "PerfMonitor",
|
||||
native_class_func = "RCTPerfMonitorCls",
|
||||
) + react_module_plugin_providers(
|
||||
name = "DevMenu",
|
||||
native_class_func = "RCTDevMenuCls",
|
||||
) + react_module_plugin_providers(
|
||||
name = "DevSettings",
|
||||
native_class_func = "RCTDevSettingsCls",
|
||||
),
|
||||
plugins_header = "FBCoreModulesPlugins.h",
|
||||
preprocessor_flags = OBJC_ARC_PREPROCESSOR_FLAGS + get_debug_preprocessor_flags() + rn_extra_build_flags() + [
|
||||
|
|
|
@ -45,6 +45,8 @@ Class RCTStatusBarManagerCls(void) __attribute__((used));
|
|||
Class RCTKeyboardObserverCls(void) __attribute__((used));
|
||||
Class RCTAppStateCls(void) __attribute__((used));
|
||||
Class RCTPerfMonitorCls(void) __attribute__((used));
|
||||
Class RCTDevMenuCls(void) __attribute__((used));
|
||||
Class RCTDevSettingsCls(void) __attribute__((used));
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -34,6 +34,8 @@ Class RCTCoreModulesClassProvider(const char *name) {
|
|||
{"KeyboardObserver", RCTKeyboardObserverCls},
|
||||
{"AppState", RCTAppStateCls},
|
||||
{"PerfMonitor", RCTPerfMonitorCls},
|
||||
{"DevMenu", RCTDevMenuCls},
|
||||
{"DevSettings", RCTDevSettingsCls},
|
||||
};
|
||||
|
||||
auto p = sCoreModuleClassMap.find(name);
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
|
||||
#import <React/RCTDevMenu.h>
|
||||
|
||||
#import <FBReactNativeSpec/FBReactNativeSpec.h>
|
||||
#import <React/RCTBridge+Private.h>
|
||||
#import <React/RCTBundleURLProvider.h>
|
||||
#import <React/RCTDefines.h>
|
||||
|
@ -16,6 +17,8 @@
|
|||
#import <React/RCTReloadCommand.h>
|
||||
#import <React/RCTUtils.h>
|
||||
|
||||
#import "CoreModulesPlugins.h"
|
||||
|
||||
#if RCT_DEV_MENU
|
||||
|
||||
#if RCT_ENABLE_INSPECTOR
|
||||
|
@ -84,7 +87,7 @@ RCT_NOT_IMPLEMENTED(-(instancetype)init)
|
|||
|
||||
typedef void (^RCTDevMenuAlertActionHandler)(UIAlertAction *action);
|
||||
|
||||
@interface RCTDevMenu () <RCTBridgeModule, RCTInvalidating>
|
||||
@interface RCTDevMenu () <RCTBridgeModule, RCTInvalidating, NativeDevMenuSpec>
|
||||
|
||||
@end
|
||||
|
||||
|
@ -229,7 +232,7 @@ RCT_EXPORT_MODULE()
|
|||
[UIAlertController alertControllerWithTitle:@"Debugger Unavailable"
|
||||
message:message
|
||||
preferredStyle:UIAlertControllerStyleAlert];
|
||||
__weak typeof(alertController) weakAlertController = alertController;
|
||||
__weak __typeof__(alertController) weakAlertController = alertController;
|
||||
[alertController
|
||||
addAction:[UIAlertAction actionWithTitle:@"OK"
|
||||
style:UIAlertActionStyleDefault
|
||||
|
@ -301,7 +304,7 @@ RCT_EXPORT_MODULE()
|
|||
[UIAlertController alertControllerWithTitle:@"Systrace Unavailable"
|
||||
message:@"Stop debugging to enable Systrace."
|
||||
preferredStyle:UIAlertControllerStyleAlert];
|
||||
__weak typeof(alertController) weakAlertController = alertController;
|
||||
__weak __typeof__(alertController) weakAlertController = alertController;
|
||||
[alertController
|
||||
addAction:[UIAlertAction actionWithTitle:@"OK"
|
||||
style:UIAlertActionStyleDefault
|
||||
|
@ -490,10 +493,18 @@ RCT_EXPORT_METHOD(setHotLoadingEnabled : (BOOL)enabled)
|
|||
return _bridge.devSettings.isHotLoadingEnabled;
|
||||
}
|
||||
|
||||
- (std::shared_ptr<facebook::react::TurboModule>)getTurboModuleWithJsInvoker:(std::shared_ptr<facebook::react::CallInvoker>)jsInvoker
|
||||
{
|
||||
return std::make_shared<facebook::react::NativeDevMenuSpecJSI>(self, jsInvoker);
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
#else // Unavailable when not in dev mode
|
||||
|
||||
@interface RCTDevMenu() <NativeDevMenuSpec>
|
||||
@end
|
||||
|
||||
@implementation RCTDevMenu
|
||||
|
||||
- (void)show
|
||||
|
@ -508,13 +519,23 @@ RCT_EXPORT_METHOD(setHotLoadingEnabled : (BOOL)enabled)
|
|||
- (void)addItem:(RCTDevMenu *)item
|
||||
{
|
||||
}
|
||||
|
||||
- (void)debugRemotely : (BOOL)enableDebug
|
||||
{
|
||||
}
|
||||
|
||||
- (BOOL)isActionSheetShown
|
||||
{
|
||||
return NO;
|
||||
}
|
||||
+ (NSString *)moduleName
|
||||
{
|
||||
return @"";
|
||||
return @"DevMenu";
|
||||
}
|
||||
|
||||
- (std::shared_ptr<facebook::react::TurboModule>)getTurboModuleWithJsInvoker:(std::shared_ptr<facebook::react::CallInvoker>)jsInvoker
|
||||
{
|
||||
return std::make_shared<facebook::react::NativeDevMenuSpecJSI>(self, jsInvoker);
|
||||
}
|
||||
|
||||
@end
|
||||
|
@ -546,3 +567,7 @@ RCT_EXPORT_METHOD(setHotLoadingEnabled : (BOOL)enabled)
|
|||
}
|
||||
|
||||
@end
|
||||
|
||||
Class RCTDevMenuCls(void) {
|
||||
return RCTDevMenu.class;
|
||||
}
|
|
@ -9,16 +9,19 @@
|
|||
|
||||
#import <objc/runtime.h>
|
||||
|
||||
#import "RCTBridge+Private.h"
|
||||
#import "RCTBridgeModule.h"
|
||||
#import "RCTEventDispatcher.h"
|
||||
#import "RCTLog.h"
|
||||
#import "RCTProfile.h"
|
||||
#import "RCTReloadCommand.h"
|
||||
#import "RCTUtils.h"
|
||||
#import <FBReactNativeSpec/FBReactNativeSpec.h>
|
||||
#import <React/RCTBridge+Private.h>
|
||||
#import <React/RCTBridgeModule.h>
|
||||
#import <React/RCTEventDispatcher.h>
|
||||
#import <React/RCTLog.h>
|
||||
#import <React/RCTProfile.h>
|
||||
#import <React/RCTReloadCommand.h>
|
||||
#import <React/RCTUtils.h>
|
||||
|
||||
#import <React/RCTDevMenu.h>
|
||||
|
||||
#import "CoreModulesPlugins.h"
|
||||
|
||||
static NSString *const kRCTDevSettingProfilingEnabled = @"profilingEnabled";
|
||||
static NSString *const kRCTDevSettingHotLoadingEnabled = @"hotLoadingEnabled";
|
||||
static NSString *const kRCTDevSettingIsInspectorShown = @"showInspector";
|
||||
|
@ -30,12 +33,12 @@ static NSString *const kRCTDevSettingIsPerfMonitorShown = @"RCTPerfMonitorKey";
|
|||
static NSString *const kRCTDevSettingsUserDefaultsKey = @"RCTDevMenu";
|
||||
|
||||
#if ENABLE_PACKAGER_CONNECTION
|
||||
#import "RCTPackagerClient.h"
|
||||
#import "RCTPackagerConnection.h"
|
||||
#import <React/RCTPackagerClient.h>
|
||||
#import <React/RCTPackagerConnection.h>
|
||||
#endif
|
||||
|
||||
#if RCT_ENABLE_INSPECTOR
|
||||
#import "RCTInspectorDevServerHelper.h"
|
||||
#import <React/RCTInspectorDevServerHelper.h>
|
||||
#endif
|
||||
|
||||
#if RCT_DEV
|
||||
|
@ -110,7 +113,7 @@ void RCTDevSettingsSetEnabled(BOOL enabled) {
|
|||
|
||||
@end
|
||||
|
||||
@interface RCTDevSettings () <RCTBridgeModule, RCTInvalidating> {
|
||||
@interface RCTDevSettings () <RCTBridgeModule, RCTInvalidating, NativeDevSettingsSpec> {
|
||||
BOOL _isJSLoaded;
|
||||
#if ENABLE_PACKAGER_CONNECTION
|
||||
RCTHandlerToken _reloadToken;
|
||||
|
@ -437,10 +440,18 @@ RCT_EXPORT_METHOD(addMenuItem:(NSString *)title)
|
|||
});
|
||||
}
|
||||
|
||||
- (std::shared_ptr<facebook::react::TurboModule>)getTurboModuleWithJsInvoker:(std::shared_ptr<facebook::react::CallInvoker>)jsInvoker
|
||||
{
|
||||
return std::make_shared<facebook::react::NativeDevSettingsSpecJSI>(self, jsInvoker);
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
#else // #if RCT_DEV
|
||||
|
||||
@interface RCTDevSettings () <NativeDevSettingsSpec>
|
||||
@end
|
||||
|
||||
@implementation RCTDevSettings
|
||||
|
||||
- (instancetype)initWithDataSource:(id<RCTDevSettingsDataSource>)dataSource
|
||||
|
@ -462,12 +473,35 @@ RCT_EXPORT_METHOD(addMenuItem:(NSString *)title)
|
|||
- (void)reload
|
||||
{
|
||||
}
|
||||
- (void)reloadWithReason
|
||||
- (void)reloadWithReason:(NSString *)reason
|
||||
{
|
||||
}
|
||||
- (void)onFastRefresh
|
||||
{
|
||||
}
|
||||
- (void)setHotLoadingEnabled:(BOOL)isHotLoadingEnabled
|
||||
{
|
||||
}
|
||||
- (void)setIsDebuggingRemotely:(BOOL)isDebuggingRemotelyEnabled
|
||||
{
|
||||
}
|
||||
- (void)setProfilingEnabled:(BOOL)isProfilingEnabled
|
||||
{
|
||||
}
|
||||
- (void)toggleElementInspector
|
||||
{
|
||||
}
|
||||
- (void)addMenuItem:(NSString *)title
|
||||
{
|
||||
}
|
||||
- (void)setIsShakeToShowDevMenuEnabled:(BOOL)enabled
|
||||
{
|
||||
}
|
||||
|
||||
- (std::shared_ptr<facebook::react::TurboModule>)getTurboModuleWithJsInvoker:(std::shared_ptr<facebook::react::CallInvoker>)jsInvoker
|
||||
{
|
||||
return std::make_shared<facebook::react::NativeDevSettingsSpecJSI>(self, jsInvoker);
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
|
@ -485,3 +519,7 @@ RCT_EXPORT_METHOD(addMenuItem:(NSString *)title)
|
|||
}
|
||||
|
||||
@end
|
||||
|
||||
Class RCTDevSettingsCls(void) {
|
||||
return RCTDevSettings.class;
|
||||
}
|
|
@ -0,0 +1,40 @@
|
|||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* <p>This source code is licensed under the MIT license found in the LICENSE file in the root
|
||||
* directory of this source tree.
|
||||
*
|
||||
* <p>Generated by an internal genrule from Flow types.
|
||||
*
|
||||
* @generated
|
||||
* @nolint
|
||||
*/
|
||||
|
||||
package com.facebook.fbreact.specs;
|
||||
|
||||
import com.facebook.react.bridge.ReactApplicationContext;
|
||||
import com.facebook.react.bridge.ReactContextBaseJavaModule;
|
||||
import com.facebook.react.bridge.ReactMethod;
|
||||
import com.facebook.react.bridge.ReactModuleWithSpec;
|
||||
import com.facebook.react.turbomodule.core.interfaces.TurboModule;
|
||||
|
||||
public abstract class NativeDevMenuSpec extends ReactContextBaseJavaModule implements ReactModuleWithSpec, TurboModule {
|
||||
public NativeDevMenuSpec(ReactApplicationContext reactContext) {
|
||||
super(reactContext);
|
||||
}
|
||||
|
||||
@ReactMethod
|
||||
public abstract void reload();
|
||||
|
||||
@ReactMethod
|
||||
public abstract void debugRemotely(boolean enableDebug);
|
||||
|
||||
@ReactMethod
|
||||
public abstract void setProfilingEnabled(boolean enabled);
|
||||
|
||||
@ReactMethod
|
||||
public abstract void show();
|
||||
|
||||
@ReactMethod
|
||||
public abstract void setHotLoadingEnabled(boolean enabled);
|
||||
}
|
Загрузка…
Ссылка в новой задаче