@@ -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,6 +57,7 @@ - (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 ];
@@ -65,11 +67,21 @@ - (void)viewDidLoad
65
67
};
66
68
67
69
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
+
68
79
[NSLayoutConstraint activateConstraints: @[
69
80
[resumeButton.widthAnchor constraintEqualToConstant: 48 ],
70
81
[resumeButton.heightAnchor constraintEqualToConstant: 46 ],
71
82
]];
72
83
84
+ #if !TARGET_OS_OSX // [macOS]
73
85
UIStackView *stackView = [[UIStackView alloc ] initWithArrangedSubviews: @[ messageContainer, resumeButton ]];
74
86
stackView.backgroundColor = [UIColor colorWithRed: 1 green: 1 blue: 0.757 alpha: 1 ];
75
87
stackView.layer .cornerRadius = 12 ;
@@ -84,41 +96,75 @@ - (void)viewDidLoad
84
96
action: @selector (handleResume: )];
85
97
[stackView addGestureRecognizer: gestureRecognizer];
86
98
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]
87
112
113
+ #if !TARGET_OS_OSX
88
114
[self .view addSubview: stackView];
89
115
90
116
[NSLayoutConstraint activateConstraints: @[
91
117
[stackView.topAnchor constraintEqualToAnchor: self .view.safeAreaLayoutGuide.topAnchor constant: 12 ],
92
118
[stackView.centerXAnchor constraintEqualToAnchor: self .view.safeAreaLayoutGuide.centerXAnchor],
93
119
]];
120
+ #else
121
+ [self setView: stackView];
122
+ #endif
94
123
124
+ #if !TARGET_OS_OSX // [macOS]
95
125
stackView.semanticContentAttribute = UISemanticContentAttributeForceLeftToRight;
126
+ #else // [macOS
127
+ stackView.userInterfaceLayoutDirection = NSUserInterfaceLayoutDirectionLeftToRight;
128
+ #endif // macOS]
96
129
}
97
130
131
+ #if !TARGET_OS_OSX // [macOS]
98
132
- (void )handleResume : (UITapGestureRecognizer *)recognizer
99
133
{
100
134
self.onResume ();
101
135
}
102
- #endif // [macOS]
136
+ #else // [macOS
137
+ - (void )handleResume : (id )sender
138
+ {
139
+ self.onResume ();
140
+ }
141
+ #endif // macOS]
103
142
@end
104
143
105
144
@implementation RCTPausedInDebuggerOverlayController
106
145
107
- #if !TARGET_OS_OSX // [macOS]
108
- - (UIWindow *)alertWindow
146
+ - (RCTPlatformWindow *)alertWindow // [macOS]
109
147
{
110
148
if (_alertWindow == nil ) {
149
+ #if !TARGET_OS_OSX // [macOS]
111
150
_alertWindow = [[UIWindow alloc ] initWithWindowScene: RCTKeyWindow ().windowScene];
112
151
113
152
if (_alertWindow) {
114
153
_alertWindow.rootViewController = [UIViewController new ];
115
154
_alertWindow.windowLevel = UIWindowLevelAlert + 1 ;
116
155
}
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]
117
164
}
118
165
119
166
return _alertWindow;
120
167
}
121
- #endif // [macOS]
122
168
123
169
- (void )showWithMessage : (NSString *)message onResume : (void (^)(void ))onResume
124
170
{
@@ -129,9 +175,21 @@ - (void)showWithMessage:(NSString *)message onResume:(void (^)(void))onResume
129
175
view.modalPresentationStyle = UIModalPresentationOverFullScreen;
130
176
view.message = message;
131
177
view.onResume = onResume;
178
+
132
179
[self .alertWindow makeKeyAndVisible ];
133
180
[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]
135
193
}
136
194
137
195
- (void )hide
@@ -140,9 +198,19 @@ - (void)hide
140
198
[_alertWindow setHidden: YES ];
141
199
142
200
_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]
143
212
144
213
_alertWindow = nil ;
145
- #endif // macOS]
146
214
}
147
215
148
216
@end
0 commit comments