From f57fd7dc770faf39e5133a615bdfd8617934bdc5 Mon Sep 17 00:00:00 2001 From: Alexei Date: Tue, 17 Mar 2026 08:22:20 +0300 Subject: [PATCH] fix(ios): expose keyboard animation params as CSS custom properties Set --keyboard-height, --keyboard-animation-duration, and --keyboard-animation-curve CSS variables on document.body, enabling web content to animate in sync with the iOS keyboard. Removes the artificial 0.2s delay previously added to the animation duration. --- ios/Sources/KeyboardPlugin/Keyboard.m | 32 ++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/ios/Sources/KeyboardPlugin/Keyboard.m b/ios/Sources/KeyboardPlugin/Keyboard.m index 29c0708..5694572 100644 --- a/ios/Sources/KeyboardPlugin/Keyboard.m +++ b/ios/Sources/KeyboardPlugin/Keyboard.m @@ -142,8 +142,34 @@ - (void)onKeyboardWillShow:(NSNotification *)notification } } - double duration = [[notification.userInfo valueForKey:UIKeyboardAnimationDurationUserInfoKey] doubleValue]+0.2; - [self setKeyboardHeight:height delay:duration]; + // Extract animation curve and convert to CSS timing function string + NSInteger animationCurve = [[notification.userInfo valueForKey:UIKeyboardAnimationCurveUserInfoKey] integerValue]; + NSString *curveString; + switch (animationCurve) { + case UIViewAnimationCurveEaseInOut: + curveString = @"ease-in-out"; + break; + case UIViewAnimationCurveEaseIn: + curveString = @"ease-in"; + break; + case UIViewAnimationCurveEaseOut: + curveString = @"ease-out"; + break; + case UIViewAnimationCurveLinear: + curveString = @"linear"; + break; + default: + curveString = @"ease-in-out"; + break; + } + + // Set CSS variables on body element + double duration = [[notification.userInfo valueForKey:UIKeyboardAnimationDurationUserInfoKey] doubleValue]; + if (duration > 0) { + [self.bridge evalWithJs: [NSString stringWithFormat:@"(function() { document.body.style.setProperty('--keyboard-animation-duration', '%fs'); document.body.style.setProperty('--keyboard-animation-curve', '%@'); })()", duration, curveString]]; + } + + [self setKeyboardHeight:height delay:0]; [self resetScrollView]; NSString * data = [NSString stringWithFormat:@"{ 'keyboardHeight': %d }", (int)height]; @@ -180,6 +206,7 @@ - (void)setKeyboardHeight:(int)height delay:(NSTimeInterval)delay return; } + [self.bridge evalWithJs: [NSString stringWithFormat:@"(function() { document.body.style.setProperty('--keyboard-height', '%dpx'); })()", height]]; self.paddingBottom = height; __weak KeyboardPlugin* weakSelf = self; @@ -403,4 +430,3 @@ - (void)dealloc @end #pragma clang diagnostic pop -