Skip to content

Commit

Permalink
fix(ios): remove applicationState check on keyboard plugin (#2820)
Browse files Browse the repository at this point in the history
  • Loading branch information
jcesarmobile committed Apr 29, 2020
1 parent 55c3d52 commit dbc1da1
Showing 1 changed file with 28 additions and 36 deletions.
64 changes: 28 additions & 36 deletions ios/Capacitor/Capacitor/Plugins/Keyboard.m
Original file line number Diff line number Diff line change
Expand Up @@ -110,59 +110,51 @@ - (void)resetScrollView

- (void)onKeyboardWillHide:(NSNotification *)notification
{
if ([UIApplication sharedApplication].applicationState == UIApplicationStateActive) {
[self setKeyboardHeight:0 delay:0.01];
[self resetScrollView];
hideTimer = [NSTimer scheduledTimerWithTimeInterval:0 repeats:NO block:^(NSTimer * _Nonnull timer) {
[self.bridge triggerWindowJSEventWithEventName:@"keyboardWillHide"];
[self notifyListeners:@"keyboardWillHide" data:nil];
}];
}
[self setKeyboardHeight:0 delay:0.01];
[self resetScrollView];
hideTimer = [NSTimer scheduledTimerWithTimeInterval:0 repeats:NO block:^(NSTimer * _Nonnull timer) {
[self.bridge triggerWindowJSEventWithEventName:@"keyboardWillHide"];
[self notifyListeners:@"keyboardWillHide" data:nil];
}];
}

- (void)onKeyboardWillShow:(NSNotification *)notification
{
[self changeKeyboardStyle:self.keyboardStyle];
if ([UIApplication sharedApplication].applicationState == UIApplicationStateActive) {
if (hideTimer != nil) {
[hideTimer invalidate];
}
CGRect rect = [[notification.userInfo valueForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue];
double height = rect.size.height;
if (hideTimer != nil) {
[hideTimer invalidate];
}
CGRect rect = [[notification.userInfo valueForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue];
double height = rect.size.height;

double duration = [[notification.userInfo valueForKey:UIKeyboardAnimationDurationUserInfoKey] doubleValue]+0.2;
[self setKeyboardHeight:height delay:duration];
[self resetScrollView];
double duration = [[notification.userInfo valueForKey:UIKeyboardAnimationDurationUserInfoKey] doubleValue]+0.2;
[self setKeyboardHeight:height delay:duration];
[self resetScrollView];

NSString * data = [NSString stringWithFormat:@"{ 'keyboardHeight': %d }", (int)height];
[self.bridge triggerWindowJSEventWithEventName:@"keyboardWillShow" data:data];
NSDictionary * kbData = @{@"keyboardHeight": [NSNumber numberWithDouble:height]};
[self notifyListeners:@"keyboardWillShow" data:kbData];
}
NSString * data = [NSString stringWithFormat:@"{ 'keyboardHeight': %d }", (int)height];
[self.bridge triggerWindowJSEventWithEventName:@"keyboardWillShow" data:data];
NSDictionary * kbData = @{@"keyboardHeight": [NSNumber numberWithDouble:height]};
[self notifyListeners:@"keyboardWillShow" data:kbData];
}

- (void)onKeyboardDidShow:(NSNotification *)notification
{
if ([UIApplication sharedApplication].applicationState == UIApplicationStateActive) {
CGRect rect = [[notification.userInfo valueForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue];
double height = rect.size.height;
CGRect rect = [[notification.userInfo valueForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue];
double height = rect.size.height;

[self resetScrollView];
[self resetScrollView];

NSString * data = [NSString stringWithFormat:@"{ 'keyboardHeight': %d }", (int)height];
[self.bridge triggerWindowJSEventWithEventName:@"keyboardDidShow" data:data];
NSDictionary * kbData = @{@"keyboardHeight": [NSNumber numberWithDouble:height]};
[self notifyListeners:@"keyboardDidShow" data:kbData];
}
NSString * data = [NSString stringWithFormat:@"{ 'keyboardHeight': %d }", (int)height];
[self.bridge triggerWindowJSEventWithEventName:@"keyboardDidShow" data:data];
NSDictionary * kbData = @{@"keyboardHeight": [NSNumber numberWithDouble:height]};
[self notifyListeners:@"keyboardDidShow" data:kbData];
}

- (void)onKeyboardDidHide:(NSNotification *)notification
{
if ([UIApplication sharedApplication].applicationState == UIApplicationStateActive) {
[self.bridge triggerWindowJSEventWithEventName:@"keyboardDidHide"];
[self notifyListeners:@"keyboardDidHide" data:nil];
[self resetScrollView];
}
[self.bridge triggerWindowJSEventWithEventName:@"keyboardDidHide"];
[self notifyListeners:@"keyboardDidHide" data:nil];
[self resetScrollView];
}

- (void)setKeyboardHeight:(int)height delay:(NSTimeInterval)delay
Expand Down

0 comments on commit dbc1da1

Please sign in to comment.