Skip to content

Commit fe3ae9d

Browse files
RSNarafacebook-github-bot
authored andcommitted
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
1 parent 686ab49 commit fe3ae9d

File tree

13 files changed

+227
-18
lines changed

13 files changed

+227
-18
lines changed

Libraries/FBReactNativeSpec/FBReactNativeSpec/FBReactNativeSpec-generated.mm

+48
Original file line numberDiff line numberDiff line change
@@ -766,6 +766,54 @@ + (RCTManagedPointer *)JS_NativeAsyncStorage_SpecGetAllKeysCallbackError:(id)jso
766766

767767

768768

769+
}
770+
771+
} // namespace react
772+
} // namespace facebook
773+
namespace facebook {
774+
namespace react {
775+
776+
777+
static facebook::jsi::Value __hostFunction_NativeDevMenuSpecJSI_show(facebook::jsi::Runtime& rt, TurboModule &turboModule, const facebook::jsi::Value* args, size_t count) {
778+
return static_cast<ObjCTurboModule&>(turboModule).invokeObjCMethod(rt, VoidKind, "show", @selector(show), args, count);
779+
}
780+
781+
static facebook::jsi::Value __hostFunction_NativeDevMenuSpecJSI_reload(facebook::jsi::Runtime& rt, TurboModule &turboModule, const facebook::jsi::Value* args, size_t count) {
782+
return static_cast<ObjCTurboModule&>(turboModule).invokeObjCMethod(rt, VoidKind, "reload", @selector(reload), args, count);
783+
}
784+
785+
static facebook::jsi::Value __hostFunction_NativeDevMenuSpecJSI_debugRemotely(facebook::jsi::Runtime& rt, TurboModule &turboModule, const facebook::jsi::Value* args, size_t count) {
786+
return static_cast<ObjCTurboModule&>(turboModule).invokeObjCMethod(rt, VoidKind, "debugRemotely", @selector(debugRemotely:), args, count);
787+
}
788+
789+
static facebook::jsi::Value __hostFunction_NativeDevMenuSpecJSI_setProfilingEnabled(facebook::jsi::Runtime& rt, TurboModule &turboModule, const facebook::jsi::Value* args, size_t count) {
790+
return static_cast<ObjCTurboModule&>(turboModule).invokeObjCMethod(rt, VoidKind, "setProfilingEnabled", @selector(setProfilingEnabled:), args, count);
791+
}
792+
793+
static facebook::jsi::Value __hostFunction_NativeDevMenuSpecJSI_setHotLoadingEnabled(facebook::jsi::Runtime& rt, TurboModule &turboModule, const facebook::jsi::Value* args, size_t count) {
794+
return static_cast<ObjCTurboModule&>(turboModule).invokeObjCMethod(rt, VoidKind, "setHotLoadingEnabled", @selector(setHotLoadingEnabled:), args, count);
795+
}
796+
797+
798+
NativeDevMenuSpecJSI::NativeDevMenuSpecJSI(id<RCTTurboModule> instance, std::shared_ptr<CallInvoker> jsInvoker)
799+
: ObjCTurboModule("DevMenu", instance, jsInvoker) {
800+
801+
methodMap_["show"] = MethodMetadata {0, __hostFunction_NativeDevMenuSpecJSI_show};
802+
803+
804+
methodMap_["reload"] = MethodMetadata {0, __hostFunction_NativeDevMenuSpecJSI_reload};
805+
806+
807+
methodMap_["debugRemotely"] = MethodMetadata {1, __hostFunction_NativeDevMenuSpecJSI_debugRemotely};
808+
809+
810+
methodMap_["setProfilingEnabled"] = MethodMetadata {1, __hostFunction_NativeDevMenuSpecJSI_setProfilingEnabled};
811+
812+
813+
methodMap_["setHotLoadingEnabled"] = MethodMetadata {1, __hostFunction_NativeDevMenuSpecJSI_setHotLoadingEnabled};
814+
815+
816+
769817
}
770818

771819
} // namespace react

Libraries/FBReactNativeSpec/FBReactNativeSpec/FBReactNativeSpec.h

+22
Original file line numberDiff line numberDiff line change
@@ -705,6 +705,28 @@ namespace facebook {
705705
};
706706
} // namespace react
707707
} // namespace facebook
708+
@protocol NativeDevMenuSpec <RCTBridgeModule, RCTTurboModule>
709+
710+
- (void)show;
711+
- (void)reload;
712+
- (void)debugRemotely:(BOOL)enableDebug;
713+
- (void)setProfilingEnabled:(BOOL)enabled;
714+
- (void)setHotLoadingEnabled:(BOOL)enabled;
715+
716+
@end
717+
namespace facebook {
718+
namespace react {
719+
/**
720+
* ObjC++ class for module 'DevMenu'
721+
*/
722+
723+
class JSI_EXPORT NativeDevMenuSpecJSI : public ObjCTurboModule {
724+
public:
725+
NativeDevMenuSpecJSI(id<RCTTurboModule> instance, std::shared_ptr<CallInvoker> jsInvoker);
726+
727+
};
728+
} // namespace react
729+
} // namespace facebook
708730
@protocol NativeDevSettingsSpec <RCTBridgeModule, RCTTurboModule>
709731

