Skip to content

Commit

Permalink
Don't respond to the insertionPointColor selector on iOS 17+ (#46373)
Browse files Browse the repository at this point in the history
  • Loading branch information
LongCatIsLooong authored and harryterkelsen committed Oct 23, 2023
1 parent 7c71da9 commit adc3f80
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -902,7 +902,14 @@ - (UITextContentType)textContentType {

// 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];
}
Expand Down Expand Up @@ -930,6 +937,16 @@ - (UIInputViewController*)inputViewController {
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -786,6 +786,17 @@ - (void)testDisablingAutocorrectDisablesSpellChecking {
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];
Expand Down

0 comments on commit adc3f80

Please sign in to comment.