Skip to content

Commit 32ad729

Browse files
committed
initial implementation
1 parent 96ee79d commit 32ad729

File tree

4 files changed

+98
-25
lines changed

4 files changed

+98
-25
lines changed

packages/react-native/React/CoreModules/RCTDevLoadingView.mm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ - (void)showMessage:(NSString *)message color:(RCTUIColor *)color backgroundColo
130130
self->_window.rootViewController = [UIViewController new];
131131
#else // [macOS
132132
self->_window = [[NSWindow alloc] initWithContentRect:NSMakeRect(0, 0, 375, 20)
133-
styleMask:NSWindowStyleMaskBorderless
133+
styleMask:NSWindowStyleMaskBorderless | NSWindowStyleMaskFullSizeContentView
134134
backing:NSBackingStoreBuffered
135135
defer:YES];
136136
[self->_window setIdentifier:sRCTDevLoadingViewWindowIdentifier];

packages/react-native/React/CoreModules/RCTLogBoxView.mm

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,11 @@ - (instancetype)initWithWindow:(RCTPlatformWindow *)window surfacePresenter:(id<
7979
#if !TARGET_OS_OSX // [macOS]
8080
self = [super initWithWindowScene:window.windowScene];
8181
#else // [macOS
82-
self = [super initWithContentRect:NSMakeRect(0, 0, 600, 800) styleMask:NSWindowStyleMaskTitled backing:NSBackingStoreBuffered defer:YES];
82+
self = [super
83+
initWithContentRect:NSMakeRect(0, 0, 600, 800)
84+
styleMask:NSWindowStyleMaskBorderless | NSWindowStyleMaskFullSizeContentView
85+
backing:NSBackingStoreBuffered
86+
defer:YES];
8387
_window = window;
8488
#endif // macOS]
8589

packages/react-native/React/DevSupport/RCTPausedInDebuggerOverlayController.mm

Lines changed: 91 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,17 @@ @interface RCTPausedInDebuggerViewController : UIViewController
1616
@end
1717

1818
@interface RCTPausedInDebuggerOverlayController ()
19-
#if !TARGET_OS_OSX // [macOS]
2019

21-
@property (nonatomic, strong) UIWindow *alertWindow;
20+
@property (nonatomic, strong) RCTPlatformWindow *alertWindow; // [macOS]
2221

23-
#endif // [macOS];
2422
@end
2523

2624
@implementation RCTPausedInDebuggerViewController
27-
#if !TARGET_OS_OSX // [macOS]
2825
- (void)viewDidLoad
2926
{
3027
[super viewDidLoad];
3128

29+
#if !TARGET_OS_OSX // [macOS]
3230
UIView *dimmingView = [[UIView alloc] init];
3331
dimmingView.translatesAutoresizingMaskIntoConstraints = NO;
3432
dimmingView.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.2];
@@ -39,15 +37,19 @@ - (void)viewDidLoad
3937
[dimmingView.leadingAnchor constraintEqualToAnchor:self.view.leadingAnchor],
4038
[dimmingView.trailingAnchor constraintEqualToAnchor:self.view.trailingAnchor]
4139
]];
42-
43-
UILabel *messageLabel = [[UILabel alloc] init];
40+
#endif // [macOS]
41+
42+
RCTUILabel *messageLabel = [[RCTUILabel alloc] init]; // [macOS]
4443
messageLabel.text = self.message;
4544
messageLabel.textAlignment = NSTextAlignmentCenter;
45+
#if !TARGET_OS_OSX // [macOS]
4646
messageLabel.numberOfLines = 0;
47+
#endif // [macOS]
4748
messageLabel.font = [UIFont boldSystemFontOfSize:16];
48-
messageLabel.textColor = [UIColor blackColor];
49+
messageLabel.textColor = [RCTUIColor blackColor]; // [macOS]
4950
messageLabel.translatesAutoresizingMaskIntoConstraints = NO;
50-
UIView *messageContainer = [[UIView alloc] init];
51+
52+
RCTUIView *messageContainer = [[RCTUIView alloc] init]; // [macOS]
5153
[messageContainer addSubview:messageLabel];
5254
[NSLayoutConstraint activateConstraints:@[
5355
[messageLabel.topAnchor constraintEqualToAnchor:messageContainer.topAnchor constant:-1],
@@ -56,6 +58,7 @@ - (void)viewDidLoad
5658
[messageLabel.trailingAnchor constraintEqualToAnchor:messageContainer.trailingAnchor],
5759
]];
5860

