Skip to content

Commit ab5f26b

Browse files
Luna Weifacebook-github-bot
Luna Wei
authored andcommitted
Back out "Fix Alert not showing in an app using UIScene"
Summary: Changelog: [Internal] - Revert #34562 re: [iOS] [Fixed] - Fix Alert not showing in an app using UIScene Reviewed By: alsun2001 Differential Revision: D39591113 fbshipit-source-id: ba707c11b3fb97eb3a6fee32e57b92403aa8b3d8
1 parent d15a82d commit ab5f26b

File tree

3 files changed

+33
-1
lines changed

3 files changed

+33
-1
lines changed

React/CoreModules/RCTAlertController.h

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

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

1415
@end

React/CoreModules/RCTAlertController.m

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

1010
#import <React/RCTAlertController.h>
1111

12+
@interface RCTAlertController ()
13+
14+
@property (nonatomic, strong) UIWindow *alertWindow;
15+
16+
@end
17+
1218
@implementation RCTAlertController
1319

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+
1430
- (void)show:(BOOL)animated completion:(void (^)(void))completion
1531
{
1632
if (@available(iOS 13.0, *)) {
1733
UIUserInterfaceStyle style =
1834
RCTSharedApplication().delegate.window.overrideUserInterfaceStyle ?: UIUserInterfaceStyleUnspecified;
1935
self.overrideUserInterfaceStyle = style;
2036
}
21-
[[RCTKeyWindow() rootViewController] presentViewController:self animated:animated completion:completion];
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;
2250
}
2351

2452
@end

React/CoreModules/RCTAlertManager.mm

+3
Original file line numberDiff line numberDiff line change
@@ -185,17 +185,20 @@ - (void)invalidate
185185
case RCTAlertViewStylePlainTextInput:
186186
case RCTAlertViewStyleSecureTextInput:
187187
callback(@[ buttonKey, [weakAlertController.textFields.firstObject text] ]);
188+
[weakAlertController hide];
188189
break;
189190
case RCTAlertViewStyleLoginAndPasswordInput: {
190191
NSDictionary<NSString *, NSString *> *loginCredentials = @{
191192
@"login" : [weakAlertController.textFields.firstObject text],
192193
@"password" : [weakAlertController.textFields.lastObject text]
193194
};
194195
callback(@[ buttonKey, loginCredentials ]);
196+
[weakAlertController hide];
195197
break;
196198
}
197199
case RCTAlertViewStyleDefault:
198200
callback(@[ buttonKey ]);
201+
[weakAlertController hide];
199202
break;
200203
}
201204
}];

0 commit comments

Comments
 (0)