710732
- (void)reload;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/**
2+
* Copyright (c) Facebook, Inc. and its 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 strict-local
8+
* @format
9+
*/
10+
11+
'use strict';
12+
13+
import type {TurboModule} from '../../TurboModule/RCTExport';
14+
import * as TurboModuleRegistry from '../../TurboModule/TurboModuleRegistry';
15+
16+
export interface Spec extends TurboModule {
17+
+show: () => void;
18+
+reload: () => void;
19+
+debugRemotely: (enableDebug: boolean) => void;
20+
+setProfilingEnabled: (enabled: boolean) => void;
21+
+setHotLoadingEnabled: (enabled: boolean) => void;
22+
}
23+
24+
export default (TurboModuleRegistry.getEnforcing<Spec>('DevMenu'): Spec);

RNTester/Podfile.lock

+2-1
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,7 @@ PODS:
237237
- ReactCommon/turbomodule/core (= 1000.0.0)
238238
- React-RCTTest (1000.0.0):
239239
- React-Core (= 1000.0.0)
240+
- React-CoreModules (= 1000.0.0)
240241
- React-RCTText (1000.0.0):
241242
- React-Core/RCTTextHeaders (= 1000.0.0)
242243
- React-RCTVibration (1000.0.0):
@@ -389,7 +390,7 @@ SPEC CHECKSUMS:
389390
React-RCTNetwork: c8f9d40297f35ea3792ea81866f33e8b45c25935
390391
React-RCTPushNotification: acffa8af6a20e6d41b041a8c4cb4bea0de9df0dd
391392
React-RCTSettings: 8138286da8de74839cb436dd37704ed64d4bfe78
392-
React-RCTTest: 73df09ec226fcad6e7e058a313e5dd16cccf86a8
393+
React-RCTTest: d148e0657ce77ffd43a10325c284f47f25fb0532
393394
React-RCTText: 9078167d3bc011162326f2d8ef4dd580ec1eca17
394395
React-RCTVibration: e3269787c533de8c4f54f489202d848fdef33e1d
395396
ReactCommon: 9d212865526209dc2d01be40340c8d27b53e6bea

RNTester/RCTTest/React-RCTTest.podspec

+2-1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ Pod::Spec.new do |s|
2929
s.preserve_paths = "package.json", "LICENSE", "LICENSE-docs"
3030
s.framework = "XCTest"
3131
s.header_dir = "RCTTest"
32-
32+
3333
s.dependency "React-Core", version
34+
s.dependency "React-CoreModules", version
3435
end

React/CoreModules/BUCK

+6
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,12 @@ rn_apple_library(
8787
) + react_module_plugin_providers(
8888
name = "PerfMonitor",
8989
native_class_func = "RCTPerfMonitorCls",
90+
) + react_module_plugin_providers(
91+
name = "DevMenu",
92+
native_class_func = "RCTDevMenuCls",
93+
) + react_module_plugin_providers(
94+
name = "DevSettings",
95+
native_class_func = "RCTDevSettingsCls",
9096
),
9197
plugins_header = "FBCoreModulesPlugins.h",
9298
preprocessor_flags = OBJC_ARC_PREPROCESSOR_FLAGS + get_debug_preprocessor_flags() + rn_extra_build_flags() + [

React/CoreModules/CoreModulesPlugins.h

+2
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ Class RCTStatusBarManagerCls(void) __attribute__((used));
4545
Class RCTKeyboardObserverCls(void) __attribute__((used));
4646
Class RCTAppStateCls(void) __attribute__((used));
4747
Class RCTPerfMonitorCls(void) __attribute__((used));
48+
Class RCTDevMenuCls(void) __attribute__((used));
49+
Class RCTDevSettingsCls(void) __attribute__((used));
4850

4951
#ifdef __cplusplus
5052
}

React/CoreModules/CoreModulesPlugins.mm

