@@ -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
0 commit comments