Skip to content

Commit

Permalink
fix(keyboard): Remove iOS keyboard delay (#1904)
Browse files Browse the repository at this point in the history
This fix aligns with the Android implementation of no delay.

This fix removes all keyboard delay, including the 0.01 second
delay for hiding. I believe this delay existed due to a slight
flicker observed when setting delay to 0. However, by
wrapping the height javascript logic in
`requestAnimationFrame()` the flicker is no longer present.

I believe this is a better solution than #2230 because it
avoids adding animations. (Users can do this themselves
by disabling resizing and hooking into keyboardWillShow,
didShow, willHide, and didHide events in javascript.)

It also avoids magic/arbitrary delay amounts, like 0.01.
  • Loading branch information
aeharding committed Nov 6, 2024
1 parent d73d33b commit b38fce1
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions keyboard/ios/Sources/KeyboardPlugin/Keyboard.m
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ - (void)resetScrollView

- (void)onKeyboardWillHide:(NSNotification *)notification
{
[self setKeyboardHeight:0 delay:0.01];
[self setKeyboardHeight:0 delay:0];
[self resetScrollView];
hideTimer = [NSTimer scheduledTimerWithTimeInterval:0 repeats:NO block:^(NSTimer * _Nonnull timer) {
[self.bridge triggerWindowJSEventWithEventName:@"keyboardWillHide"];
Expand Down Expand Up @@ -142,8 +142,7 @@ - (void)onKeyboardWillShow:(NSNotification *)notification
}
}

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

NSString * data = [NSString stringWithFormat:@"{ 'keyboardHeight': %d }", (int)height];
Expand Down Expand Up @@ -199,7 +198,7 @@ - (void)resizeElement:(NSString *)element withPaddingBottom:(int)paddingBottom w
height = screenHeight - paddingBottom;
}

[self.bridge evalWithJs: [NSString stringWithFormat:@"(function() { var el = %@; var height = %d; if (el) { el.style.height = height > -1 ? height + 'px' : null; } })()", element, height]];
[self.bridge evalWithJs: [NSString stringWithFormat:@"requestAnimationFrame(() => { var el = %@; var height = %d; if (el) { el.style.height = height > -1 ? height + 'px' : null; } })", element, height]];
}

- (void)_updateFrame
Expand Down

0 comments on commit b38fce1

Please sign in to comment.