19
19
@interface LRDRCTSimpleToast : NSObject <RCTBridgeModule>
20
20
@end
21
21
22
- @implementation LRDRCTSimpleToast
22
+ @implementation LRDRCTSimpleToast {
23
+ CGFloat _keyOffset;
24
+ }
25
+
26
+ - (instancetype )init {
27
+ if (self = [super init ]) {
28
+ _keyOffset = 0 ;
29
+ [[NSNotificationCenter defaultCenter ] addObserver: self
30
+ selector: @selector (keyboardWasShown: )
31
+ name: UIKeyboardDidShowNotification
32
+ object: nil ];
33
+ [[NSNotificationCenter defaultCenter ] addObserver: self
34
+ selector: @selector (keyboardWillHiden: )
35
+ name: UIKeyboardWillHideNotification
36
+ object: nil ];
37
+ }
38
+ return self;
39
+ }
40
+
41
+ - (void )keyboardWasShown : (NSNotification *)notification {
42
+
43
+ CGSize keyboardSize = [[[notification userInfo ] objectForKey: UIKeyboardFrameBeginUserInfoKey] CGRectValue ].size ;
44
+
45
+ int height = MIN (keyboardSize.height ,keyboardSize.width );
46
+ int width = MAX (keyboardSize.height ,keyboardSize.width );
47
+
48
+ _keyOffset = height;
49
+ }
50
+
51
+ - (void )keyboardWillHiden : (NSNotification *)notification {
52
+ _keyOffset = 0 ;
53
+ }
54
+
23
55
24
56
RCT_EXPORT_MODULE ()
25
57
@@ -45,6 +77,7 @@ - (void)_show:(NSString *)msg duration:(NSTimeInterval)duration gravity:(NSInteg
45
77
dispatch_async (dispatch_get_main_queue (), ^{
46
78
UIView *root = [[[[[UIApplication sharedApplication ] delegate ] window ] rootViewController ] view ];
47
79
CGRect bound = root.bounds ;
80
+ bound.size .height -= _keyOffset;
48
81
if (bound.size .height > LRDRCTSimpleToastBottomOffset*2 ) {
49
82
bound.origin .y += LRDRCTSimpleToastBottomOffset;
50
83
bound.size .height -= LRDRCTSimpleToastBottomOffset*2 ;
0 commit comments