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

Commit 289f29b

Browse files
Don't respond to the insertionPointColor selector on iOS 17+ (#46373)
Fixes flutter/flutter#132548 [C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
1 parent 659e68a commit 289f29b

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

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

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -902,7 +902,14 @@ - (UITextContentType)textContentType {
902902

903903
// Prevent UIKit from showing selection handles or highlights. This is needed
904904
// because Scribble interactions require the view to have it's actual frame on
905-
// the screen.
905+
// the screen. They're not needed on iOS 17 with the new
906+
// UITextSelectionDisplayInteraction API.
907+
//
908+
// These are undocumented methods. On iOS 17, the insertion point color is also
909+
// used as the highlighted background of the selected IME candidate:
910+
// https://github.com/flutter/flutter/issues/132548
911+
// So the respondsToSelector method is overridden to return NO for this method
912+
// on iOS 17+.
906913
- (UIColor*)insertionPointColor {
907914
return [UIColor clearColor];
908915
}
@@ -930,6 +937,16 @@ - (UIInputViewController*)inputViewController {
930937
return _textInputPlugin.textInputDelegate;
931938
}
932939

940+
- (BOOL)respondsToSelector:(SEL)selector {
941+
if (@available(iOS 17.0, *)) {
942+
// See the comment on this method.
943+
if (selector == @selector(insertionPointColor)) {
944+
return NO;
945+
}
946+
}
947+
return [super respondsToSelector:selector];
948+
}
949+
933950
- (void)setTextInputClient:(int)client {
934951
_textInputClient = client;
935952
_hasPlaceholder = NO;

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -786,6 +786,17 @@ - (void)testDisablingAutocorrectDisablesSpellChecking {
786786
XCTAssertEqual(inputView.spellCheckingType, UITextSpellCheckingTypeNo);
787787
}
788788

789+
- (void)testFlutterTextInputViewOnlyRespondsToInsertionPointColorBelowIOS17 {
790+
FlutterTextInputView* inputView = [[FlutterTextInputView alloc] initWithOwner:textInputPlugin];
791+
BOOL respondsToInsertionPointColor =
792+
[inputView respondsToSelector:@selector(insertionPointColor)];
793+
if (@available(iOS 17, *)) {
794+
XCTAssertFalse(respondsToInsertionPointColor);
795+
} else {
796+
XCTAssertTrue(respondsToInsertionPointColor);
797+
}
798+
}
799+
789800
#pragma mark - TextEditingDelta tests
790801
- (void)testTextEditingDeltasAreGeneratedOnTextInput {
791802
FlutterTextInputView* inputView = [[FlutterTextInputView alloc] initWithOwner:textInputPlugin];

0 commit comments

Comments
 (0)