Skip to content

Commit 5e37c96

Browse files
authored
[iOS][Engine] Fix view removal process for AutofillContextAction.cancel (#160653)
Original PR flutter/engine#57209 --- The `removeFromSuperview` in the `hideTextInput` method was triggering the save password, so I changed it to `cleanUpViewHierarchy`. fix flutter/flutter#145681 sample app code https://github.com/koji-1009/autofill_cancel_issue before https://github.com/user-attachments/assets/c380538b-6783-4706-9a09-4db1c3b761df after https://github.com/user-attachments/assets/b6654b80-f383-408d-9820-6fe53279ce14 ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [x] I signed the [CLA]. - [x] I listed at least one issue that this PR fixes in the description above. - [x] I updated/added relevant documentation (doc comments with `///`). - [x] I added new tests to check the change I am making, or this PR is [test-exempt]. - [x] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [x] All existing and new tests are passing. If you need help, consider asking for advice on the #hackers-new channel on [Discord]. <!-- Links --> [Contributor Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview [Tree Hygiene]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md [test-exempt]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests [Flutter Style Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md [Features we expect every widget to implement]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [breaking change policy]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md [Data Driven Fixes]: https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
1 parent dee15f5 commit 5e37c96

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterTextInputPlugin.mm

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2685,8 +2685,11 @@ - (void)hideTextInput {
26852685
[self removeEnableFlutterTextInputViewAccessibilityTimer];
26862686
_activeView.accessibilityEnabled = NO;
26872687
[_activeView resignFirstResponder];
2688-
[_activeView removeFromSuperview];
2689-
[_inputHider removeFromSuperview];
2688+
// Removes the focus from the `_activeView` (UIView<UITextInput>)
2689+
// when the user stops typing (keyboard is hidden).
2690+
// For more details, refer to the discussion at:
2691+
// https://github.com/flutter/engine/pull/57209#discussion_r1905942577
2692+
[self cleanUpViewHierarchy:YES clearText:YES delayRemoval:NO];
26902693
}
26912694

26922695
- (void)triggerAutofillSave:(BOOL)saveEntries {

engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterTextInputPluginTest.mm

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2718,6 +2718,27 @@ - (void)testInitialActiveViewCantAccessTextInputDelegate {
27182718
XCTAssertNil(textInputPlugin.activeView.textInputDelegate);
27192719
}
27202720

2721+
- (void)testAutoFillDoesNotTriggerOnHideButTriggersOnCommit {
2722+
// Regression test for https://github.com/flutter/flutter/issues/145681.
2723+
NSMutableDictionary* configuration = self.mutableTemplateCopy;
2724+
[configuration setValue:@{
2725+
@"uniqueIdentifier" : @"field1",
2726+
@"hints" : @[ UITextContentTypePassword ],
2727+
@"editingValue" : @{@"text" : @""}
2728+
}
2729+
forKey:@"autofill"];
2730+
[configuration setValue:@[ [configuration copy] ] forKey:@"fields"];
2731+
2732+
[self setClientId:123 configuration:configuration];
2733+
XCTAssertEqual(self.viewsVisibleToAutofill.count, 1ul);
2734+
2735+
[self setTextInputHide];
2736+
// Before the fix in https://github.com/flutter/flutter/pull/160653, it was 0ul.
2737+
XCTAssertEqual(self.viewsVisibleToAutofill.count, 1ul);
2738+
2739+
[self commitAutofillContextAndVerify];
2740+
}
2741+
27212742
#pragma mark - Accessibility - Tests
27222743

27232744
- (void)testUITextInputAccessibilityNotHiddenWhenShowed {

0 commit comments

Comments
 (0)