Skip to content

Commit 65160aa

Browse files
committed
feat: Implement RCTPausedInDebuggerOverlayController
1 parent 12c8ecd commit 65160aa

File tree

3 files changed

+97
-24
lines changed

3 files changed

+97
-24
lines changed

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:(RCTUIWindow *)window surfacePresenter:(id<RCTSur
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,87 +58,155 @@ - (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];
6265
resumeButton.adjustsImageWhenDisabled = NO;
6366
resumeButton.enabled = NO;
67+
#else // [macOS
68+
NSButton *resumeButton = [[NSButton alloc] init];
69+
[resumeButton setImage:[NSImage imageWithSystemSymbolName:@"forward.frame.fill" accessibilityDescription:@"Resume"]];
70+
resumeButton.bordered = NO;
71+
resumeButton.target = self;
72+
resumeButton.action = @selector(handleResume:);
73+
resumeButton.contentTintColor = [NSColor colorWithRed:0.37 green:0.37 blue:0.37 alpha:1];
74+
#endif // macOS]
75+
6476
[NSLayoutConstraint activateConstraints:@[
6577
[resumeButton.widthAnchor constraintEqualToConstant:48],
6678
[resumeButton.heightAnchor constraintEqualToConstant:46],
6779
]];
6880

81+
#if !TARGET_OS_OSX // [macOS]
6982
UIStackView *stackView = [[UIStackView alloc] initWithArrangedSubviews:@[ messageContainer, resumeButton ]];
7083
stackView.backgroundColor = [UIColor colorWithRed:1 green:1 blue:0.757 alpha:1];
84+
stackView.axis = UILayoutConstraintAxisHorizontal;
85+
stackView.distribution = UIStackViewDistributionFill;
86+
stackView.alignment = UIStackViewAlignmentCenter;
7187
stackView.layer.cornerRadius = 12;
7288
stackView.layer.borderWidth = 2;
7389
stackView.layer.borderColor = [UIColor colorWithRed:0.71 green:0.71 blue:0.62 alpha:1].CGColor;
7490
stackView.translatesAutoresizingMaskIntoConstraints = NO;
75-
stackView.axis = UILayoutConstraintAxisHorizontal;
76-
stackView.distribution = UIStackViewDistributionFill;
77-
stackView.alignment = UIStackViewAlignmentCenter;
7891

7992
UITapGestureRecognizer *gestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self
8093
action:@selector(handleResume:)];
8194
[stackView addGestureRecognizer:gestureRecognizer];
8295
stackView.userInteractionEnabled = YES;
96+
#else // [macOS
97+
NSStackView *stackView = [NSStackView stackViewWithViews:@[ messageContainer, resumeButton ]];
98+
stackView.wantsLayer = YES;
99+
stackView.layer.backgroundColor = [NSColor colorWithRed:1 green:1 blue:0.757 alpha:1].CGColor;
100+
stackView.orientation = NSUserInterfaceLayoutOrientationHorizontal;
101+
stackView.distribution = NSStackViewDistributionFill;
102+
stackView.alignment = NSLayoutAttributeCenterY;
103+
stackView.translatesAutoresizingMaskIntoConstraints = NO;
83104

105+
NSClickGestureRecognizer *gestureRecognizer = [[NSClickGestureRecognizer alloc] initWithTarget:self
106+
action:@selector(handleResume:)];
107+
[stackView addGestureRecognizer:gestureRecognizer];
108+
#endif // macOS]
109+
110+
#if !TARGET_OS_OSX
84111
[self.view addSubview:stackView];
85112

86113
[NSLayoutConstraint activateConstraints:@[
87114
[stackView.topAnchor constraintEqualToAnchor:self.view.safeAreaLayoutGuide.topAnchor constant:12],
88-
[stackView.centerXAnchor constraintEqualToAnchor:self.view.safeAreaLayoutGuide.centerXAnchor],
115+
[stackView.topAnchor constraintEqualToAnchor:self.view.topAnchor constant:20],
116+
[stackView.leadingAnchor constraintEqualToAnchor:self.view.leadingAnchor constant:20],
117+
[stackView.trailingAnchor constraintEqualToAnchor:self.view.trailingAnchor constant:-20],
118+
[stackView.bottomAnchor constraintEqualToAnchor:self.view.bottomAnchor constant:-20],
119+
[stackView.centerXAnchor constraintEqualToAnchor:self.view.centerXAnchor],
89120
]];
121+
#else
122+
[self setView:stackView];
123+
#endif
90124