+2
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ Class RCTCoreModulesClassProvider(const char *name) {
3434
{"KeyboardObserver", RCTKeyboardObserverCls},
3535
{"AppState", RCTAppStateCls},
3636
{"PerfMonitor", RCTPerfMonitorCls},
37+
{"DevMenu", RCTDevMenuCls},
38+
{"DevSettings", RCTDevSettingsCls},
3739
};
3840

3941
auto p = sCoreModuleClassMap.find(name);
File renamed without changes.

React/DevSupport/RCTDevMenu.m React/CoreModules/RCTDevMenu.mm

+29-4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
#import <React/RCTDevMenu.h>
99

10+
#import <FBReactNativeSpec/FBReactNativeSpec.h>
1011
#import <React/RCTBridge+Private.h>
1112
#import <React/RCTBundleURLProvider.h>
1213
#import <React/RCTDefines.h>
@@ -16,6 +17,8 @@
1617
#import <React/RCTReloadCommand.h>
1718
#import <React/RCTUtils.h>
1819

20+
#import "CoreModulesPlugins.h"
21+
1922
#if RCT_DEV_MENU
2023

2124
#if RCT_ENABLE_INSPECTOR
@@ -84,7 +87,7 @@ - (NSString *)title
8487

8588
typedef void (^RCTDevMenuAlertActionHandler)(UIAlertAction *action);
8689

87-
@interface RCTDevMenu () <RCTBridgeModule, RCTInvalidating>
90+
@interface RCTDevMenu () <RCTBridgeModule, RCTInvalidating, NativeDevMenuSpec>
8891

8992
@end
9093

