diff --git a/shell/platform/darwin/ios/framework/Source/FlutterTextInputPlugin.mm b/shell/platform/darwin/ios/framework/Source/FlutterTextInputPlugin.mm index 9c16ec3070242..a1ec6bdc85b04 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterTextInputPlugin.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterTextInputPlugin.mm @@ -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; diff --git a/shell/platform/darwin/ios/framework/Source/FlutterTextInputPluginTest.mm b/shell/platform/darwin/ios/framework/Source/FlutterTextInputPluginTest.mm index 6fae2c6d76a8f..f39168fdeb87a 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterTextInputPluginTest.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterTextInputPluginTest.mm @@ -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 { @@ -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];