61+
#if !TARGET_OS_OSX // [macOS]
5962
UIButton *resumeButton = [UIButton buttonWithType:UIButtonTypeCustom];
6063
[resumeButton setImage:[UIImage systemImageNamed:@"forward.frame.fill"] forState:UIControlStateNormal];
6164
resumeButton.tintColor = [UIColor colorWithRed:0.37 green:0.37 blue:0.37 alpha:1];
@@ -65,82 +68,149 @@ - (void)viewDidLoad
6568
};
6669

6770
resumeButton.enabled = NO;
71+
#else // [macOS
72+
NSButton *resumeButton = [[NSButton alloc] init];
73+
[resumeButton setImage:[NSImage imageWithSystemSymbolName:@"forward.frame.fill" accessibilityDescription:@"Resume"]];
74+
resumeButton.bordered = NO;
75+
resumeButton.target = self;
76+
resumeButton.action = @selector(handleResume:);
77+
resumeButton.contentTintColor = [NSColor colorWithRed:0.37 green:0.37 blue:0.37 alpha:1];
78+
#endif // macOS]
79+
6880
[NSLayoutConstraint activateConstraints:@[
6981
[resumeButton.widthAnchor constraintEqualToConstant:48],
7082
[resumeButton.heightAnchor constraintEqualToConstant:46],
7183
]];
7284

85+
#if !TARGET_OS_OSX // [macOS]
7386
UIStackView *stackView = [[UIStackView alloc] initWithArrangedSubviews:@[ messageContainer, resumeButton ]];
7487
stackView.backgroundColor = [UIColor colorWithRed:1 green:1 blue:0.757 alpha:1];
88+
stackView.axis = UILayoutConstraintAxisHorizontal;
89+
stackView.distribution = UIStackViewDistributionFill;
90+
stackView.alignment = UIStackViewAlignmentCenter;
7591
stackView.layer.cornerRadius = 12;
7692
stackView.layer.borderWidth = 2;
7793
stackView.layer.borderColor = [UIColor colorWithRed:0.71 green:0.71 blue:0.62 alpha:1].CGColor;
7894
stackView.translatesAutoresizingMaskIntoConstraints = NO;
79-
stackView.axis = UILayoutConstraintAxisHorizontal;
80-
stackView.distribution = UIStackViewDistributionFill;
81-
stackView.alignment = UIStackViewAlignmentCenter;
8295

8396
UITapGestureRecognizer *gestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self
8497
action:@selector(handleResume:)];
8598
[stackView addGestureRecognizer:gestureRecognizer];
8699
stackView.userInteractionEnabled = YES;
100+
#else // [macOS
101+
NSStackView *stackView = [NSStackView stackViewWithViews:@[ messageContainer, resumeButton ]];
102+
stackView.wantsLayer = YES;
103+
stackView.layer.backgroundColor = [NSColor colorWithRed:1 green:1 blue:0.757 alpha:1].CGColor;
104+
stackView.orientation = NSUserInterfaceLayoutOrientationHorizontal;
105+
stackView.distribution = NSStackViewDistributionFill;
106+
stackView.alignment = NSLayoutAttributeCenterY;
107+
stackView.translatesAutoresizingMaskIntoConstraints = NO;
87108

109+
NSClickGestureRecognizer *gestureRecognizer = [[NSClickGestureRecognizer alloc] initWithTarget:self
110+
action:@selector(handleResume:)];
111+
[stackView addGestureRecognizer:gestureRecognizer];
112+
#endif // macOS]
113+
114+
#if !TARGET_OS_OSX
88115
[self.view addSubview:stackView];
89116

90117
[NSLayoutConstraint activateConstraints:@[
91118
[stackView.topAnchor constraintEqualToAnchor:self.view.safeAreaLayoutGuide.topAnchor constant:12],
92-
[stackView.centerXAnchor constraintEqualToAnchor:self.view.safeAreaLayoutGuide.centerXAnchor],
119+
[stackView.topAnchor constraintEqualToAnchor:self.view.topAnchor constant:20],
120+
[stackView.leadingAnchor constraintEqualToAnchor:self.view.leadingAnchor constant:20],
121+
[stackView.trailingAnchor constraintEqualToAnchor:self.view.trailingAnchor constant:-20],
122+
[stackView.bottomAnchor constraintEqualToAnchor:self.view.bottomAnchor constant:-20],
123+
[stackView.centerXAnchor constraintEqualToAnchor:self.view.centerXAnchor],
93124
]];
125+
#else
126+
[self setView:stackView];
127+
#endif
94128

