File tree 4 files changed +33
-78
lines changed
4 files changed +33
-78
lines changed Original file line number Diff line number Diff line change 1
1
#import " RNSimpleToast.h"
2
2
3
3
#import " UIView+Toast.h"
4
- #import " RNToastViewController.h"
5
4
#import < React/RCTConvert.h>
6
5
#import " RNToastView.h"
6
+ #import " RNToastWindow.h"
7
7
8
8
static double defaultPositionId = 2.0 ;
9
9
@@ -106,18 +106,17 @@ - (void)_show:(NSString *)msg
106
106
107
107
NSString *positionString = RNToastPositionMap[@(position)] ?: CSToastPositionBottom;
108
108
dispatch_async (dispatch_get_main_queue (), ^{
109
- RNToastViewController *controller = [RNToastViewController new ];
110
- [controller show ];
109
+ UIWindow *window = [RNToastWindow new ];
111
110
BOOL kbdAvoidEnabled = [CSToastPositionBottom isEqualToString: positionString];
112
- UIView *view = [[RNToastView alloc ] initWithFrame: controller.toastWindow .bounds kbdHeight: self ->_kbdHeight kbdAvoidEnabled: kbdAvoidEnabled];
113
- [controller.toastWindow addSubview: view];
111
+ UIView *view = [[RNToastView alloc ] initWithFrame: window .bounds kbdHeight: self ->_kbdHeight kbdAvoidEnabled: kbdAvoidEnabled];
112
+ [window addSubview: view];
114
113
UIView __weak *weakView = view;
115
114
116
115
UIView *toast = [view toastViewForMessage: msg title: nil image: nil style: style];
117
116
118
117
void (^completion)(BOOL ) = ^(BOOL didTap) {
119
118
[weakView removeFromSuperview ];
120
- [controller hide ];
119
+ [window setHidden: YES ];
121
120
};
122
121
// CSToastManager state is shared among toasts, and is used when toast is shown
123
122
// so modifications to it should happen in the dispatch_get_main_queue block
Load Diff This file was deleted.
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 1
1
#import " RNToastWindow.h"
2
+ #import < React/RCTUtils.h>
2
3
3
4
@implementation RNToastWindow
4
5
5
- - (instancetype )initWithFrame : (CGRect )frame {
6
- if (self = [super initWithFrame: frame]) {
7
- self.windowLevel = UIWindowLevelAlert + 1 ;
6
+ - (instancetype )init
7
+ {
8
+ if (@available (iOS 13.0 , *)) {
9
+ for (UIScene *scene in RCTSharedApplication ().connectedScenes ) {
10
+ if (scene.activationState == UISceneActivationStateForegroundActive &&
11
+ [scene isKindOfClass: [UIWindowScene class ]]) {
12
+ self = [super initWithWindowScene: (UIWindowScene *)scene];
13
+ }
14
+ }
8
15
}
9
- return self;
10
- }
11
-
12
- - (instancetype )initWithWindowScene : (UIWindowScene *)windowScene {
13
- if (self = [super initWithWindowScene: windowScene]) {
16
+ if (!self) {
17
+ UIWindow *keyWindow = RCTSharedApplication ().keyWindow ;
18
+ if (keyWindow) {
19
+ self = [super initWithFrame: keyWindow.bounds];
20
+ } else {
21
+ // keyWindow is nil, so we cannot create and initialize _toastWindow
22
+ NSLog (@" Unable to create alert window: keyWindow is nil" );
23
+ }
24
+ }
25
+ if (self) {
26
+ [self setHidden: NO ];
14
27
self.windowLevel = UIWindowLevelAlert + 1 ;
15
28
}
16
29
return self;
@@ -22,4 +35,11 @@ - (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event {
22
35
else return hitView;
23
36
}
24
37
38
+ - (void )dealloc
39
+ {
40
+ if (@available (iOS 13 , *)) {
41
+ self.windowScene = nil ;
42
+ }
43
+ }
44
+
25
45
@end
You can’t perform that action at this time.
0 commit comments