Skip to content

Commit 5914c8e

Browse files
authored
feat(0.77): Implement RCTPausedInDebuggerOverlayController (#2588)
1 parent 413c6aa commit 5914c8e

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,6 +57,7 @@ - (void)viewDidLoad
5657
[messageLabel.trailingAnchor constraintEqualToAnchor:messageContainer.trailingAnchor],
5758
]];
5859

60+
#if !TARGET_OS_OSX // [macOS]
5961
UIButton *resumeButton = [UIButton buttonWithType:UIButtonTypeCustom];
6062
[resumeButton setImage:[UIImage systemImageNamed:@"forward.frame.fill"] forState:UIControlStateNormal];
6163
resumeButton.tintColor = [UIColor colorWithRed:0.37 green:0.37 blue:0.37 alpha:1];
@@ -65,11 +67,21 @@ - (void)viewDidLoad
6567
};
6668

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

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

113+
#if !TARGET_OS_OSX
88114
[self.view addSubview:stackView];
89115

90116
[NSLayoutConstraint activateConstraints:@[
91117
[stackView.topAnchor constraintEqualToAnchor:self.view.safeAreaLayoutGuide.topAnchor constant:12],
92118
[stackView.centerXAnchor constraintEqualToAnchor:self.view.safeAreaLayoutGuide.centerXAnchor],
93119
]];
120+
#else
121+
[self setView:stackView];
122+
#endif
94123

124+
#if !TARGET_OS_OSX // [macOS]
95125
stackView.semanticContentAttribute = UISemanticContentAttributeForceLeftToRight;
126+
#else // [macOS
127+
stackView.userInterfaceLayoutDirection = NSUserInterfaceLayoutDirectionLeftToRight;
128+
#endif // macOS]
96129
}
97130

131+
#if !TARGET_OS_OSX // [macOS]
98132
- (void)handleResume:(UITapGestureRecognizer *)recognizer
99133
{
100134
self.onResume();
101135
}
102-
#endif // [macOS]
136+
#else // [macOS
137+
- (void)handleResume:(id)sender
138+
{
139+
self.onResume();
140+
}
141+
#endif // macOS]
103142
@end
104143

105144
@implementation RCTPausedInDebuggerOverlayController
106145

107-
#if !TARGET_OS_OSX // [macOS]
108-
- (UIWindow *)alertWindow
146+
- (RCTPlatformWindow *)alertWindow // [macOS]
109147
{
110148
if (_alertWindow == nil) {
149+
#if !TARGET_OS_OSX // [macOS]
111150
_alertWindow = [[UIWindow alloc] initWithWindowScene:RCTKeyWindow().windowScene];
112151

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

119166
return _alertWindow;
120167
}
121-
#endif // [macOS]
122168

123169
- (void)showWithMessage:(NSString *)message onResume:(void (^)(void))onResume
124170
{
@@ -129,9 +175,21 @@ - (void)showWithMessage:(NSString *)message onResume:(void (^)(void))onResume
129175
view.modalPresentationStyle = UIModalPresentationOverFullScreen;
130176
view.message = message;
131177
view.onResume = onResume;
178+
132179
[self.alertWindow makeKeyAndVisible];
133180
[self.alertWindow.rootViewController presentViewController:view animated:NO completion:nil];
134-
#endif // [macOS]
181+
#else // [macOS]
182+
self.alertWindow.contentViewController = view;
183+
view.message = message;
184+
view.onResume = onResume;
185+
186+
NSWindow *parentWindow = RCTKeyWindow();
187+
if (![[parentWindow sheets] doesContain:self->_alertWindow]) {
188+
[parentWindow beginSheet:self.alertWindow completionHandler:^(NSModalResponse returnCode) {
189+
[self->_alertWindow orderOut:self];
190+
}];
191+
}
192+
#endif // macOS]
135193
}
136194

137195
- (void)hide
@@ -140,9 +198,19 @@ - (void)hide
140198
[_alertWindow setHidden:YES];
141199

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

144213
_alertWindow = nil;
145-
#endif // macOS]
146214
}
147215

148216
@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)