-
-
Notifications
You must be signed in to change notification settings - Fork 36
/
Copy pathRNToastViewController.m
54 lines (43 loc) · 1.33 KB
/
RNToastViewController.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#import "RNToastViewController.h"
#import <React/RCTUtils.h>
#import "RNToastWindow.h"
@implementation RNToastViewController
- (UIWindow *)toastWindow
{
if (_toastWindow == nil) {
_toastWindow = [self getUIWindowFromScene];
if (_toastWindow == nil) {
UIWindow *keyWindow = RCTSharedApplication().keyWindow;
if (keyWindow) {
_toastWindow = [[RNToastWindow alloc] initWithFrame:keyWindow.bounds];
} else {
// keyWindow is nil, so we cannot create and initialize _toastWindow
NSLog(@"Unable to create alert window: keyWindow is nil");
}
}
}
return _toastWindow;
}
- (void)show {
[self.toastWindow setHidden:NO];
}
- (void)hide {
[_toastWindow setHidden:YES];
if (@available(iOS 13, *)) {
_toastWindow.windowScene = nil;
}
_toastWindow = nil;
}
- (UIWindow *)getUIWindowFromScene
{
if (@available(iOS 13.0, *)) {
for (UIScene *scene in RCTSharedApplication().connectedScenes) {
if (scene.activationState == UISceneActivationStateForegroundActive &&
[scene isKindOfClass:[UIWindowScene class]]) {
return [[RNToastWindow alloc] initWithWindowScene:(UIWindowScene *)scene];
}
}
}
return nil;
}
@end