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