Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

fix(ios): remove applicationState check on keyboard plugin #2820

Merged
merged 1 commit into from
Apr 29, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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