1919@interface LRDRCTSimpleToast : NSObject <RCTBridgeModule>
2020@end
2121
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+
2355
2456RCT_EXPORT_MODULE ()
2557
@@ -45,6 +77,7 @@ - (void)_show:(NSString *)msg duration:(NSTimeInterval)duration gravity:(NSInteg
4577 dispatch_async (dispatch_get_main_queue (), ^{
4678 UIView *root = [[[[[UIApplication sharedApplication ] delegate ] window ] rootViewController ] view ];
4779 CGRect bound = root.bounds ;
80+ bound.size .height -= _keyOffset;
4881 if (bound.size .height > LRDRCTSimpleToastBottomOffset*2 ) {
4982 bound.origin .y += LRDRCTSimpleToastBottomOffset;
5083 bound.size .height -= LRDRCTSimpleToastBottomOffset*2 ;
0 commit comments