-
Notifications
You must be signed in to change notification settings - Fork 6k
[ios][ios17]fix auto correction highlight on top left corner #44779
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2449,18 +2449,32 @@ - (void)takeKeyboardScreenshotAndDisplay { | |
} | ||
|
||
- (void)setEditableSizeAndTransform:(NSDictionary*)dictionary { | ||
[_activeView setEditableTransform:dictionary[@"transform"]]; | ||
NSArray* transform = dictionary[@"transform"]; | ||
[_activeView setEditableTransform:transform]; | ||
const int leftIndex = 12; | ||
const int topIndex = 13; | ||
if ([_activeView isScribbleAvailable]) { | ||
// This is necessary to set up where the scribble interactable element will be. | ||
int leftIndex = 12; | ||
int topIndex = 13; | ||
_inputHider.frame = | ||
CGRectMake([dictionary[@"transform"][leftIndex] intValue], | ||
[dictionary[@"transform"][topIndex] intValue], [dictionary[@"width"] intValue], | ||
[dictionary[@"height"] intValue]); | ||
CGRectMake([transform[leftIndex] intValue], [transform[topIndex] intValue], | ||
[dictionary[@"width"] intValue], [dictionary[@"height"] intValue]); | ||
_activeView.frame = | ||
CGRectMake(0, 0, [dictionary[@"width"] intValue], [dictionary[@"height"] intValue]); | ||
_activeView.tintColor = [UIColor clearColor]; | ||
} else { | ||
// TODO(hellohuanlin): Also need to handle iOS 16 case, where the auto-correction highlight does | ||
// not match the size of text. | ||
// See https://github.com/flutter/flutter/issues/131695 | ||
if (@available(iOS 17, *)) { | ||
// Move auto-correction highlight to overlap with the actual text. | ||
// This is to fix an issue where the system auto-correction highlight is displayed at | ||
// the top left corner of the screen on iOS 17+. | ||
// This problem also happens on iOS 16, but the size of highlight does not match the text. | ||
// See https://github.com/flutter/flutter/issues/131695 | ||
// TODO(hellohuanlin): Investigate if we can use non-zero size. | ||
_inputHider.frame = | ||
CGRectMake([transform[leftIndex] intValue], [transform[topIndex] intValue], 0, 0); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What happens if you pass the real width and height here like in the scribble case above instead of 0,0? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've tried that and got the same result in my tests. Nothing seems to break. But wanted to be safe and keep the same zero size as before. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (This is one of the things I was thinking would be part of unifying the these two codepaths in a follow-up, master-only PR.) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. added a todo there. |
||
} | ||
} | ||
} | ||
|
||
|
@@ -2488,7 +2502,22 @@ - (void)setSelectionRects:(NSArray*)encodedRects { | |
? NSWritingDirectionLeftToRight | ||
: NSWritingDirectionRightToLeft]]; | ||
} | ||
|
||
BOOL shouldNotifyTextChange = NO; | ||
if (@available(iOS 17, *)) { | ||
// Force UIKit to query the selectionRects again on iOS 17+ | ||
// This is to fix a bug on iOS 17+ where UIKit queries the outdated selectionRects after | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similar to above, I think this bug exists on all versions of iOS, right? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not in this case - in iOS 16, we do not use system highlight, so no such bug. I also tried to notify the change on iOS 16 and nothing seems to break, but just to be safe here. |
||
// entering a character, resulting in auto-correction highlight region missing the last | ||
// character. | ||
shouldNotifyTextChange = YES; | ||
} | ||
if (shouldNotifyTextChange) { | ||
[_activeView.inputDelegate textWillChange:_activeView]; | ||
} | ||
_activeView.selectionRects = rectsAsRect; | ||
if (shouldNotifyTextChange) { | ||
[_activeView.inputDelegate textDidChange:_activeView]; | ||
} | ||
} | ||
|
||
- (void)startLiveTextInput { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a TODO to simplify all of this logic. It looks like post cherry-pick we can probably just make the
_inputHider.frame
logic unconditional?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The iOS 16 behavior is different - the highlight region does not match the size of text (see screenshot in flutter/flutter#131695 for iOS 16). But will add a TODO to explain this.