@@ -16,19 +16,17 @@ @interface RCTPausedInDebuggerViewController : UIViewController
16
16
@end
17
17
18
18
@interface RCTPausedInDebuggerOverlayController ()
19
- #if !TARGET_OS_OSX // [macOS]
20
19
21
- @property (nonatomic , strong ) UIWindow *alertWindow;
20
+ @property (nonatomic , strong ) RCTPlatformWindow *alertWindow; // [macOS]
22
21
23
- #endif // [macOS];
24
22
@end
25
23
26
24
@implementation RCTPausedInDebuggerViewController
27
- #if !TARGET_OS_OSX // [macOS]
28
25
- (void )viewDidLoad
29
26
{
30
27
[super viewDidLoad ];
31
28
29
+ #if !TARGET_OS_OSX // [macOS]
32
30
UIView *dimmingView = [[UIView alloc ] init ];
33
31
dimmingView.translatesAutoresizingMaskIntoConstraints = NO ;
34
32
dimmingView.backgroundColor = [[UIColor blackColor ] colorWithAlphaComponent: 0.2 ];
@@ -39,15 +37,18 @@ - (void)viewDidLoad
39
37
[dimmingView.leadingAnchor constraintEqualToAnchor: self .view.leadingAnchor],
40
38
[dimmingView.trailingAnchor constraintEqualToAnchor: self .view.trailingAnchor]
41
39
]];
42
-
43
- UILabel *messageLabel = [[UILabel alloc ] init ];
40
+ #endif // [macOS]
41
+
42
+ RCTUILabel *messageLabel = [[RCTUILabel alloc ] init ]; // [macOS]
44
43
messageLabel.text = self.message ;
45
44
messageLabel.textAlignment = NSTextAlignmentCenter;
45
+ #if !TARGET_OS_OSX // [macOS]
46
46
messageLabel.numberOfLines = 0 ;
47
+ #endif // [macOS]
47
48
messageLabel.font = [UIFont boldSystemFontOfSize: 16 ];
48
- messageLabel.textColor = [UIColor blackColor ];
49
+ messageLabel.textColor = [RCTUIColor blackColor ]; // [macOS]
49
50
messageLabel.translatesAutoresizingMaskIntoConstraints = NO ;
50
- UIView *messageContainer = [[UIView alloc ] init ];
51
+ RCTUIView *messageContainer = [[RCTUIView alloc ] init ]; // [macOS]
51
52
[messageContainer addSubview: messageLabel];
52
53
[NSLayoutConstraint activateConstraints: @[
53
54
[messageLabel.topAnchor constraintEqualToAnchor: messageContainer.topAnchor constant: -1 ],
@@ -56,16 +57,27 @@ - (void)viewDidLoad
56
57
[messageLabel.trailingAnchor constraintEqualToAnchor: messageContainer.trailingAnchor],
57
58
]];
58
59
60
+ #if !TARGET_OS_OSX // [macOS]
59
61
UIButton *resumeButton = [UIButton buttonWithType: UIButtonTypeCustom];
60
62
[resumeButton setImage: [UIImage systemImageNamed: @" forward.frame.fill" ] forState: UIControlStateNormal];
61
63
resumeButton.tintColor = [UIColor colorWithRed: 0.37 green: 0.37 blue: 0.37 alpha: 1 ];
62
64
resumeButton.adjustsImageWhenDisabled = NO ;
63
65
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
+
64
75
[NSLayoutConstraint activateConstraints: @[
65
76
[resumeButton.widthAnchor constraintEqualToConstant: 48 ],
66
77
[resumeButton.heightAnchor constraintEqualToConstant: 46 ],
67
78
]];
68
79
80
+ #if !TARGET_OS_OSX // [macOS]
69
81
UIStackView *stackView = [[UIStackView alloc ] initWithArrangedSubviews: @[ messageContainer, resumeButton ]];
70
82
stackView.backgroundColor = [UIColor colorWithRed: 1 green: 1 blue: 0.757 alpha: 1 ];
71
83
stackView.layer .cornerRadius = 12 ;
@@ -80,41 +92,75 @@ - (void)viewDidLoad
80
92
action: @selector (handleResume: )];
81
93
[stackView addGestureRecognizer: gestureRecognizer];
82
94
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]
83
108
109
+ #if !TARGET_OS_OSX
84
110
[self .view addSubview: stackView];
85
111
86
112
[NSLayoutConstraint activateConstraints: @[
87
113
[stackView.topAnchor constraintEqualToAnchor: self .view.safeAreaLayoutGuide.topAnchor constant: 12 ],
88
114
[stackView.centerXAnchor constraintEqualToAnchor: self .view.safeAreaLayoutGuide.centerXAnchor],
89
115
]];
116
+ #else
117
+ [self setView: stackView];
118
+ #endif
90
119
120
+ #if !TARGET_OS_OSX // [macOS]
91
121
stackView.semanticContentAttribute = UISemanticContentAttributeForceLeftToRight;
122
+ #else // [macOS
123
+ stackView.userInterfaceLayoutDirection = NSUserInterfaceLayoutDirectionLeftToRight;
124
+ #endif // macOS]
92
125
}
93
126
127
+ #if !TARGET_OS_OSX // [macOS]
94
128
- (void )handleResume : (UITapGestureRecognizer *)recognizer
95
129
{
96
130
self.onResume ();
97
131
}
98
- #endif // [macOS]
132
+ #else // [macOS
133
+ - (void )handleResume : (id )sender
134
+ {
135
+ self.onResume ();
136
+ }
137
+ #endif // macOS]
99
138
@end
100
139
101
140
@implementation RCTPausedInDebuggerOverlayController
102
141
103
- #if !TARGET_OS_OSX // [macOS]
104
- - (UIWindow *)alertWindow
142
+ - (RCTPlatformWindow *)alertWindow // [macOS]
105
143
{
106
144
if (_alertWindow == nil ) {
145
+ #if !TARGET_OS_OSX // [macOS]
107
146
_alertWindow = [[UIWindow alloc ] initWithWindowScene: RCTKeyWindow ().windowScene];
108
147
109
148
if (_alertWindow) {
110
149
_alertWindow.rootViewController = [UIViewController new ];
111
150
_alertWindow.windowLevel = UIWindowLevelAlert + 1 ;
112
151
}
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]
113
160
}
114
161
115
162
return _alertWindow;
116
163
}
117
- #endif // [macOS]
118
164
119
165
- (void )showWithMessage : (NSString *)message onResume : (void (^)(void ))onResume
120
166
{
@@ -125,9 +171,21 @@ - (void)showWithMessage:(NSString *)message onResume:(void (^)(void))onResume
125
171
view.modalPresentationStyle = UIModalPresentationOverFullScreen;
126
172
view.message = message;
127
173
view.onResume = onResume;
174
+
128
175
[self .alertWindow makeKeyAndVisible ];
129
176
[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]
131
189
}
132
190
133
191
- (void )hide
@@ -136,9 +194,19 @@ - (void)hide
136
194
[_alertWindow setHidden: YES ];
137
195
138
196
_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]
139
208
140
209
_alertWindow = nil ;
141
- #endif // macOS]
142
210
}
143
211
144
212
@end
0 commit comments