@@ -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,18 +57,29 @@ - (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
UIImage *image = [UIImage systemImageNamed: @" forward.frame.fill" ];
61
63
[resumeButton setImage: image forState: UIControlStateNormal];
62
64
[resumeButton setImage: image forState: UIControlStateDisabled];
63
65
resumeButton.tintColor = [UIColor colorWithRed: 0.37 green: 0.37 blue: 0.37 alpha: 1 ];
64
66
65
67
resumeButton.enabled = NO ;
68
+ #else // [macOS
69
+ NSButton *resumeButton = [[NSButton alloc ] init ];
70
+ [resumeButton setImage: [NSImage imageWithSystemSymbolName: @" forward.frame.fill" accessibilityDescription: @" Resume" ]];
71
+ resumeButton.bordered = NO ;
72
+ resumeButton.target = self;
73
+ resumeButton.action = @selector (handleResume: );
74
+ resumeButton.contentTintColor = [NSColor colorWithRed: 0.37 green: 0.37 blue: 0.37 alpha: 1 ];
75
+ #endif // macOS]
76
+
66
77
[NSLayoutConstraint activateConstraints: @[
67
78
[resumeButton.widthAnchor constraintEqualToConstant: 48 ],
68
79
[resumeButton.heightAnchor constraintEqualToConstant: 46 ],
69
80
]];
70
81
82
+ #if !TARGET_OS_OSX // [macOS]
71
83
UIStackView *stackView = [[UIStackView alloc ] initWithArrangedSubviews: @[ messageContainer, resumeButton ]];
72
84
stackView.backgroundColor = [UIColor colorWithRed: 1 green: 1 blue: 0.757 alpha: 1 ];
73
85
stackView.layer .cornerRadius = 12 ;
@@ -82,41 +94,75 @@ - (void)viewDidLoad
82
94
action: @selector (handleResume: )];
83
95
[stackView addGestureRecognizer: gestureRecognizer];
84
96
stackView.userInteractionEnabled = YES ;
97
+ #else // [macOS
98
+ NSStackView *stackView = [NSStackView stackViewWithViews: @[ messageContainer, resumeButton ]];
99
+ stackView.wantsLayer = YES ;
100
+ stackView.layer .backgroundColor = [NSColor colorWithRed: 1 green: 1 blue: 0.757 alpha: 1 ].CGColor ;
101
+ stackView.translatesAutoresizingMaskIntoConstraints = NO ;
102
+ stackView.orientation = NSUserInterfaceLayoutOrientationHorizontal;
103
+ stackView.distribution = NSStackViewDistributionFill;
104
+ stackView.alignment = NSLayoutAttributeCenterY;
105
+
106
+ NSClickGestureRecognizer *gestureRecognizer = [[NSClickGestureRecognizer alloc ] initWithTarget: self
107
+ action: @selector (handleResume: )];
108
+ [stackView addGestureRecognizer: gestureRecognizer];
109
+ #endif // macOS]
85
110
111
+ #if !TARGET_OS_OSX
86
112
[self .view addSubview: stackView];
87
113
88
114
[NSLayoutConstraint activateConstraints: @[
89
115
[stackView.topAnchor constraintEqualToAnchor: self .view.safeAreaLayoutGuide.topAnchor constant: 12 ],
90
116
[stackView.centerXAnchor constraintEqualToAnchor: self .view.safeAreaLayoutGuide.centerXAnchor],
91
117
]];
118
+ #else
119
+ [self setView: stackView];
120
+ #endif
92
121
122
+ #if !TARGET_OS_OSX // [macOS]
93
123
stackView.semanticContentAttribute = UISemanticContentAttributeForceLeftToRight;
124
+ #else // [macOS
125
+ stackView.userInterfaceLayoutDirection = NSUserInterfaceLayoutDirectionLeftToRight;
126
+ #endif // macOS]
94
127
}
95
128
129
+ #if !TARGET_OS_OSX // [macOS]
96
130
- (void )handleResume : (UITapGestureRecognizer *)recognizer
97
131
{
98
132
self.onResume ();
99
133
}
100
- #endif // [macOS]
134
+ #else // [macOS
135
+ - (void )handleResume : (id )sender
136
+ {
137
+ self.onResume ();
138
+ }
139
+ #endif // macOS]
101
140
@end
102
141
103
142
@implementation RCTPausedInDebuggerOverlayController
104
143
105
- #if !TARGET_OS_OSX // [macOS]
106
- - (UIWindow *)alertWindow
144
+ - (RCTPlatformWindow *)alertWindow // [macOS]
107
145
{
108
146
if (_alertWindow == nil ) {
147
+ #if !TARGET_OS_OSX // [macOS]
109
148
_alertWindow = [[UIWindow alloc ] initWithWindowScene: RCTKeyWindow ().windowScene];
110
149
111
150
if (_alertWindow) {
112
151
_alertWindow.rootViewController = [UIViewController new ];
113
152
_alertWindow.windowLevel = UIWindowLevelAlert + 1 ;
114
153
}
154
+ #else // [macOS]
155
+ _alertWindow = [[NSWindow alloc ] initWithContentRect: NSMakeRect (0 , 0 , 100 , 100 )
156
+ styleMask: NSWindowStyleMaskBorderless | NSWindowStyleMaskFullSizeContentView
157
+ backing: NSBackingStoreBuffered
158
+ defer: YES ];
159
+ _alertWindow.backgroundColor = [NSColor clearColor ];
160
+ _alertWindow.opaque = NO ;
161
+ #endif // macOS]
115
162
}
116
163
117
164
return _alertWindow;
118
165
}
119
- #endif // [macOS]
120
166
121
167
- (void )showWithMessage : (NSString *)message onResume : (void (^)(void ))onResume
122
168
{
@@ -127,9 +173,21 @@ - (void)showWithMessage:(NSString *)message onResume:(void (^)(void))onResume
127
173
view.modalPresentationStyle = UIModalPresentationOverFullScreen;
128
174
view.message = message;
129
175
view.onResume = onResume;
176
+
130
177
[self .alertWindow makeKeyAndVisible ];
131
178
[self .alertWindow.rootViewController presentViewController: view animated: NO completion: nil ];
132
- #endif // [macOS]
179
+ #else // [macOS]
180
+ self.alertWindow .contentViewController = view;
181
+ view.message = message;
182
+ view.onResume = onResume;
183
+
184
+ NSWindow *parentWindow = RCTKeyWindow ();
185
+ if (![[parentWindow sheets ] doesContain: self ->_alertWindow]) {
186
+ [parentWindow beginSheet: self .alertWindow completionHandler: ^(NSModalResponse returnCode) {
187
+ [self ->_alertWindow orderOut: self ];
188
+ }];
189
+ }
190
+ #endif // macOS]
133
191
}
134
192
135
193
- (void )hide
@@ -138,9 +196,19 @@ - (void)hide
138
196
[_alertWindow setHidden: YES ];
139
197
140
198
_alertWindow.windowScene = nil ;
199
+ #else // [macOS]
200
+ NSWindow *parentWindow = RCTKeyWindow ();
201
+ if (parentWindow) {
202
+ for (NSWindow *sheet in [parentWindow sheets ]) {
203
+ if (sheet == _alertWindow) {
204
+ [parentWindow endSheet: sheet];
205
+ break ;
206
+ }
207
+ }
208
+ }
209
+ #endif // macOS]
141
210
142
211
_alertWindow = nil ;
143
- #endif // macOS]
144
212
}
145
213
146
214
@end
0 commit comments