diff --git a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterTextInputPlugin.mm b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterTextInputPlugin.mm index a287a54f8b..08ea6910bb 100644 --- a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterTextInputPlugin.mm +++ b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterTextInputPlugin.mm @@ -2685,8 +2685,11 @@ static BOOL IsSelectionRectBoundaryCloserToPoint(CGPoint point, [self removeEnableFlutterTextInputViewAccessibilityTimer]; _activeView.accessibilityEnabled = NO; [_activeView resignFirstResponder]; - [_activeView removeFromSuperview]; - [_inputHider removeFromSuperview]; + // Removes the focus from the `_activeView` (UIView) + // when the user stops typing (keyboard is hidden). + // For more details, refer to the discussion at: + // https://github.com/flutter/engine/pull/57209#discussion_r1905942577 + [self cleanUpViewHierarchy:YES clearText:YES delayRemoval:NO]; } - (void)triggerAutofillSave:(BOOL)saveEntries { diff --git a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterTextInputPluginTest.mm b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterTextInputPluginTest.mm index f12b2aa296..c51db3219c 100644 --- a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterTextInputPluginTest.mm +++ b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterTextInputPluginTest.mm @@ -2718,6 +2718,27 @@ FLUTTER_ASSERT_ARC XCTAssertNil(textInputPlugin.activeView.textInputDelegate); } +- (void)testAutoFillDoesNotTriggerOnHideButTriggersOnCommit { + // Regression test for https://github.com/flutter/flutter/issues/145681. + NSMutableDictionary* configuration = self.mutableTemplateCopy; + [configuration setValue:@{ + @"uniqueIdentifier" : @"field1", + @"hints" : @[ UITextContentTypePassword ], + @"editingValue" : @{@"text" : @""} + } + forKey:@"autofill"]; + [configuration setValue:@[ [configuration copy] ] forKey:@"fields"]; + + [self setClientId:123 configuration:configuration]; + XCTAssertEqual(self.viewsVisibleToAutofill.count, 1ul); + + [self setTextInputHide]; + // Before the fix in https://github.com/flutter/flutter/pull/160653, it was 0ul. + XCTAssertEqual(self.viewsVisibleToAutofill.count, 1ul); + + [self commitAutofillContextAndVerify]; +} + #pragma mark - Accessibility - Tests - (void)testUITextInputAccessibilityNotHiddenWhenShowed {