Skip to content

Commit a9398d3

Browse files
authored
feat(0.78): Implement RCTPausedInDebuggerOverlayController (#2587)
1 parent e666b40 commit a9398d3

File tree

5 files changed

+93
-18
lines changed

5 files changed

+93
-18
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
__default__: patch
3+
---
4+
5+
Implement paused in Debugger overlay

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: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,10 @@ - (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 initWithContentRect:NSMakeRect(0, 0, 600, 800)
83+
styleMask:NSWindowStyleMaskBorderless | NSWindowStyleMaskFullSizeContentView
84+
backing:NSBackingStoreBuffered
85+
defer:YES];
8386
_window = window;
8487
#endif // macOS]
8588

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

Lines changed: 82 additions & 14 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,18 @@ - (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+
RCTUIView *messageContainer = [[RCTUIView alloc] init]; // [macOS]
5152
[messageContainer addSubview:messageLabel];
5253
[NSLayoutConstraint activateConstraints:@[
5354
[messageLabel.topAnchor constraintEqualToAnchor:messageContainer.topAnchor constant:-1],
@@ -56,18 +57,29 @@ - (void)viewDidLoad
5657
[messageLabel.trailingAnchor constraintEqualToAnchor:messageContainer.trailingAnchor],
5758
]];
5859

60+
#if !TARGET_OS_OSX // [macOS]
5961
UIButton *resumeButton = [UIButton buttonWithType:UIButtonTypeCustom];
6062
UIImage *image = [UIImage systemImageNamed:@"forward.frame.fill"];
6163
[resumeButton setImage:image forState:UIControlStateNormal];
6264
[resumeButton setImage:image forState:UIControlStateDisabled];
6365
resumeButton.tintColor = [UIColor colorWithRed:0.37 green:0.37 blue:0.37 alpha:1];
6466

6567
resumeButton.enabled = NO;
68+
#else // [macOS
69+
NSButton *resumeButton = [[NSButton alloc] init];
70+
[resumeButton setImage:[NSImage imageWithSystemSymbolName:@"forward.frame.fill" accessibilityDescription:@"Resume"]];
71+
resumeButton.bordered = NO;
72+
resumeButton.target = self;
73+
resumeButton.action = @selector(handleResume:);
74+
resumeButton.contentTintColor = [NSColor colorWithRed:0.37 green:0.37 blue:0.37 alpha:1];
75+
#endif // macOS]
76+
6677
[NSLayoutConstraint activateConstraints:@[
6778
[resumeButton.widthAnchor constraintEqualToConstant:48],
6879
[resumeButton.heightAnchor constraintEqualToConstant:46],
6980
]];
7081

82+
#if !TARGET_OS_OSX // [macOS]
7183
UIStackView *stackView = [[UIStackView alloc] initWithArrangedSubviews:@[ messageContainer, resumeButton ]];
7284
stackView.backgroundColor = [UIColor colorWithRed:1 green:1 blue:0.757 alpha:1];
7385
stackView.layer.cornerRadius = 12;
@@ -82,41 +94,75 @@ - (void)viewDidLoad
8294
action:@selector(handleResume:)];
8395
[stackView addGestureRecognizer:gestureRecognizer];
8496
stackView.userInteractionEnabled = YES;
97+
#else // [macOS
98+
NSStackView *stackView = [NSStackView stackViewWithViews:@[ messageContainer, resumeButton ]];
99+
stackView.wantsLayer = YES;
100+
stackView.layer.backgroundColor = [NSColor colorWithRed:1 green:1 blue:0.757 alpha:1].CGColor;
101+
stackView.translatesAutoresizingMaskIntoConstraints = NO;
102+
stackView.orientation = NSUserInterfaceLayoutOrientationHorizontal;
103+
stackView.distribution = NSStackViewDistributionFill;
104+
stackView.alignment = NSLayoutAttributeCenterY;
105+
106+
NSClickGestureRecognizer *gestureRecognizer = [[NSClickGestureRecognizer alloc] initWithTarget:self
107+
action:@selector(handleResume:)];
108+
[stackView addGestureRecognizer:gestureRecognizer];
109+
#endif // macOS]
85110

111+
#if !TARGET_OS_OSX
86112
[self.view addSubview:stackView];
87113

88114
[NSLayoutConstraint activateConstraints:@[
89115
[stackView.topAnchor constraintEqualToAnchor:self.view.safeAreaLayoutGuide.topAnchor constant:12],
90116
[stackView.centerXAnchor constraintEqualToAnchor:self.view.safeAreaLayoutGuide.centerXAnchor],
91117
]];
118+
#else
119+
[self setView:stackView];
120+
#endif
92121

122+
#if !TARGET_OS_OSX // [macOS]
93123
stackView.semanticContentAttribute = UISemanticContentAttributeForceLeftToRight;
124+
#else // [macOS
125+
stackView.userInterfaceLayoutDirection = NSUserInterfaceLayoutDirectionLeftToRight;
126+
#endif // macOS]
94127
}
95128

