Skip to content

Commit 6190a6b

Browse files
committed
Why do we need context container at all?
1 parent aeb41e0 commit 6190a6b

File tree

4 files changed

+31
-73
lines changed

4 files changed

+31
-73
lines changed

packages/react-native/Libraries/AppDelegate/RCTRootViewFactory.mm

Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,7 @@
3434
#import <react/renderer/runtimescheduler/RuntimeSchedulerCallInvoker.h>
3535
#import <react/runtime/JSRuntimeFactory.h>
3636

37-
#if TARGET_OS_OSX && __has_include("RCTDevMenu.h") // [macOS
38-
#import <React/RCTSurfaceHostingView+Private.h>
39-
#import <react/utils/ManagedObjectWrapper.h>
37+
#if RCT_DEV_MENU // [macOS
4038
#import "RCTDevMenu.h"
4139
#endif // macOS]
4240

@@ -159,14 +157,12 @@ - (RCTPlatformView *)viewWithModuleName:(NSString *)moduleName // [macOS]
159157
surfaceHostingProxyRootView.backgroundColor = [UIColor systemBackgroundColor];
160158
#endif // [macOS]
161159

162-
#if TARGET_OS_OSX && __has_include("RCTDevMenu.h") && RCT_DEV
160+
#if RCT_DEV_MENU // [macOS
163161
RCTDevMenu *devMenu = [self.reactHost.moduleRegistry moduleForClass:[RCTDevMenu class]];
164162
if (devMenu) {
165-
_contextContainer->erase("RCTDevMenu");
166-
_contextContainer->insert("RCTDevMenu", facebook::react::wrapManagedObject(devMenu));
163+
surfaceHostingProxyRootView.devMenu = devMenu;
167164
}
168-
[surfaceHostingProxyRootView setContextContainer:_contextContainer]; // [macOS]
169-
#endif
165+
#endif // macOS]
170166

