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

[ios][autocorrection]disable auto-correction highlight in iOS 17 #44176

Merged
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 @@ -1632,10 +1632,21 @@ - (CGRect)firstRectForRange:(UITextRange*)range {

if (_scribbleInteractionStatus == FlutterScribbleInteractionStatusNone &&
_scribbleFocusStatus == FlutterScribbleFocusStatusUnfocused) {
[self.textInputDelegate flutterTextInputView:self
showAutocorrectionPromptRectForStart:start
end:end
withClient:_textInputClient];
if (@available(iOS 17.0, *)) {
// Disable auto-correction highlight feature for iOS 17+.
// In iOS 17+, whenever a character is inserted or deleted, the system will always query
// the rect for every single character of the current word.
// GitHub Issue: https://github.com/flutter/flutter/issues/128406
} else {
// This tells the framework to show the highlight for incorrectly spelled word that is
// about to be auto-corrected.
// There is no other UITextInput API that informs about the auto-correction highlight.
// So we simply add the call here as a workaround.
[self.textInputDelegate flutterTextInputView:self
showAutocorrectionPromptRectForStart:start
end:end
withClient:_textInputClient];
}
}

NSUInteger first = start;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -313,15 +313,22 @@ - (void)testSettingKeyboardTypeNoneDisablesSystemKeyboard {
XCTAssertNil(textInputPlugin.activeView.inputViewController);
}

- (void)testAutocorrectionPromptRectAppears {
- (void)testAutocorrectionPromptRectAppearsBeforeIOS17AndDoesNotAppearAfterIOS17 {
FlutterTextInputView* inputView = [[FlutterTextInputView alloc] initWithOwner:textInputPlugin];
[inputView firstRectForRange:[FlutterTextRange rangeWithNSRange:NSMakeRange(0, 1)]];

// Verify behavior.
OCMVerify([engine flutterTextInputView:inputView
showAutocorrectionPromptRectForStart:0
end:1
withClient:0]);
if (@available(iOS 17.0, *)) {
// Auto-correction prompt is disabled in iOS 17+.
OCMVerify(never(), [engine flutterTextInputView:inputView
showAutocorrectionPromptRectForStart:0
end:1
withClient:0]);
} else {
OCMVerify([engine flutterTextInputView:inputView
showAutocorrectionPromptRectForStart:0
end:1
withClient:0]);
}
}

- (void)testIgnoresSelectionChangeIfSelectionIsDisabled {
Expand Down Expand Up @@ -353,6 +360,11 @@ - (void)testIgnoresSelectionChangeIfSelectionIsDisabled {
}

- (void)testAutocorrectionPromptRectDoesNotAppearDuringScribble {
// Auto-correction prompt is disabled in iOS 17+.
if (@available(iOS 17.0, *)) {
return;
}

if (@available(iOS 14.0, *)) {
FlutterTextInputView* inputView = [[FlutterTextInputView alloc] initWithOwner:textInputPlugin];

Expand Down