Skip to content

Commit b38fce1

Browse files
committed
fix(keyboard): Remove iOS keyboard delay (ionic-team#1904)
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 ionic-team#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.
1 parent d73d33b commit b38fce1

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

keyboard/ios/Sources/KeyboardPlugin/Keyboard.m

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ - (void)resetScrollView
110110

111111
- (void)onKeyboardWillHide:(NSNotification *)notification
112112
{
113-
[self setKeyboardHeight:0 delay:0.01];
113+
[self setKeyboardHeight:0 delay:0];
114114
[self resetScrollView];
115115
hideTimer = [NSTimer scheduledTimerWithTimeInterval:0 repeats:NO block:^(NSTimer * _Nonnull timer) {
116116
[self.bridge triggerWindowJSEventWithEventName:@"keyboardWillHide"];
@@ -142,8 +142,7 @@ - (void)onKeyboardWillShow:(NSNotification *)notification
142142
}
143143
}
144144

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

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

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

205204
- (void)_updateFrame

0 commit comments

Comments
 (0)