171167
if (_configuration.customizeRootView != nil) {
172168
_configuration.customizeRootView(surfaceHostingProxyRootView);
@@ -200,15 +196,19 @@ - (RCTPlatformView *)createRootViewWithBridge:(RCTBridge *)bridge
200196
{
201197
BOOL enableFabric = _configuration.fabricEnabled;
202198
RCTPlatformView *rootView = RCTAppSetupDefaultRootView(bridge, moduleName, initProps, enableFabric); // [macOS]
203-
#if !TARGET_OS_OSX // [macOS]
204-
rootView.backgroundColor = [UIColor systemBackgroundColor];
205-
#endif // [macOS]
206199

207-
#if TARGET_OS_OSX // [macOS
200+
#if RCT_DEV_MENU // [macOS
208201
if (enableFabric && [rootView isKindOfClass:[RCTSurfaceHostingView class]]) {
209-
[(RCTSurfaceHostingView *)rootView setContextContainer:_contextContainer];
202+
RCTDevMenu *devMenu = [bridge moduleForClass:[RCTDevMenu class]];
203+
if (devMenu) {
204+
[(RCTSurfaceHostingView *)rootView setDevMenu:devMenu];
205+
}
210206
}
211207
#endif // macOS]
208+
209+
#if !TARGET_OS_OSX // [macOS]
210+
rootView.backgroundColor = [UIColor systemBackgroundColor];
211+
#endif // [macOS]
212212

213213
return rootView;
214214
}
@@ -227,15 +227,6 @@ - (RCTPlatformView *)createRootViewWithBridge:(RCTBridge *)bridge
227227
_contextContainer->erase("RuntimeScheduler");
228228
_contextContainer->insert("RuntimeScheduler", _runtimeScheduler);
229229

230-
#if TARGET_OS_OSX && __has_include("RCTDevMenu.h") && RCT_DEV
231-
// Insert dev menu for macOS context menu access using proper moduleForClass pattern
232-
RCTDevMenu *devMenu = [bridge moduleForClass:[RCTDevMenu class]];
233-
if (devMenu) {
234-
_contextContainer->erase("RCTDevMenu");
235-
_contextContainer->insert("RCTDevMenu", facebook::react::wrapManagedObject(devMenu));
236-
}
237-
#endif
238-
239230
return RCTAppSetupDefaultJsExecutorFactory(bridge, turboModuleManager, _runtimeScheduler);
240231
} else {
241232
return RCTAppSetupJsExecutorFactoryForOldArch(bridge, _runtimeScheduler);

packages/react-native/React/Base/Surface/SurfaceHostingView/RCTSurfaceHostingView+Private.h

Lines changed: 0 additions & 28 deletions
This file was deleted.

packages/react-native/React/Base/Surface/SurfaceHostingView/RCTSurfaceHostingView.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@
1515
@class RCTBridge;
1616
@class RCTSurface;
1717

18+
#if RCT_DEV_MENU// [macOS]
19+
@class RCTDevMenu;
20+
#endif // [macOS]
21+
1822
typedef RCTPlatformView *_Nullable (^RCTSurfaceHostingViewActivityIndicatorViewFactory)(void); // [macOS]
1923

2024
NS_ASSUME_NONNULL_BEGIN
@@ -63,6 +67,14 @@ NS_ASSUME_NONNULL_BEGIN
6367
* @param disabled if `YES`, the auto-hide is disabled. Otherwise the loading view will be hidden automatically
6468
*/
6569
- (void)disableActivityIndicatorAutoHide:(BOOL)disabled;
70+
71+
#if RCT_DEV_MENU // [macOS
72+
/**
73+
* Dev menu for macOS context menu access.
74+
*/
75+
@property (nonatomic, strong, nullable) RCTDevMenu *devMenu;
76+
#endif // macOS]
77+
6678
@end
6779

6880
NS_ASSUME_NONNULL_END

packages/react-native/React/Base/Surface/SurfaceHostingView/RCTSurfaceHostingView.mm

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
*/
77

88
#import "RCTSurfaceHostingView.h"
9-
#import "RCTSurfaceHostingView+Private.h" // [macOS]
109
#import "RCTConstants.h"
1110
#import "RCTDefines.h"
1211
#import "RCTSurface.h"
@@ -31,7 +30,6 @@ @implementation RCTSurfaceHostingView {
3130
RCTPlatformView *_Nullable _surfaceView; // [macOS]
3231
RCTSurfaceStage _stage;
3332
BOOL _autoHideDisabled;
34-
facebook::react::ContextContainer::Shared _contextContainer; // [macOS]
3533
}
3634

3735
RCT_NOT_IMPLEMENTED(-(instancetype)init)
@@ -142,18 +140,6 @@ - (void)setSizeMeasureMode:(RCTSurfaceSizeMeasureMode)sizeMeasureMode
142140
[self _invalidateLayout];
143141
}
144142

145-
#if TARGET_OS_OSX // [macOS
146-
- (facebook::react::ContextContainer::Shared)contextContainer
147-
{
148-
return _contextContainer;
149-
}
150-
151-
- (void)setContextContainer:(facebook::react::ContextContainer::Shared)contextContainer
152-
{
153-
_contextContainer = contextContainer;
154-
}
155-
#endif // macOS]
156-
157143
- (void)disableActivityIndicatorAutoHide:(BOOL)disabled
158144
{
159145
_autoHideDisabled = disabled;
@@ -304,16 +290,13 @@ - (void)surface:(__unused RCTSurface *)surface didChangeIntrinsicSize:(__unused
304290

305291
- (NSMenu *)menuForEvent:(NSEvent *)event
306292
{
307-
#if RCT_DEV_MENU && __has_include("RCTDevMenu.h")
308-
if (_contextContainer) {
309-
auto devMenuOptional = _contextContainer->find<std::shared_ptr<void>>("RCTDevMenu");
310-
if (devMenuOptional.has_value()) {
311-
RCTDevMenu *devMenu = facebook::react::unwrapManagedObject(*devMenuOptional);
312-
if (devMenu) {
313-
return [devMenu menu];
314-
}
315-
}
293+
#if __has_include("RCTDevMenu.h") && RCT_DEV
294+
// Try direct dev menu property first (simplest approach)
295+
if (_devMenu) {
296+
return [_devMenu menu];
316297
}
298+
299+
317300
#endif
318301

319302
return [super menuForEvent:event];

0 commit comments

Comments
 (0)