@@ -229,7 +232,7 @@ - (void)setDefaultJSBundle
229232
[UIAlertController alertControllerWithTitle:@"Debugger Unavailable"
230233
message:message
231234
preferredStyle:UIAlertControllerStyleAlert];
232-
__weak typeof(alertController) weakAlertController = alertController;
235+
__weak __typeof__(alertController) weakAlertController = alertController;
233236
[alertController
234237
addAction:[UIAlertAction actionWithTitle:@"OK"
235238
style:UIAlertActionStyleDefault
@@ -301,7 +304,7 @@ - (void)setDefaultJSBundle
301304
[UIAlertController alertControllerWithTitle:@"Systrace Unavailable"
302305
message:@"Stop debugging to enable Systrace."
303306
preferredStyle:UIAlertControllerStyleAlert];
304-
__weak typeof(alertController) weakAlertController = alertController;
307+
__weak __typeof__(alertController) weakAlertController = alertController;
305308
[alertController
306309
addAction:[UIAlertAction actionWithTitle:@"OK"
307310
style:UIAlertActionStyleDefault
@@ -490,10 +493,18 @@ - (BOOL)hotLoadingEnabled
490493
return _bridge.devSettings.isHotLoadingEnabled;
491494
}
492495

496+
- (std::shared_ptr<facebook::react::TurboModule>)getTurboModuleWithJsInvoker:(std::shared_ptr<facebook::react::CallInvoker>)jsInvoker
497+
{
498+
return std::make_shared<facebook::react::NativeDevMenuSpecJSI>(self, jsInvoker);
499+
}
500+
493501
@end
494502

495503
#else // Unavailable when not in dev mode
496504

505+
@interface RCTDevMenu() <NativeDevMenuSpec>
506+
@end
507+
497508
@implementation RCTDevMenu
498509

499510
- (void)show
@@ -508,13 +519,23 @@ - (void)addItem:(NSString *)title handler:(dispatch_block_t)handler
508519
- (void)addItem:(RCTDevMenu *)item
509520
{
510521
}
522+
523+
- (void)debugRemotely : (BOOL)enableDebug
524+
{
525+
}
526+
511527
- (BOOL)isActionSheetShown
512528
{
513529
return NO;
514530
}
515531
+ (NSString *)moduleName
516532
{
517-
return @"";
533+
return @"DevMenu";
534+
}
535+
536+
- (std::shared_ptr<facebook::react::TurboModule>)getTurboModuleWithJsInvoker:(std::shared_ptr<facebook::react::CallInvoker>)jsInvoker
537+
{
538+
return std::make_shared<facebook::react::NativeDevMenuSpecJSI>(self, jsInvoker);
518539
}
519540

520541
@end
@@ -546,3 +567,7 @@ - (RCTDevMenu *)devMenu
546567
}
547568

548569
@end
570+
571+
Class RCTDevMenuCls(void) {
572+
return RCTDevMenu.class;
573+
}
File renamed without changes.

React/Modules/RCTDevSettings.mm React/CoreModules/RCTDevSettings.mm

+50-12
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,19 @@
99

1010
#import <objc/runtime.h>
1111

12-
#import "RCTBridge+Private.h"
13-
#import "RCTBridgeModule.h"
14-
#import "RCTEventDispatcher.h"
15-
#import "RCTLog.h"
16-
#import "RCTProfile.h"
17-
#import "RCTReloadCommand.h"
18-
#import "RCTUtils.h"
12+
#import <FBReactNativeSpec/FBReactNativeSpec.h>
13+
#import <React/RCTBridge+Private.h>
14+
#import <React/RCTBridgeModule.h>
15+
#import <React/RCTEventDispatcher.h>
16+
#import <React/RCTLog.h>
17+
#import <React/RCTProfile.h>
18+
#import <React/RCTReloadCommand.h>
19+
#import <React/RCTUtils.h>
1920

2021
#import <React/RCTDevMenu.h>
2122

23+
#import "CoreModulesPlugins.h"
24+
2225
static NSString *const kRCTDevSettingProfilingEnabled = @"profilingEnabled";
2326
static NSString *const kRCTDevSettingHotLoadingEnabled = @"hotLoadingEnabled";
2427
static NSString *const kRCTDevSettingIsInspectorShown = @"showInspector";
@@ -30,12 +33,12 @@
3033
static NSString *const kRCTDevSettingsUserDefaultsKey = @"RCTDevMenu";
3134

3235
#if ENABLE_PACKAGER_CONNECTION
33-
#import "RCTPackagerClient.h"
34-
#import "RCTPackagerConnection.h"
36+
#import <React/RCTPackagerClient.h>
37+
#import <React/RCTPackagerConnection.h>
3538
#endif
3639

3740
#if RCT_ENABLE_INSPECTOR
38-
#import "RCTInspectorDevServerHelper.h"
41+
#import <React/RCTInspectorDevServerHelper.h>
3942
#endif
4043

4144
#if RCT_DEV
@@ -110,7 +113,7 @@ - (void)_reloadWithDefaults:(NSDictionary *)defaultValues
110113

111114
@end
112115

113-
@interface RCTDevSettings () <RCTBridgeModule, RCTInvalidating> {
116+
@interface RCTDevSettings () <RCTBridgeModule, RCTInvalidating, NativeDevSettingsSpec> {
114117
BOOL _isJSLoaded;
115118
#if ENABLE_PACKAGER_CONNECTION
116119
RCTHandlerToken _reloadToken;
@@ -437,10 +440,18 @@ - (void)jsLoaded:(NSNotification *)notification
437440
});
438441
}
439442

443+
- (std::shared_ptr<facebook::react::TurboModule>)getTurboModuleWithJsInvoker:(std::shared_ptr<facebook::react::CallInvoker>)jsInvoker
444+
{
445+
return std::make_shared<facebook::react::NativeDevSettingsSpecJSI>(self, jsInvoker);
446+
}
447+
440448
@end
441449

442450
#else // #if RCT_DEV
443451

452+
@interface RCTDevSettings () <NativeDevSettingsSpec>
453+
@end
454+
444455
@implementation RCTDevSettings
445456

446457
- (instancetype)initWithDataSource:(id<RCTDevSettingsDataSource>)dataSource
@@ -462,12 +473,35 @@ - (id)settingForKey:(NSString *)key
462473
- (void)reload
463474
{
464475
}
465-
- (void)reloadWithReason
476+
- (void)reloadWithReason:(NSString *)reason
477+
{
478+
}
479+
- (void)onFastRefresh
480+
{
481+
}
482+
- (void)setHotLoadingEnabled:(BOOL)isHotLoadingEnabled
483+
{
484+
}
485+
- (void)setIsDebuggingRemotely:(BOOL)isDebuggingRemotelyEnabled
486+
{
487+
}
488+
- (void)setProfilingEnabled:(BOOL)isProfilingEnabled
466489
{
467490
}
468491
- (void)toggleElementInspector
469492
{
470493
}
494+
- (void)addMenuItem:(NSString *)title
495+
{
496+
}
497+
- (void)setIsShakeToShowDevMenuEnabled:(BOOL)enabled
498+
{
499+
}
500+
501+
- (std::shared_ptr<facebook::react::TurboModule>)getTurboModuleWithJsInvoker:(std::shared_ptr<facebook::react::CallInvoker>)jsInvoker
502+
{
503+
return std::make_shared<facebook::react::NativeDevSettingsSpecJSI>(self, jsInvoker);
504+
}
471505

472506
@end
473507

@@ -485,3 +519,7 @@ - (RCTDevSettings *)devSettings
485519
}
486520

487521
@end
522+
523+
Class RCTDevSettingsCls(void) {
524+
return RCTDevSettings.class;
525+
}

0 commit comments

Comments
 (0)