From 2b08036a2ab7ad233c2af5a326a4f9f97e597137 Mon Sep 17 00:00:00 2001 From: Koji Wakamiya Date: Sat, 14 Dec 2024 18:53:25 +0900 Subject: [PATCH 1/4] fix: Fix view removal process for AutofillContextAction.cancel --- .../darwin/ios/framework/Source/FlutterTextInputPlugin.mm | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/shell/platform/darwin/ios/framework/Source/FlutterTextInputPlugin.mm b/shell/platform/darwin/ios/framework/Source/FlutterTextInputPlugin.mm index 9358431cf5a6f..b421c7043fbcf 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterTextInputPlugin.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterTextInputPlugin.mm @@ -2675,8 +2675,7 @@ - (void)hideTextInput { [self removeEnableFlutterTextInputViewAccessibilityTimer]; _activeView.accessibilityEnabled = NO; [_activeView resignFirstResponder]; - [_activeView removeFromSuperview]; - [_inputHider removeFromSuperview]; + [self cleanUpViewHierarchy:YES clearText:NO delayRemoval:NO]; } - (void)triggerAutofillSave:(BOOL)saveEntries { From a8ef38861f1a73c8508713d302add94f756b0dc4 Mon Sep 17 00:00:00 2001 From: Koji Wakamiya Date: Sun, 5 Jan 2025 19:32:59 +0900 Subject: [PATCH 2/4] =?UTF-8?q?test:=20Confirm=20hide=20doesn=E2=80=99t=20?= =?UTF-8?q?but=20commit=20does=20trigger=20autofill?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Source/FlutterTextInputPluginTest.mm | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/shell/platform/darwin/ios/framework/Source/FlutterTextInputPluginTest.mm b/shell/platform/darwin/ios/framework/Source/FlutterTextInputPluginTest.mm index be00f6e1e63d4..46a2104164a2c 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterTextInputPluginTest.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterTextInputPluginTest.mm @@ -2691,6 +2691,27 @@ - (void)testInitialActiveViewCantAccessTextInputDelegate { 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/engine/pull/57209, it was 0ul. + XCTAssertEqual(self.viewsVisibleToAutofill.count, 1ul); + + [self commitAutofillContextAndVerify]; +} + #pragma mark - Accessibility - Tests - (void)testUITextInputAccessibilityNotHiddenWhenShowed { From 436ae8e4b23fb9a8d7848542050088f6170700ca Mon Sep 17 00:00:00 2001 From: Koji Wakamiya Date: Sun, 5 Jan 2025 22:25:06 +0900 Subject: [PATCH 3/4] fix: Set clearText:YES --- .../darwin/ios/framework/Source/FlutterTextInputPlugin.mm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shell/platform/darwin/ios/framework/Source/FlutterTextInputPlugin.mm b/shell/platform/darwin/ios/framework/Source/FlutterTextInputPlugin.mm index b421c7043fbcf..764a888b899f1 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterTextInputPlugin.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterTextInputPlugin.mm @@ -2675,7 +2675,7 @@ - (void)hideTextInput { [self removeEnableFlutterTextInputViewAccessibilityTimer]; _activeView.accessibilityEnabled = NO; [_activeView resignFirstResponder]; - [self cleanUpViewHierarchy:YES clearText:NO delayRemoval:NO]; + [self cleanUpViewHierarchy:YES clearText:YES delayRemoval:NO]; } - (void)triggerAutofillSave:(BOOL)saveEntries { From 8f1fe672e9776b006f063b34d079bb7c174307b8 Mon Sep 17 00:00:00 2001 From: Koji Wakamiya Date: Fri, 10 Jan 2025 22:31:10 +0900 Subject: [PATCH 4/4] refactor: Add comment --- .../darwin/ios/framework/Source/FlutterTextInputPlugin.mm | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/shell/platform/darwin/ios/framework/Source/FlutterTextInputPlugin.mm b/shell/platform/darwin/ios/framework/Source/FlutterTextInputPlugin.mm index 764a888b899f1..4531df7e182c8 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterTextInputPlugin.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterTextInputPlugin.mm @@ -2675,6 +2675,10 @@ - (void)hideTextInput { [self removeEnableFlutterTextInputViewAccessibilityTimer]; _activeView.accessibilityEnabled = NO; [_activeView resignFirstResponder]; + // 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]; }