|
15 | 15 |
|
16 | 16 | #if __has_include(<React/RCTDevMenu.h>) && RCT_DEV |
17 | 17 | #import <React/RCTDevMenu.h> |
| 18 | +#import <React/RCTSurfacePresenter.h> |
| 19 | +#import <react/utils/ContextContainer.h> |
| 20 | +#import <react/utils/ManagedObjectWrapper.h> |
18 | 21 | #endif |
19 | 22 |
|
20 | 23 | @interface RCTSurfaceHostingView () |
@@ -287,11 +290,30 @@ - (NSMenu *)menuForEvent:(NSEvent *)event |
287 | 290 | { |
288 | 291 | NSMenu *menu = nil; |
289 | 292 | #if __has_include(<React/RCTDevMenu.h>) && RCT_DEV |
290 | | - // In Fabric/bridgeless mode, trigger the dev menu via notification |
291 | | - // This is bridge-independent and works without accessing the bridge |
292 | | - [[NSNotificationCenter defaultCenter] postNotificationName:RCTShowDevMenuNotification object:nil]; |
293 | | - // Return nil as the menu will be shown programmatically via notification |
294 | | - return nil; |
| 293 | + // Try to get DevMenu from the contextContainer via the surface presenter |
| 294 | + // This works in Fabric architecture where DevMenu is stored in contextContainer |
| 295 | + if ([self.surface respondsToSelector:@selector(surfacePresenter)]) { |
| 296 | + RCTSurfacePresenter *surfacePresenter = [self.surface performSelector:@selector(surfacePresenter)]; |
| 297 | + if (surfacePresenter) { |
| 298 | + auto contextContainer = surfacePresenter.contextContainer; |
| 299 | + if (contextContainer) { |
| 300 | + auto optionalDevMenu = contextContainer->find<std::shared_ptr<void>>("RCTDevMenu"); |
| 301 | + if (optionalDevMenu) { |
| 302 | + RCTDevMenu *devMenu = facebook::react::unwrapManagedObject(optionalDevMenu.value()); |
| 303 | + if (devMenu) { |
| 304 | + menu = [devMenu menu]; |
| 305 | + } |
| 306 | + } |
| 307 | + } |
| 308 | + } |
| 309 | + } |
| 310 | + |
| 311 | + // Fall back to notification-based approach if contextContainer access fails |
| 312 | + if (menu == nil) { |
| 313 | + [[NSNotificationCenter defaultCenter] postNotificationName:RCTShowDevMenuNotification object:nil]; |
| 314 | + // Return nil as the menu will be shown programmatically via notification |
| 315 | + return nil; |
| 316 | + } |
295 | 317 | #endif |
296 | 318 |
|
297 | 319 | if (menu == nil) { |
|
0 commit comments