Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit bf3ea6f

Browse files
committed
Fix iOS password autofill prompt dismissal causes layout to resize
1 parent 9bd98bc commit bf3ea6f

File tree

2 files changed

+63
-0
lines changed

2 files changed

+63
-0
lines changed

shell/platform/darwin/ios/framework/Source/FlutterViewController.mm

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1520,6 +1520,15 @@ - (void)handleKeyboardNotification:(NSNotification*)notification {
15201520
BOOL keyboardAnimationIsCompounding =
15211521
self.keyboardAnimationIsShowing == keyboardWillShow && _keyboardAnimationVSyncClient != nil;
15221522

1523+
// Avoid triggering startKeyBoardAnimation when keyboard notifications are triggered
1524+
// by the dismissal of password autofill prompt. When this happens, there is
1525+
// no keyboard on the screen and FlutterTextInputViewAccessibilityHider is nil.
1526+
FlutterTextInputPlugin* textInputPlugin = self.engine.textInputPlugin;
1527+
UIView* textInputHider = [[textInputPlugin textInputView] superview];
1528+
if (keyboardWillShow && textInputHider == nil) {
1529+
return;
1530+
}
1531+
15231532
// Mark keyboard as showing or hiding.
15241533
self.keyboardAnimationIsShowing = keyboardWillShow;
15251534

shell/platform/darwin/ios/framework/Source/FlutterViewControllerTest.mm

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,18 @@ - (void)testKeyboardAnimationIsShowingAndCompounding {
305305
FlutterViewController* viewController = [[FlutterViewController alloc] initWithEngine:engine
306306
nibName:nil
307307
bundle:nil];
308+
FlutterMethodCall* setClientCall =
309+
[FlutterMethodCall methodCallWithMethodName:@"TextInput.setClient"
310+
arguments:@[ @(123), @{@"autocorrect" : @YES} ]];
311+
[engine.textInputPlugin handleMethodCall:setClientCall
312+
result:^(id _Nullable result){
313+
}];
314+
315+
// Check if FlutterTextInputViewAccessibilityHider exist.
316+
FlutterTextInputPlugin* textInputPlugin = engine.textInputPlugin;
317+
UIView* textInputHider = [[textInputPlugin textInputView] superview];
318+
XCTAssertNotNil(textInputHider);
319+
308320
FlutterViewController* viewControllerMock = OCMPartialMock(viewController);
309321
UIScreen* screen = [self setUpMockScreen];
310322
CGRect viewFrame = screen.bounds;
@@ -2188,4 +2200,46 @@ - (void)testFlutterViewControllerStartKeyboardAnimationWillCreateVsyncClientCorr
21882200
XCTAssertNil(viewController.keyboardAnimationVSyncClient);
21892201
}
21902202

2203+
- (void)testAvoidKeyboardAnimationWhenFlutterTextInputViewAccessibilityHiderIsNil {
2204+
FlutterEngine* engine = [[FlutterEngine alloc] init];
2205+
[engine runWithEntrypoint:nil];
2206+
FlutterViewController* viewController = [[FlutterViewController alloc] initWithEngine:engine
2207+
nibName:nil
2208+
bundle:nil];
2209+
2210+
FlutterViewController* viewControllerMock = OCMPartialMock(viewController);
2211+
UIScreen* screen = [self setUpMockScreen];
2212+
CGRect viewFrame = screen.bounds;
2213+
[self setUpMockView:viewControllerMock
2214+
screen:screen
2215+
viewFrame:viewFrame
2216+
convertedFrame:viewFrame];
2217+
2218+
CGFloat screenHeight = screen.bounds.size.height;
2219+
CGFloat screenWidth = screen.bounds.size.height;
2220+
2221+
// Check if FlutterTextInputViewAccessibilityHider is nil.
2222+
FlutterTextInputPlugin* textInputPlugin = engine.textInputPlugin;
2223+
UIView* textInputHider = [[textInputPlugin textInputView] superview];
2224+
XCTAssertNil(textInputHider);
2225+
2226+
// Start show keyboard animation.
2227+
CGRect showKeyboardBeginFrame = CGRectMake(0, screenHeight, screenWidth, 250);
2228+
CGRect showKeyboardEndFrame = CGRectMake(0, screenHeight - 250, screenWidth, 250);
2229+
NSNotification* fakeNotification =
2230+
[NSNotification notificationWithName:UIKeyboardWillChangeFrameNotification
2231+
object:nil
2232+
userInfo:@{
2233+
@"UIKeyboardFrameBeginUserInfoKey" : @(showKeyboardBeginFrame),
2234+
@"UIKeyboardFrameEndUserInfoKey" : @(showKeyboardEndFrame),
2235+
@"UIKeyboardAnimationDurationUserInfoKey" : @(0.25),
2236+
@"UIKeyboardIsLocalUserInfoKey" : @(YES)
2237+
}];
2238+
2239+
viewControllerMock.targetViewInsetBottom = 0;
2240+
[viewControllerMock handleKeyboardNotification:fakeNotification];
2241+
BOOL isShowingAnimation = viewControllerMock.keyboardAnimationIsShowing;
2242+
XCTAssertFalse(isShowingAnimation);
2243+
}
2244+
21912245
@end

0 commit comments

Comments
 (0)