File tree 3 files changed +33
-1
lines changed
3 files changed +33
-1
lines changed Original file line number Diff line number Diff line change 10
10
@interface RCTAlertController : UIAlertController
11
11
12
12
- (void )show : (BOOL )animated completion : (void (^)(void ))completion ;
13
+ - (void )hide ;
13
14
14
15
@end
Original file line number Diff line number Diff line change 9
9
10
10
#import < React/RCTAlertController.h>
11
11
12
+ @interface RCTAlertController ()
13
+
14
+ @property (nonatomic , strong ) UIWindow *alertWindow;
15
+
16
+ @end
17
+
12
18
@implementation RCTAlertController
13
19
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
+
14
30
- (void )show : (BOOL )animated completion : (void (^)(void ))completion
15
31
{
16
32
if (@available (iOS 13.0 , *)) {
17
33
UIUserInterfaceStyle style =
18
34
RCTSharedApplication ().delegate .window .overrideUserInterfaceStyle ?: UIUserInterfaceStyleUnspecified;
19
35
self.overrideUserInterfaceStyle = style;
20
36
}
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 ;
22
50
}
23
51
24
52
@end
Original file line number Diff line number Diff line change @@ -185,17 +185,20 @@ - (void)invalidate
185
185
case RCTAlertViewStylePlainTextInput:
186
186
case RCTAlertViewStyleSecureTextInput:
187
187
callback (@[ buttonKey, [weakAlertController.textFields.firstObject text ] ]);
188
+ [weakAlertController hide ];
188
189
break ;
189
190
case RCTAlertViewStyleLoginAndPasswordInput: {
190
191
NSDictionary <NSString *, NSString *> *loginCredentials = @{
191
192
@" login" : [weakAlertController.textFields.firstObject text ],
192
193
@" password" : [weakAlertController.textFields.lastObject text ]
193
194
};
194
195
callback (@[ buttonKey, loginCredentials ]);
196
+ [weakAlertController hide ];
195
197
break ;
196
198
}
197
199
case RCTAlertViewStyleDefault:
198
200
callback (@[ buttonKey ]);
201
+ [weakAlertController hide ];
199
202
break ;
200
203
}
201
204
}];
You can’t perform that action at this time.
0 commit comments