@@ -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,16 +57,27 @@ - (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 ];
6264 resumeButton.adjustsImageWhenDisabled = NO ;
6365 resumeButton.enabled = NO ;
66+ #else // [macOS
67+ NSButton *resumeButton = [[NSButton alloc ] init ];
68+ [resumeButton setImage: [NSImage imageWithSystemSymbolName: @" forward.frame.fill" accessibilityDescription: @" Resume" ]];
69+ resumeButton.bordered = NO ;
70+ resumeButton.target = self;
71+ resumeButton.action = @selector (handleResume: );
72+ resumeButton.contentTintColor = [NSColor colorWithRed: 0.37 green: 0.37 blue: 0.37 alpha: 1 ];
73+ #endif // macOS]
74+
6475 [NSLayoutConstraint activateConstraints: @[
6576 [resumeButton.widthAnchor constraintEqualToConstant: 48 ],
6677 [resumeButton.heightAnchor constraintEqualToConstant: 46 ],
6778 ]];
6879
80+ #if !TARGET_OS_OSX // [macOS]
6981 UIStackView *stackView = [[UIStackView alloc ] initWithArrangedSubviews: @[ messageContainer, resumeButton ]];
7082 stackView.backgroundColor = [UIColor colorWithRed: 1 green: 1 blue: 0.757 alpha: 1 ];
7183 stackView.layer .cornerRadius = 12 ;
@@ -80,41 +92,75 @@ - (void)viewDidLoad
8092 action: @selector (handleResume: )];
8193 [stackView addGestureRecognizer: gestureRecognizer];
8294 stackView.userInteractionEnabled = YES ;
95+ #else // [macOS
96+ NSStackView *stackView = [NSStackView stackViewWithViews: @[ messageContainer, resumeButton ]];
97+ stackView.wantsLayer = YES ;
98+ stackView.layer .backgroundColor = [NSColor colorWithRed: 1 green: 1 blue: 0.757 alpha: 1 ].CGColor ;
99+ stackView.translatesAutoresizingMaskIntoConstraints = NO ;
100+ stackView.orientation = NSUserInterfaceLayoutOrientationHorizontal;
101+ stackView.distribution = NSStackViewDistributionFill;
102+ stackView.alignment = NSLayoutAttributeCenterY;
103+
104+ NSClickGestureRecognizer *gestureRecognizer = [[NSClickGestureRecognizer alloc ] initWithTarget: self
105+ action: @selector (handleResume: )];
106+ [stackView addGestureRecognizer: gestureRecognizer];
107+ #endif // macOS]
83108
109+ #if !TARGET_OS_OSX
84110 [self .view addSubview: stackView];
85111
86112 [NSLayoutConstraint activateConstraints: @[
87113 [stackView.topAnchor constraintEqualToAnchor: self .view.safeAreaLayoutGuide.topAnchor constant: 12 ],
88114 [stackView.centerXAnchor constraintEqualToAnchor: self .view.safeAreaLayoutGuide.centerXAnchor],
89115 ]];
116+ #else
117+ [self setView: stackView];
118+ #endif
90119
120+ #if !TARGET_OS_OSX // [macOS]
91121 stackView.semanticContentAttribute = UISemanticContentAttributeForceLeftToRight;
122+ #else // [macOS
123+ stackView.userInterfaceLayoutDirection = NSUserInterfaceLayoutDirectionLeftToRight;
124+ #endif // macOS]
92125}
93126
127+ #if !TARGET_OS_OSX // [macOS]
94128- (void )handleResume : (UITapGestureRecognizer *)recognizer
95129{
96130 self.onResume ();
97131}
98- #endif // [macOS]
132+ #else // [macOS
133+ - (void )handleResume : (id )sender
134+ {
135+ self.onResume ();
136+ }
137+ #endif // macOS]
99138@end
100139
101140@implementation RCTPausedInDebuggerOverlayController
102141
103- #if !TARGET_OS_OSX // [macOS]
104- - (UIWindow *)alertWindow
142+ - (RCTPlatformWindow *)alertWindow // [macOS]
105143{
106144 if (_alertWindow == nil ) {
145+ #if !TARGET_OS_OSX // [macOS]
107146 _alertWindow = [[UIWindow alloc ] initWithWindowScene: RCTKeyWindow ().windowScene];
108147
109148 if (_alertWindow) {
110149 _alertWindow.rootViewController = [UIViewController new ];
111150 _alertWindow.windowLevel = UIWindowLevelAlert + 1 ;
112151 }
152+ #else // [macOS]
153+ _alertWindow = [[NSWindow alloc ] initWithContentRect: NSMakeRect (0 , 0 , 100 , 100 )
154+ styleMask: NSWindowStyleMaskBorderless | NSWindowStyleMaskFullSizeContentView
155+ backing: NSBackingStoreBuffered
156+ defer: YES ];
157+ _alertWindow.backgroundColor = [NSColor clearColor ];
158+ _alertWindow.opaque = NO ;
159+ #endif // macOS]
113160 }
114161
115162 return _alertWindow;
116163}
117- #endif // [macOS]
118164
119165- (void )showWithMessage : (NSString *)message onResume : (void (^)(void ))onResume
120166{
@@ -125,9 +171,21 @@ - (void)showWithMessage:(NSString *)message onResume:(void (^)(void))onResume
125171 view.modalPresentationStyle = UIModalPresentationOverFullScreen;
126172 view.message = message;
127173 view.onResume = onResume;
174+
128175 [self .alertWindow makeKeyAndVisible ];
129176 [self .alertWindow.rootViewController presentViewController: view animated: NO completion: nil ];
130- #endif // [macOS]
177+ #else // [macOS]
178+ self.alertWindow .contentViewController = view;
179+ view.message = message;
180+ view.onResume = onResume;
181+
182+ NSWindow *parentWindow = RCTKeyWindow ();
183+ if (![[parentWindow sheets ] doesContain: self ->_alertWindow]) {
184+ [parentWindow beginSheet: self .alertWindow completionHandler: ^(NSModalResponse returnCode) {
185+ [self ->_alertWindow orderOut: self ];
186+ }];
187+ }
188+ #endif // macOS]
131189}
132190
133191- (void )hide
@@ -136,9 +194,19 @@ - (void)hide
136194 [_alertWindow setHidden: YES ];
137195
138196 _alertWindow.windowScene = nil ;
197+ #else // [macOS]
198+ NSWindow *parentWindow = RCTKeyWindow ();
199+ if (parentWindow) {
200+ for (NSWindow *sheet in [parentWindow sheets ]) {
201+ if (sheet == _alertWindow) {
202+ [parentWindow endSheet: sheet];
203+ break ;
204+ }
205+ }
206+ }
207+ #endif // macOS]
139208
140209 _alertWindow = nil ;
141- #endif // macOS]
142210}
143211
144212@end
0 commit comments