129+
#if !TARGET_OS_OSX // [macOS]
95130
stackView.semanticContentAttribute = UISemanticContentAttributeForceLeftToRight;
131+
#else // [macOS
132+
stackView.userInterfaceLayoutDirection = NSUserInterfaceLayoutDirectionLeftToRight;
133+
#endif // macOS]
96134
}
97135

136+
#if !TARGET_OS_OSX // [macOS]
98137
- (void)handleResume:(UITapGestureRecognizer *)recognizer
99138
{
100139
self.onResume();
101140
}
102-
#endif // [macOS]
141+
#else // [macOS
142+
- (void)handleResume:(id)sender
143+
{
144+
self.onResume();
145+
}
146+
#endif // macOS]
103147
@end
104148

105149
@implementation RCTPausedInDebuggerOverlayController
106150

107-
#if !TARGET_OS_OSX // [macOS]
108-
- (UIWindow *)alertWindow
151+
- (RCTPlatformWindow *)alertWindow // [macOS]
109152
{
110153
if (_alertWindow == nil) {
154+
#if !TARGET_OS_OSX // [macOS]
111155
_alertWindow = [[UIWindow alloc] initWithWindowScene:RCTKeyWindow().windowScene];
112156

113157
if (_alertWindow) {
114158
_alertWindow.rootViewController = [UIViewController new];
115159
_alertWindow.windowLevel = UIWindowLevelAlert + 1;
116160
}
161+
#else // [macOS]
162+
_alertWindow = [[NSWindow alloc] initWithContentRect:NSMakeRect(0, 0, 100, 100)
163+
styleMask:NSWindowStyleMaskBorderless | NSWindowStyleMaskFullSizeContentView
164+
backing:NSBackingStoreBuffered
165+
defer:YES];
166+
_alertWindow.backgroundColor = [NSColor clearColor];
167+
_alertWindow.opaque = NO;
168+
#endif // macOS]
117169
}
118170

119171
return _alertWindow;
120172
}
121-
#endif // [macOS]
122173

123174
- (void)showWithMessage:(NSString *)message onResume:(void (^)(void))onResume
124175
{
125176
[self hide];
126177

127178
RCTPausedInDebuggerViewController *view = [[RCTPausedInDebuggerViewController alloc] init];
128-
#if !TARGET_OS_OSX // [macOS]
129-
view.modalPresentationStyle = UIModalPresentationOverFullScreen;
130179
view.message = message;
131180
view.onResume = onResume;
181+
182+
#if !TARGET_OS_OSX // [macOS]
183+
view.modalPresentationStyle = UIModalPresentationOverFullScreen;
132184
[self.alertWindow makeKeyAndVisible];
133185
[self.alertWindow.rootViewController presentViewController:view animated:NO completion:nil];
134-
#endif // [macOS]
186+
#else // [macOS]
187+
self.alertWindow.contentViewController = view;
188+
189+
NSWindow *parentWindow = RCTKeyWindow();
190+
if (![[parentWindow sheets] doesContain:self->_alertWindow]) {
191+
[parentWindow beginSheet:self.alertWindow completionHandler:^(NSModalResponse returnCode) {
192+
[self->_alertWindow orderOut:self];
193+
}];
194+
}
195+
#endif // macOS]
135196
}
136197

137198
- (void)hide
138199
{
139200
#if !TARGET_OS_OSX // [macOS]
140201
[_alertWindow setHidden:YES];
141-
142202
_alertWindow.windowScene = nil;
143-
203+
_alertWindow = nil;
204+
#else // [macOS]
205+
NSWindow *parentWindow = RCTKeyWindow();
206+
if (parentWindow) {
207+
for (NSWindow *sheet in [parentWindow sheets]) {
208+
if (sheet == _alertWindow) {
209+
[parentWindow endSheet:sheet];
210+
break;
211+
}
212+
}
213+
}
144214
_alertWindow = nil;
145215
#endif // macOS]
146216
}

packages/rn-tester/Podfile

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,7 @@ def pods(target_name, options = {})
3939

4040
# Hermes is now enabled by default.
4141
# The following line will only disable Hermes if the USE_HERMES envvar is SET to a value other than 1 (e.g. USE_HERMES=0).
42-
# [macOS] Make hermes disabled by default for our fork
43-
hermes_enabled = ENV['USE_HERMES'] == '1'
42+
hermes_enabled = !ENV.has_key?('USE_HERMES') || ENV['USE_HERMES'] == '1'
4443
puts "Configuring #{target_name} with Fabric #{fabric_enabled ? "enabled" : "disabled"}.#{hermes_enabled ? " Using Hermes engine." : ""}"
4544

4645
use_react_native!(

0 commit comments

Comments
 (0)