forked from facebook/react-native
-
Notifications
You must be signed in to change notification settings - Fork 145
/
Copy pathRCTDevMenu.mm
679 lines (570 loc) · 22.7 KB
/
RCTDevMenu.mm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
/*
* 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/RCTDevMenu.h>
#import <FBReactNativeSpec/FBReactNativeSpec.h>
#import <React/RCTBridge+Private.h>
#import <React/RCTBundleURLProvider.h>
#import <React/RCTDefines.h>
#import <React/RCTDevSettings.h>
#if !TARGET_OS_OSX // [macOS]
#import <React/RCTKeyCommands.h>
#endif // [macOS]
#import <React/RCTLog.h>
#import <React/RCTReloadCommand.h>
#import <React/RCTUtils.h>
#import "CoreModulesPlugins.h"
#if RCT_DEV_MENU
#if RCT_ENABLE_INSPECTOR
#import <React/RCTInspectorDevServerHelper.h>
#endif
@protocol RCTDevMenuItemProvider
- (RCTDevMenuItem *)devMenuItem;
@end
NSString *const RCTShowDevMenuNotification = @"RCTShowDevMenuNotification";
#if !TARGET_OS_OSX // [macOS]
// [macOS
typedef void (*MotionEndedWithEventImpType)(id self, SEL selector, UIEventSubtype motion, UIEvent *event);
static MotionEndedWithEventImpType RCTOriginalUIWindowMotionEndedWithEventImp = nil;
// macOS]
@implementation UIWindow (RCTDevMenu)
- (void)RCT_motionEnded:(__unused UIEventSubtype)motion withEvent:(UIEvent *)event
{
RCTOriginalUIWindowMotionEndedWithEventImp(self, @selector(motionEnded:withEvent:), motion, event); // [macOS]
if (event.subtype == UIEventSubtypeMotionShake) {
[[NSNotificationCenter defaultCenter] postNotificationName:RCTShowDevMenuNotification object:nil];
}
}
@end
#endif // [macOS]
@implementation RCTDevMenuItem {
RCTDevMenuItemTitleBlock _titleBlock;
dispatch_block_t _handler;
}
- (instancetype)initWithTitleBlock:(RCTDevMenuItemTitleBlock)titleBlock handler:(dispatch_block_t)handler
{
if ((self = [super init])) {
_titleBlock = [titleBlock copy];
_handler = [handler copy];
}
return self;
}
RCT_NOT_IMPLEMENTED(-(instancetype)init)
+ (instancetype)buttonItemWithTitleBlock:(NSString * (^)(void))titleBlock handler:(dispatch_block_t)handler
{
return [[self alloc] initWithTitleBlock:titleBlock handler:handler];
}
+ (instancetype)buttonItemWithTitle:(NSString *)title handler:(dispatch_block_t)handler
{
return [[self alloc]
initWithTitleBlock:^NSString * {
return title;
}
handler:handler];
}
- (void)callHandler
{
if (_handler) {
_handler();
}
}
- (NSString *)title
{
if (_titleBlock) {
return _titleBlock();
}
return nil;
}
@end
#if !TARGET_OS_OSX // [macOS]
typedef void (^RCTDevMenuAlertActionHandler)(UIAlertAction *action);
#endif // [macOS]
@interface RCTDevMenu () <RCTBridgeModule, RCTInvalidating, NativeDevMenuSpec>
@end
@implementation RCTDevMenu {
#if !TARGET_OS_OSX // [macOS]
UIAlertController *_actionSheet;
#endif // [macOS]
NSMutableArray<RCTDevMenuItem *> *_extraMenuItems;
}
@synthesize bridge = _bridge;
@synthesize moduleRegistry = _moduleRegistry;
@synthesize callableJSModules = _callableJSModules;
@synthesize bundleManager = _bundleManager;
RCT_EXPORT_MODULE()
+ (void)initialize
{
#if !TARGET_OS_OSX // [macOS]
// We're swizzling here because it's poor form to override methods in a category,
RCTOriginalUIWindowMotionEndedWithEventImp = (MotionEndedWithEventImpType) RCTSwapInstanceMethods([UIWindow class], @selector(motionEnded:withEvent:), @selector(RCT_motionEnded:withEvent:)); // [macOS]
#endif // [macOS]
}
+ (BOOL)requiresMainQueueSetup
{
return YES;
}
- (instancetype)init
{
if ((self = [super init])) {
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(showOnShake)
name:RCTShowDevMenuNotification
object:nil];
_extraMenuItems = [NSMutableArray new];
[self registerHotkeys];
}
return self;
}
- (void)registerHotkeys
{
#if TARGET_OS_SIMULATOR || TARGET_OS_MACCATALYST
RCTKeyCommands *commands = [RCTKeyCommands sharedInstance];
__weak __typeof(self) weakSelf = self;
// Toggle debug menu
[commands registerKeyCommandWithInput:@"d"
modifierFlags:UIKeyModifierCommand
action:^(__unused UIKeyCommand *command) {
[weakSelf toggle];
}];
// Toggle element inspector
[commands registerKeyCommandWithInput:@"i"
modifierFlags:UIKeyModifierCommand
action:^(__unused UIKeyCommand *command) {
[(RCTDevSettings *)[weakSelf.moduleRegistry moduleForName:"DevSettings"]
toggleElementInspector];
}];
// Reload in normal mode
[commands registerKeyCommandWithInput:@"n"
modifierFlags:UIKeyModifierCommand
action:^(__unused UIKeyCommand *command) {
[(RCTDevSettings *)[weakSelf.moduleRegistry moduleForName:"DevSettings"]
setIsDebuggingRemotely:NO];
}];
#endif
}
- (void)unregisterHotkeys
{
#if TARGET_OS_SIMULATOR || TARGET_OS_MACCATALYST
RCTKeyCommands *commands = [RCTKeyCommands sharedInstance];
[commands unregisterKeyCommandWithInput:@"d" modifierFlags:UIKeyModifierCommand];
[commands unregisterKeyCommandWithInput:@"i" modifierFlags:UIKeyModifierCommand];
[commands unregisterKeyCommandWithInput:@"n" modifierFlags:UIKeyModifierCommand];
#endif
}
- (BOOL)isHotkeysRegistered
{
#if TARGET_OS_SIMULATOR || TARGET_OS_MACCATALYST
RCTKeyCommands *commands = [RCTKeyCommands sharedInstance];
return [commands isKeyCommandRegisteredForInput:@"d" modifierFlags:UIKeyModifierCommand] &&
[commands isKeyCommandRegisteredForInput:@"i" modifierFlags:UIKeyModifierCommand] &&
[commands isKeyCommandRegisteredForInput:@"n" modifierFlags:UIKeyModifierCommand];
#else
return NO;
#endif
}
- (dispatch_queue_t)methodQueue
{
return dispatch_get_main_queue();
}
- (void)invalidate
{
_presentedItems = nil;
#if !TARGET_OS_OSX // [macOS]
[_actionSheet dismissViewControllerAnimated:YES
completion:^(void){
}];
#endif // [macOS]
}
- (void)showOnShake
{
if ([((RCTDevSettings *)[_moduleRegistry moduleForName:"DevSettings"]) isShakeToShowDevMenuEnabled]) {
for (RCTPlatformWindow *window in [RCTSharedApplication() windows]) {
NSString *recursiveDescription = [window valueForKey:@"recursiveDescription"];
if ([recursiveDescription containsString:@"RCTView"]) {
[self show];
return;
}
}
}
}
#if !TARGET_OS_OSX // [macOS]
- (void)toggle
{
if (_actionSheet.isBeingPresented || _actionSheet.beingDismissed) {
return;
}
if (_actionSheet) {
[_actionSheet dismissViewControllerAnimated:YES
completion:^(void) {
self->_actionSheet = nil;
}];
} else {
[self show];
}
}
- (BOOL)isActionSheetShown
{
return _actionSheet != nil;
}
#endif // [macOS]
- (void)addItem:(NSString *)title handler:(void (^)(void))handler
{
[self addItem:[RCTDevMenuItem buttonItemWithTitle:title handler:handler]];
}
- (void)addItem:(RCTDevMenuItem *)item
{
[_extraMenuItems addObject:item];
}
- (void)setDefaultJSBundle
{
[[RCTBundleURLProvider sharedSettings] resetToDefaults];
self->_bundleManager.bundleURL = [[RCTBundleURLProvider sharedSettings] jsBundleURLForFallbackExtension:nil];
RCTTriggerReloadCommandListeners(@"Dev menu - reset to default");
}
- (NSArray<RCTDevMenuItem *> *)_menuItemsToPresent
{
NSMutableArray<RCTDevMenuItem *> *items = [NSMutableArray new];
// Add built-in items
__weak RCTDevSettings *devSettings = [_moduleRegistry moduleForName:"DevSettings"];
__weak RCTDevMenu *weakSelf = self;
__weak RCTBundleManager *bundleManager = _bundleManager;
[items addObject:[RCTDevMenuItem buttonItemWithTitle:@"Reload"
handler:^{
RCTTriggerReloadCommandListeners(@"Dev menu - reload");
}]];
if (!devSettings.isProfilingEnabled) {
#if RCT_ENABLE_INSPECTOR
if (devSettings.isDeviceDebuggingAvailable) {
// On-device JS debugging (CDP). Render action to open debugger frontend.
BOOL isDisconnected = RCTInspectorDevServerHelper.isPackagerDisconnected;
NSString *title = isDisconnected
? [NSString stringWithFormat:@"Connect to %@ to debug JavaScript", RCT_PACKAGER_NAME]
: @"Open DevTools";
RCTDevMenuItem *item = [RCTDevMenuItem
buttonItemWithTitle:title
handler:^{
[RCTInspectorDevServerHelper
openDebugger:bundleManager.bundleURL
withErrorMessage:
@"Failed to open debugger. Please check that the dev server is running and reload the app."];
}];
[item setDisabled:isDisconnected];
[items addObject:item];
}
#endif
}
[items addObject:[RCTDevMenuItem
buttonItemWithTitleBlock:^NSString * {
return @"Toggle Element Inspector";
}
handler:^{
[devSettings toggleElementInspector];
}]];
if (devSettings.isHotLoadingAvailable) {
[items addObject:[RCTDevMenuItem
buttonItemWithTitleBlock:^NSString * {
// Previously known as "Hot Reloading". We won't use this term anymore.
return devSettings.isHotLoadingEnabled ? @"Disable Fast Refresh" : @"Enable Fast Refresh";
}
handler:^{
devSettings.isHotLoadingEnabled = !devSettings.isHotLoadingEnabled;
}]];
}
#if !TARGET_OS_OSX // [macOS]
id perfMonitorItemOpaque = [_moduleRegistry moduleForName:"PerfMonitor"];
SEL devMenuItem = @selector(devMenuItem);
if ([perfMonitorItemOpaque respondsToSelector:devMenuItem]) {
RCTDevMenuItem *perfMonitorItem = [perfMonitorItemOpaque devMenuItem];
[items addObject:perfMonitorItem];
}
#endif // [macOS]
[items
addObject:[RCTDevMenuItem
buttonItemWithTitleBlock:^NSString * {
return @"Configure Bundler";
}
handler:^{
#if !TARGET_OS_OSX // [macOS]
UIAlertController *alertController = [UIAlertController
alertControllerWithTitle:@"Configure Bundler"
message:@"Provide a custom bundler address, port, and entrypoint."
preferredStyle:UIAlertControllerStyleAlert];
[alertController addTextFieldWithConfigurationHandler:^(UITextField *textField) {
textField.placeholder = @"0.0.0.0";
}];
[alertController addTextFieldWithConfigurationHandler:^(UITextField *textField) {
textField.placeholder = @"8081";
}];
[alertController addTextFieldWithConfigurationHandler:^(UITextField *textField) {
textField.placeholder = @"index";
}];
[alertController
addAction:[UIAlertAction
actionWithTitle:@"Apply Changes"
style:UIAlertActionStyleDefault
handler:^(__unused UIAlertAction *action) {
NSArray *textfields = alertController.textFields;
UITextField *ipTextField = textfields[0];
UITextField *portTextField = textfields[1];
UITextField *bundleRootTextField = textfields[2];
NSString *bundleRoot = bundleRootTextField.text;
if (ipTextField.text.length == 0 && portTextField.text.length == 0) {
[weakSelf setDefaultJSBundle];
return;
}
NSNumberFormatter *formatter = [NSNumberFormatter new];
formatter.numberStyle = NSNumberFormatterDecimalStyle;
NSNumber *portNumber =
[formatter numberFromString:portTextField.text];
if (portNumber == nil) {
portNumber = [NSNumber numberWithInt:RCT_METRO_PORT];
}
[RCTBundleURLProvider sharedSettings].jsLocation = [NSString
stringWithFormat:@"%@:%d", ipTextField.text, portNumber.intValue];
if (bundleRoot.length == 0) {
[bundleManager resetBundleURL];
} else {
bundleManager.bundleURL = [[RCTBundleURLProvider sharedSettings]
jsBundleURLForBundleRoot:bundleRoot];
}
RCTTriggerReloadCommandListeners(@"Dev menu - apply changes");
}]];
[alertController addAction:[UIAlertAction actionWithTitle:@"Reset to Default"
style:UIAlertActionStyleDefault
handler:^(__unused UIAlertAction *action) {
[weakSelf setDefaultJSBundle];
}]];
[alertController addAction:[UIAlertAction actionWithTitle:@"Cancel"
style:UIAlertActionStyleCancel
handler:^(__unused UIAlertAction *action) {
return;
}]];
[RCTPresentedViewController() presentViewController:alertController animated:YES completion:NULL];
#else // [macOS
NSAlert *alert = [NSAlert new];
[alert setMessageText:@"Change packager location"];
[alert setInformativeText:@"Input packager IP, port and entrypoint"];
[alert addButtonWithTitle:@"Use bundled JS"];
[alert setAlertStyle:NSWarningAlertStyle];
[alert beginSheetModalForWindow:[NSApp keyWindow] completionHandler:nil];
#endif // macOS]
}]];
[items addObjectsFromArray:_extraMenuItems];
return items;
}
RCT_EXPORT_METHOD(show)
{
#if !TARGET_OS_OSX // [macOS]
if (_actionSheet || RCTRunningInAppExtension()) {
return;
}
NSString *bridgeDescription = _bridge.bridgeDescription;
NSString *description =
bridgeDescription.length > 0 ? [NSString stringWithFormat:@"Running %@", bridgeDescription] : nil;
// On larger devices we don't have an anchor point for the action sheet
UIAlertControllerStyle style = [[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone
? UIAlertControllerStyleActionSheet
: UIAlertControllerStyleAlert;
NSString *devMenuType = [self.bridge isKindOfClass:RCTBridge.class] ? @"Bridge" : @"Bridgeless";
NSString *devMenuTitle = [NSString stringWithFormat:@"React Native Dev Menu (%@)", devMenuType];
_actionSheet = [UIAlertController alertControllerWithTitle:devMenuTitle message:description preferredStyle:style];
NSArray<RCTDevMenuItem *> *items = [self _menuItemsToPresent];
for (RCTDevMenuItem *item in items) {
UIAlertAction *action = [UIAlertAction actionWithTitle:item.title
style:UIAlertActionStyleDefault
handler:[self alertActionHandlerForDevItem:item]];
[action setEnabled:!item.isDisabled];
[_actionSheet addAction:action];
}
[_actionSheet addAction:[UIAlertAction actionWithTitle:@"Cancel"
style:UIAlertActionStyleCancel
handler:[self alertActionHandlerForDevItem:nil]]];
_presentedItems = items;
[RCTPresentedViewController() presentViewController:_actionSheet animated:YES completion:nil];
#else // [macOS
NSMenu *menu = [self menu];
NSWindow *window = [NSApp keyWindow];
NSEvent *event = [NSEvent mouseEventWithType:NSLeftMouseUp location:CGPointMake(0, 0) modifierFlags:0 timestamp:NSTimeIntervalSince1970 windowNumber:[window windowNumber] context:nil eventNumber:0 clickCount:0 pressure:0.1];
[NSMenu popUpContextMenu:menu withEvent:event forView:[window contentView]];
#endif // macOS]
[_callableJSModules invokeModule:@"RCTNativeAppEventEmitter" method:@"emit" withArgs:@[ @"RCTDevMenuShown" ]];
}
#if !TARGET_OS_OSX // [macOS]
- (RCTDevMenuAlertActionHandler)alertActionHandlerForDevItem:(RCTDevMenuItem *__nullable)item
{
return ^(__unused UIAlertAction *action) {
if (item) {
[item callHandler];
}
self->_actionSheet = nil;
};
}
#else // [macOS
- (NSMenu *)menu
{
if ([_bridge.devSettings isSecondaryClickToShowDevMenuEnabled]) {
NSMenu *menu = nil;
if (_bridge) {
NSString *desc = _bridge.bridgeDescription;
if (desc.length == 0) {
desc = NSStringFromClass([_bridge class]);
}
NSString *title = [NSString stringWithFormat:@"React Native: Development\n(%@)", desc];
menu = [NSMenu new];
NSMutableAttributedString *attributedTitle = [[NSMutableAttributedString alloc]initWithString:title];
[attributedTitle setAttributes: @{ NSFontAttributeName : [NSFont menuFontOfSize:0] } range: NSMakeRange(0, [attributedTitle length])];
NSMenuItem *titleItem = [NSMenuItem new];
[titleItem setAttributedTitle:attributedTitle];
[menu addItem:titleItem];
[menu addItem:[NSMenuItem separatorItem]];
NSArray<RCTDevMenuItem *> *items = [self _menuItemsToPresent];
for (RCTDevMenuItem *item in items) {
NSMenuItem *menuItem = [[NSMenuItem alloc] initWithTitle:[item title] action:@selector(menuItemSelected:) keyEquivalent:@""];
[menuItem setTarget:self];
[menuItem setRepresentedObject:item];
[menu addItem:menuItem];
}
}
return menu;
}
return nil;
}
-(void)menuItemSelected:(id)sender
{
NSMenuItem *menuItem = (NSMenuItem *)sender;
RCTDevMenuItem *item = (RCTDevMenuItem *)[menuItem representedObject];
[item callHandler];
}
- (void)setSecondaryClickToShow:(BOOL)secondaryClickToShow
{
_bridge.devSettings.isSecondaryClickToShowDevMenuEnabled = secondaryClickToShow;
}
#endif // macOS]
#pragma mark - deprecated methods and properties
#define WARN_DEPRECATED_DEV_MENU_EXPORT() \
RCTLogWarn(@"Using deprecated method %s, use RCTDevSettings instead", __func__)
- (void)setShakeToShow:(BOOL)shakeToShow
{
((RCTDevSettings *)[_moduleRegistry moduleForName:"DevSettings"]).isShakeToShowDevMenuEnabled = shakeToShow;
}
- (BOOL)shakeToShow
{
return ((RCTDevSettings *)[_moduleRegistry moduleForName:"DevSettings"]).isShakeToShowDevMenuEnabled;
}
RCT_EXPORT_METHOD(reload)
{
WARN_DEPRECATED_DEV_MENU_EXPORT();
RCTTriggerReloadCommandListeners(@"Unknown from JS");
}
RCT_EXPORT_METHOD(debugRemotely : (BOOL)enableDebug)
{
WARN_DEPRECATED_DEV_MENU_EXPORT();
((RCTDevSettings *)[_moduleRegistry moduleForName:"DevSettings"]).isDebuggingRemotely = enableDebug;
}
RCT_EXPORT_METHOD(setProfilingEnabled : (BOOL)enabled)
{
WARN_DEPRECATED_DEV_MENU_EXPORT();
((RCTDevSettings *)[_moduleRegistry moduleForName:"DevSettings"]).isProfilingEnabled = enabled;
}
- (BOOL)profilingEnabled
{
return ((RCTDevSettings *)[_moduleRegistry moduleForName:"DevSettings"]).isProfilingEnabled;
}
RCT_EXPORT_METHOD(setHotLoadingEnabled : (BOOL)enabled)
{
WARN_DEPRECATED_DEV_MENU_EXPORT();
((RCTDevSettings *)[_moduleRegistry moduleForName:"DevSettings"]).isHotLoadingEnabled = enabled;
}
- (BOOL)hotLoadingEnabled
{
return ((RCTDevSettings *)[_moduleRegistry moduleForName:"DevSettings"]).isHotLoadingEnabled;
}
- (void)setHotkeysEnabled:(BOOL)enabled
{
if (enabled) {
[self registerHotkeys];
} else {
[self unregisterHotkeys];
}
}
- (BOOL)hotkeysEnabled
{
return [self isHotkeysRegistered];
}
- (std::shared_ptr<facebook::react::TurboModule>)getTurboModule:
(const facebook::react::ObjCTurboModule::InitParams &)params
{
return std::make_shared<facebook::react::NativeDevMenuSpecJSI>(params);
}
@end
#else // Unavailable when not in dev mode
@interface RCTDevMenu () <NativeDevMenuSpec>
@end
@implementation RCTDevMenu
- (void)show
{
}
- (void)reload
{
}
- (void)addItem:(NSString *)title handler:(dispatch_block_t)handler
{
}
- (void)addItem:(RCTDevMenu *)item
{
}
- (void)debugRemotely:(BOOL)enableDebug
{
}
- (BOOL)isActionSheetShown
{
return NO;
}
+ (NSString *)moduleName
{
return @"DevMenu";
}
- (std::shared_ptr<facebook::react::TurboModule>)getTurboModule:
(const facebook::react::ObjCTurboModule::InitParams &)params
{
return std::make_shared<facebook::react::NativeDevMenuSpecJSI>(params);
}
@end
@implementation RCTDevMenuItem
+ (instancetype)buttonItemWithTitle:(NSString *)title handler:(void (^)(void))handler
{
return nil;
}
+ (instancetype)buttonItemWithTitleBlock:(NSString * (^)(void))titleBlock handler:(void (^)(void))handler
{
return nil;
}
@end
#endif
@implementation RCTBridge (RCTDevMenu)
- (RCTDevMenu *)devMenu
{
#if RCT_DEV_MENU
return [self moduleForClass:[RCTDevMenu class]];
#else
return nil;
#endif
}
@end
@implementation RCTBridgeProxy (RCTDevMenu)
- (RCTDevMenu *)devMenu
{
#if RCT_DEV_MENU
return [self moduleForClass:[RCTDevMenu class]];
#else
return nil;
#endif
}
@end
Class RCTDevMenuCls(void)
{
return RCTDevMenu.class;
}