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

Commit c1f977f

Browse files
authored
[CP][ios][autocorrection]disable autocorrection for ios 17 (#44354)
Original PR: #44176 *List which issues are fixed by this PR. You must list at least one issue.* flutter/flutter#131890 *If you had to change anything in the [flutter/tests] repo, include a link to the migration guide as per the [breaking change policy].* [C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
1 parent b8332e3 commit c1f977f

File tree

2 files changed

+33
-10
lines changed

2 files changed

+33
-10
lines changed

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

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1631,10 +1631,21 @@ - (CGRect)firstRectForRange:(UITextRange*)range {
16311631

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

16401651
NSUInteger first = start;

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

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -299,15 +299,22 @@ - (void)testSettingKeyboardTypeNoneDisablesSystemKeyboard {
299299
XCTAssertNil(textInputPlugin.activeView.inputViewController);
300300
}
301301

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

306-
// Verify behavior.
307-
OCMVerify([engine flutterTextInputView:inputView
308-
showAutocorrectionPromptRectForStart:0
309-
end:1
310-
withClient:0]);
306+
if (@available(iOS 17.0, *)) {
307+
// Auto-correction prompt is disabled in iOS 17+.
308+
OCMVerify(never(), [engine flutterTextInputView:inputView
309+
showAutocorrectionPromptRectForStart:0
310+
end:1
311+
withClient:0]);
312+
} else {
313+
OCMVerify([engine flutterTextInputView:inputView
314+
showAutocorrectionPromptRectForStart:0
315+
end:1
316+
withClient:0]);
317+
}
311318
}
312319

313320
- (void)testIgnoresSelectionChangeIfSelectionIsDisabled {
@@ -339,6 +346,11 @@ - (void)testIgnoresSelectionChangeIfSelectionIsDisabled {
339346
}
340347

341348
- (void)testAutocorrectionPromptRectDoesNotAppearDuringScribble {
349+
// Auto-correction prompt is disabled in iOS 17+.
350+
if (@available(iOS 17.0, *)) {
351+
return;
352+
}
353+
342354
if (@available(iOS 14.0, *)) {
343355
FlutterTextInputView* inputView = [[FlutterTextInputView alloc] initWithOwner:textInputPlugin];
344356

0 commit comments

Comments
 (0)