Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -1520,6 +1520,15 @@ - (void)handleKeyboardNotification:(NSNotification*)notification {
BOOL keyboardAnimationIsCompounding =
self.keyboardAnimationIsShowing == keyboardWillShow && _keyboardAnimationVSyncClient != nil;

// Avoid triggering startKeyBoardAnimation when keyboard notifications are triggered
// by the dismissal of password autofill prompt. When this happens, there is
// no keyboard on the screen and FlutterTextInputViewAccessibilityHider is nil.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice.

FlutterTextInputPlugin* textInputPlugin = self.engine.textInputPlugin;
UIView* textInputHider = [[textInputPlugin textInputView] superview];
if (keyboardWillShow && textInputHider == nil) {
return;
}

// Mark keyboard as showing or hiding.
self.keyboardAnimationIsShowing = keyboardWillShow;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,18 @@ - (void)testKeyboardAnimationIsShowingAndCompounding {
FlutterViewController* viewController = [[FlutterViewController alloc] initWithEngine:engine
nibName:nil
bundle:nil];
FlutterMethodCall* setClientCall =
[FlutterMethodCall methodCallWithMethodName:@"TextInput.setClient"
arguments:@[ @(123), @{@"autocorrect" : @YES} ]];
[engine.textInputPlugin handleMethodCall:setClientCall
result:^(id _Nullable result){
}];

// Check if FlutterTextInputViewAccessibilityHider exists.
FlutterTextInputPlugin* textInputPlugin = engine.textInputPlugin;
UIView* textInputHider = [[textInputPlugin textInputView] superview];
XCTAssertNotNil(textInputHider);

FlutterViewController* viewControllerMock = OCMPartialMock(viewController);
UIScreen* screen = [self setUpMockScreen];
CGRect viewFrame = screen.bounds;
Expand Down Expand Up @@ -2188,4 +2200,46 @@ - (void)testFlutterViewControllerStartKeyboardAnimationWillCreateVsyncClientCorr
XCTAssertNil(viewController.keyboardAnimationVSyncClient);
}

- (void)testAvoidKeyboardAnimationWhenFlutterTextInputViewAccessibilityHiderIsNil {
FlutterEngine* engine = [[FlutterEngine alloc] init];
[engine runWithEntrypoint:nil];
FlutterViewController* viewController = [[FlutterViewController alloc] initWithEngine:engine
nibName:nil
bundle:nil];

FlutterViewController* viewControllerMock = OCMPartialMock(viewController);
UIScreen* screen = [self setUpMockScreen];
CGRect viewFrame = screen.bounds;
[self setUpMockView:viewControllerMock
screen:screen
viewFrame:viewFrame
convertedFrame:viewFrame];

CGFloat screenHeight = screen.bounds.size.height;
CGFloat screenWidth = screen.bounds.size.height;

// Check if FlutterTextInputViewAccessibilityHider is nil.
FlutterTextInputPlugin* textInputPlugin = engine.textInputPlugin;
UIView* textInputHider = [[textInputPlugin textInputView] superview];
XCTAssertNil(textInputHider);

// Start show keyboard animation.
CGRect showKeyboardBeginFrame = CGRectMake(0, screenHeight, screenWidth, 250);
CGRect showKeyboardEndFrame = CGRectMake(0, screenHeight - 250, screenWidth, 250);
NSNotification* fakeNotification =
[NSNotification notificationWithName:UIKeyboardWillChangeFrameNotification
object:nil
userInfo:@{
@"UIKeyboardFrameBeginUserInfoKey" : @(showKeyboardBeginFrame),
@"UIKeyboardFrameEndUserInfoKey" : @(showKeyboardEndFrame),
@"UIKeyboardAnimationDurationUserInfoKey" : @(0.25),
@"UIKeyboardIsLocalUserInfoKey" : @(YES)
}];

viewControllerMock.targetViewInsetBottom = 0;
[viewControllerMock handleKeyboardNotification:fakeNotification];
BOOL isShowingAnimation = viewControllerMock.keyboardAnimationIsShowing;
XCTAssertFalse(isShowingAnimation);
}

@end