From d4211a976b85332e85611454e9299dd55b26f5f2 Mon Sep 17 00:00:00 2001 From: LongCatIsLooong <31859944+LongCatIsLooong@users.noreply.github.com> Date: Tue, 17 Oct 2023 12:03:48 -0700 Subject: [PATCH] Don't respond to the `insertionPointColor` selector on iOS 17+ (flutter/engine#46373) Fixes https://github.com/flutter/flutter/issues/132548 [C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style --- .../Source/FlutterTextInputPlugin.mm | 19 ++++++++++++++++++- .../Source/FlutterTextInputPluginTest.mm | 11 +++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterTextInputPlugin.mm b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterTextInputPlugin.mm index f02ab85da7..e2fe1334ff 100644 --- a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterTextInputPlugin.mm +++ b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterTextInputPlugin.mm @@ -902,7 +902,14 @@ static BOOL IsSelectionRectBoundaryCloserToPoint(CGPoint point, // Prevent UIKit from showing selection handles or highlights. This is needed // because Scribble interactions require the view to have it's actual frame on -// the screen. +// the screen. They're not needed on iOS 17 with the new +// UITextSelectionDisplayInteraction API. +// +// These are undocumented methods. On iOS 17, the insertion point color is also +// used as the highlighted background of the selected IME candidate: +// https://github.com/flutter/flutter/issues/132548 +// So the respondsToSelector method is overridden to return NO for this method +// on iOS 17+. - (UIColor*)insertionPointColor { return [UIColor clearColor]; } @@ -930,6 +937,16 @@ static BOOL IsSelectionRectBoundaryCloserToPoint(CGPoint point, return _textInputPlugin.textInputDelegate; } +- (BOOL)respondsToSelector:(SEL)selector { + if (@available(iOS 17.0, *)) { + // See the comment on this method. + if (selector == @selector(insertionPointColor)) { + return NO; + } + } + return [super respondsToSelector:selector]; +} + - (void)setTextInputClient:(int)client { _textInputClient = client; _hasPlaceholder = NO; diff --git a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterTextInputPluginTest.mm b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterTextInputPluginTest.mm index f18357acf0..b4d6dcb7e0 100644 --- a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterTextInputPluginTest.mm +++ b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterTextInputPluginTest.mm @@ -786,6 +786,17 @@ FLUTTER_ASSERT_ARC XCTAssertEqual(inputView.spellCheckingType, UITextSpellCheckingTypeNo); } +- (void)testFlutterTextInputViewOnlyRespondsToInsertionPointColorBelowIOS17 { + FlutterTextInputView* inputView = [[FlutterTextInputView alloc] initWithOwner:textInputPlugin]; + BOOL respondsToInsertionPointColor = + [inputView respondsToSelector:@selector(insertionPointColor)]; + if (@available(iOS 17, *)) { + XCTAssertFalse(respondsToInsertionPointColor); + } else { + XCTAssertTrue(respondsToInsertionPointColor); + } +} + #pragma mark - TextEditingDelta tests - (void)testTextEditingDeltasAreGeneratedOnTextInput { FlutterTextInputView* inputView = [[FlutterTextInputView alloc] initWithOwner:textInputPlugin];