129+
#if !TARGET_OS_OSX // [macOS]
96130
- (void)handleResume:(UITapGestureRecognizer *)recognizer
97131
{
98132
self.onResume();
99133
}
100-
#endif // [macOS]
134+
#else // [macOS
135+
- (void)handleResume:(id)sender
136+
{
137+
self.onResume();
138+
}
139+
#endif // macOS]
101140
@end
102141

103142
@implementation RCTPausedInDebuggerOverlayController
104143

105-
#if !TARGET_OS_OSX // [macOS]
106-
- (UIWindow *)alertWindow
144+
- (RCTPlatformWindow *)alertWindow // [macOS]
107145
{
108146
if (_alertWindow == nil) {
147+
#if !TARGET_OS_OSX // [macOS]
109148
_alertWindow = [[UIWindow alloc] initWithWindowScene:RCTKeyWindow().windowScene];
110149

111150
if (_alertWindow) {
112151
_alertWindow.rootViewController = [UIViewController new];
113152
_alertWindow.windowLevel = UIWindowLevelAlert + 1;
114153
}
154+
#else // [macOS]
155+
_alertWindow = [[NSWindow alloc] initWithContentRect:NSMakeRect(0, 0, 100, 100)
156+
styleMask:NSWindowStyleMaskBorderless | NSWindowStyleMaskFullSizeContentView
157+
backing:NSBackingStoreBuffered
158+
defer:YES];
159+
_alertWindow.backgroundColor = [NSColor clearColor];
160+
_alertWindow.opaque = NO;
161+
#endif // macOS]
115162
}
116163

117164
return _alertWindow;
118165
}
119-
#endif // [macOS]
120166

121167
- (void)showWithMessage:(NSString *)message onResume:(void (^)(void))onResume
122168
{
@@ -127,9 +173,21 @@ - (void)showWithMessage:(NSString *)message onResume:(void (^)(void))onResume
127173
view.modalPresentationStyle = UIModalPresentationOverFullScreen;
128174
view.message = message;
129175
view.onResume = onResume;
176+
130177
[self.alertWindow makeKeyAndVisible];
131178
[self.alertWindow.rootViewController presentViewController:view animated:NO completion:nil];
132-
#endif // [macOS]
179+
#else // [macOS]
180+
self.alertWindow.contentViewController = view;
181+
view.message = message;
182+
view.onResume = onResume;
183+
184+
NSWindow *parentWindow = RCTKeyWindow();
185+
if (![[parentWindow sheets] doesContain:self->_alertWindow]) {
186+
[parentWindow beginSheet:self.alertWindow completionHandler:^(NSModalResponse returnCode) {
187+
[self->_alertWindow orderOut:self];
188+
}];
189+
}
190+
#endif // macOS]
133191
}
134192

135193
- (void)hide
@@ -138,9 +196,19 @@ - (void)hide
138196
[_alertWindow setHidden:YES];
139197

140198
_alertWindow.windowScene = nil;
199+
#else // [macOS]
200+
NSWindow *parentWindow = RCTKeyWindow();
201+
if (parentWindow) {
202+
for (NSWindow *sheet in [parentWindow sheets]) {
203+
if (sheet == _alertWindow) {
204+
[parentWindow endSheet:sheet];
205+
break;
206+
}
207+
}
208+
}
209+
#endif // macOS]
141210

142211
_alertWindow = nil;
143-
#endif // macOS]
144212
}
145213

146214
@end

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)