Skip to content

Commit

Permalink
Back out "Fix Alert not showing in an app using UIScene"
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Luna Wei authored and facebook-github-bot committed Sep 17, 2022
1 parent d15a82d commit ab5f26b
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
1 change: 1 addition & 0 deletions React/CoreModules/RCTAlertController.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@
@interface RCTAlertController : UIAlertController

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

@end
30 changes: 29 additions & 1 deletion React/CoreModules/RCTAlertController.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,44 @@

#import <React/RCTAlertController.h>

@interface RCTAlertController ()

@property (nonatomic, strong) UIWindow *alertWindow;

@end

@implementation RCTAlertController

- (UIWindow *)alertWindow
{
if (_alertWindow == nil) {
_alertWindow = [[UIWindow alloc] initWithFrame:RCTSharedApplication().keyWindow.bounds];
_alertWindow.rootViewController = [UIViewController new];
_alertWindow.windowLevel = UIWindowLevelAlert + 1;
}
return _alertWindow;
}

- (void)show:(BOOL)animated completion:(void (^)(void))completion
{
if (@available(iOS 13.0, *)) {
UIUserInterfaceStyle style =
RCTSharedApplication().delegate.window.overrideUserInterfaceStyle ?: UIUserInterfaceStyleUnspecified;
self.overrideUserInterfaceStyle = style;
}
[[RCTKeyWindow() rootViewController] presentViewController:self animated:animated completion:completion];
[self.alertWindow makeKeyAndVisible];
[self.alertWindow.rootViewController presentViewController:self animated:animated completion:completion];
}

- (void)hide
{
[_alertWindow setHidden:YES];

if (@available(iOS 13, *)) {
_alertWindow.windowScene = nil;
}

_alertWindow = nil;
}

@end
3 changes: 3 additions & 0 deletions React/CoreModules/RCTAlertManager.mm
Original file line number Diff line number Diff line change
Expand Up @@ -185,17 +185,20 @@ - (void)invalidate
case RCTAlertViewStylePlainTextInput:
case RCTAlertViewStyleSecureTextInput:
callback(@[ buttonKey, [weakAlertController.textFields.firstObject text] ]);
[weakAlertController hide];
break;
case RCTAlertViewStyleLoginAndPasswordInput: {
NSDictionary<NSString *, NSString *> *loginCredentials = @{
@"login" : [weakAlertController.textFields.firstObject text],
@"password" : [weakAlertController.textFields.lastObject text]
};
callback(@[ buttonKey, loginCredentials ]);
[weakAlertController hide];
break;
}
case RCTAlertViewStyleDefault:
callback(@[ buttonKey ]);
[weakAlertController hide];
break;
}
}];
Expand Down

0 comments on commit ab5f26b

Please sign in to comment.