Skip to content

Commit d52f7ff

Browse files
committed
Fix Alert not showing in an app using UIScene
Summary In an app using `UIScene`, `Alert` no longer pops up because the window that gets created are not attached to a scene. Changelog [iOS] [Fixed] - Fix `Alert` not showing in an app using `UIScene` Test Plan Use the test plan in #29295. This should not regress that fix.
1 parent 7aa203b commit d52f7ff

File tree

3 files changed

+1
-33
lines changed

3 files changed

+1
-33
lines changed

React/CoreModules/RCTAlertController.h

-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,5 @@
1010
@interface RCTAlertController : UIAlertController
1111

1212
- (void)show:(BOOL)animated completion:(void (^)(void))completion;
13-
- (void)hide;
1413

1514
@end

React/CoreModules/RCTAlertController.m

+1-29
Original file line numberDiff line numberDiff line change
@@ -9,44 +9,16 @@
99

1010
#import <React/RCTAlertController.h>
1111

12-
@interface RCTAlertController ()
13-
14-
@property (nonatomic, strong) UIWindow *alertWindow;
15-
16-
@end
17-
1812
@implementation RCTAlertController
1913

20-
- (UIWindow *)alertWindow
21-
{
22-
if (_alertWindow == nil) {
23-
_alertWindow = [[UIWindow alloc] initWithFrame:RCTSharedApplication().keyWindow.bounds];
24-
_alertWindow.rootViewController = [UIViewController new];
25-
_alertWindow.windowLevel = UIWindowLevelAlert + 1;
26-
}
27-
return _alertWindow;
28-
}
29-
3014
- (void)show:(BOOL)animated completion:(void (^)(void))completion
3115
{
3216
if (@available(iOS 13.0, *)) {
3317
UIUserInterfaceStyle style =
3418
RCTSharedApplication().delegate.window.overrideUserInterfaceStyle ?: UIUserInterfaceStyleUnspecified;
3519
self.overrideUserInterfaceStyle = style;
3620
}
37-
[self.alertWindow makeKeyAndVisible];
38-
[self.alertWindow.rootViewController presentViewController:self animated:animated completion:completion];
39-
}
40-
41-
- (void)hide
42-
{
43-
[_alertWindow setHidden:YES];
44-
45-
if (@available(iOS 13, *)) {
46-
_alertWindow.windowScene = nil;
47-
}
48-
49-
_alertWindow = nil;
21+
[[RCTKeyWindow() rootViewController] presentViewController:self animated:animated completion:completion];
5022
}
5123

5224
@end

React/CoreModules/RCTAlertManager.mm

-3
Original file line numberDiff line numberDiff line change
@@ -185,20 +185,17 @@ - (void)invalidate
185185
case RCTAlertViewStylePlainTextInput:
186186
case RCTAlertViewStyleSecureTextInput:
187187
callback(@[ buttonKey, [weakAlertController.textFields.firstObject text] ]);
188-
[weakAlertController hide];
189188
break;
190189
case RCTAlertViewStyleLoginAndPasswordInput: {
191190
NSDictionary<NSString *, NSString *> *loginCredentials = @{
192191
@"login" : [weakAlertController.textFields.firstObject text],
193192
@"password" : [weakAlertController.textFields.lastObject text]
194193
};
195194
callback(@[ buttonKey, loginCredentials ]);
196-
[weakAlertController hide];
197195
break;
198196
}
199197
case RCTAlertViewStyleDefault:
200198
callback(@[ buttonKey ]);
201-
[weakAlertController hide];
202199
break;
203200
}
204201
}];

0 commit comments

Comments
 (0)