125+
#if !TARGET_OS_OSX // [macOS]
91126
stackView.semanticContentAttribute = UISemanticContentAttributeForceLeftToRight;
127+
#else // [macOS
128+
stackView.userInterfaceLayoutDirection = NSUserInterfaceLayoutDirectionLeftToRight;
129+
#endif // macOS]
92130
}
93131

132+
#if !TARGET_OS_OSX // [macOS]
94133
- (void)handleResume:(UITapGestureRecognizer *)recognizer
95134
{
96135
self.onResume();
97136
}
98-
#endif // [macOS]
137+
#else // [macOS
138+
- (void)handleResume:(id)sender
139+
{
140+
self.onResume();
141+
}
142+
#endif // macOS]
99143
@end
100144

101145
@implementation RCTPausedInDebuggerOverlayController
102146

103-
#if !TARGET_OS_OSX // [macOS]
104-
- (UIWindow *)alertWindow
147+
- (RCTPlatformWindow *)alertWindow // [macOS]
105148
{
106149
if (_alertWindow == nil) {
150+
#if !TARGET_OS_OSX // [macOS]
107151
_alertWindow = [[UIWindow alloc] initWithWindowScene:RCTKeyWindow().windowScene];
108152

109153
if (_alertWindow) {
110154
_alertWindow.rootViewController = [UIViewController new];
111155
_alertWindow.windowLevel = UIWindowLevelAlert + 1;
112156
}
157+
#else // [macOS]
158+
_alertWindow = [[NSWindow alloc] initWithContentRect:NSMakeRect(0, 0, 100, 100)
159+
styleMask:NSWindowStyleMaskBorderless | NSWindowStyleMaskFullSizeContentView
160+
backing:NSBackingStoreBuffered
161+
defer:YES];
162+
_alertWindow.backgroundColor = [NSColor clearColor];
163+
_alertWindow.opaque = NO;
164+
#endif // macOS]
113165
}
114166

115167
return _alertWindow;
116168
}
117-
#endif // [macOS]
118169

119170
- (void)showWithMessage:(NSString *)message onResume:(void (^)(void))onResume
120171
{
121172
[self hide];
122173

123174
RCTPausedInDebuggerViewController *view = [[RCTPausedInDebuggerViewController alloc] init];
124-
#if !TARGET_OS_OSX // [macOS]
125-
view.modalPresentationStyle = UIModalPresentationOverFullScreen;
126175
view.message = message;
127176
view.onResume = onResume;
177+
178+
#if !TARGET_OS_OSX // [macOS]
179+
view.modalPresentationStyle = UIModalPresentationOverFullScreen;
128180
[self.alertWindow makeKeyAndVisible];
129181
[self.alertWindow.rootViewController presentViewController:view animated:NO completion:nil];
130-
#endif // [macOS]
182+
#else // [macOS]
183+
self.alertWindow.contentViewController = view;
184+
185+
NSWindow *parentWindow = RCTKeyWindow();
186+
if (![[parentWindow sheets] doesContain:self->_alertWindow]) {
187+
[parentWindow beginSheet:self.alertWindow completionHandler:^(NSModalResponse returnCode) {
188+
[self->_alertWindow orderOut:self];
189+
}];
190+
}
191+
#endif // macOS]
131192
}
132193

133194
- (void)hide
134195
{
135196
#if !TARGET_OS_OSX // [macOS]
136197
[_alertWindow setHidden:YES];
137-
138198
_alertWindow.windowScene = nil;
139-
199+
_alertWindow = nil;
200+
#else // [macOS]
201+
NSWindow *parentWindow = RCTKeyWindow();
202+
if (parentWindow) {
203+
for (NSWindow *sheet in [parentWindow sheets]) {
204+
if (sheet == _alertWindow) {
205+
[parentWindow endSheet:sheet];
206+
break;
207+
}
208+
}
209+
}
140210
_alertWindow = nil;
141211
#endif // macOS]
142212
}

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)