-
Notifications
You must be signed in to change notification settings - Fork 6k
Don't respond to the insertionPointColor selector on iOS 17+
#46373
Don't respond to the insertionPointColor selector on iOS 17+
#46373
Conversation
35ce1ca to
8ec60f5
Compare
8ec60f5 to
05f8e8a
Compare
ed47e43 to
900069b
Compare
| // the screen. | ||
| // | ||
| // These are not documened methods. On iOS 17, the insertion point color is also | ||
| // used to paint the highlighted background of the selected IME candidate: |
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.
what else do we use this function for?
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 paragraph above says that it's used to make sure the system caret / selection handles aren't visible.
| // because Scribble interactions require the view to have it's actual frame on | ||
| // the screen. | ||
| // | ||
| // These are not documened methods. On iOS 17, the insertion point color is also |
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.
Nit: documented
| // used to paint 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+. |
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.
I'm confused as to why we are both implementing it but claiming not to. Are we relying on an implementation detail of some system code calling this unconditionally and other code checking whether its implemented first, and relying on that distinction to make things work? If so, that seems incredibly fragile, and the sort of thing that's likely to cause another round of fire drills in a subsequent iOS version.
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.
UIKit falls back to UIColor.insertionPointColor if the receiver doesn't respond to insertionPointColor. That color is unfortunately private.
some system code calling this unconditionally
The method is actually private (but it's in the codebase for a while and no complains from app store) and it's not part of any protocols, so UIKit has to check respondsToSelector first.
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 method is actually private (but it's in the codebase for a while and no complains from app store) and it's not part of any protocols, so UIKit has to check
respondsToSelectorfirst.
Then how does this change not break the "Prevent UIKit from showing selection handles or highlights" use case that the implementation is documented as being for?
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.
On iOS 17 there's new API for adding system UI for text selection/cursor/highlights: https://developer.apple.com/documentation/uikit/uitextselectiondisplayinteraction?language=objc . Without adding that interaction to the input view (and we don't add UIITextInteraction to the view unless the framework is currently sending editing state updates, as a hack to fix a different bug), UIKit doesn't seem to add selection handles or highlights automatically on iOS 17.
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.
I see; please update the comments on this method then to explain this, and that it's bypassed on iOS 17+ by a respondsToSelector: check.
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.
Hi @fbcouch do you remember when is insertionPointColor called during scribble? I'd like to verify if this is still needed on iOS17.
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.
If I recall correctly, it was basically during any text interaction – since we changed to show the frame in it's proper place on the screen, iPadOS was able to draw it's own selection handles, etc
| return NO; | ||
| } | ||
| } | ||
| return [FlutterTextInputView instancesRespondToSelector:selector]; |
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.
Why isn't this just calling super?
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.
According to the documentation [super respondsToSelector:] is equivalent to [self respondsToSelector:] https://developer.apple.com/documentation/objectivec/1418956-nsobject/1418583-respondstoselector#discussion, so i thought there was going to be an infinite loop. Let me try it out.
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.
Well that worked. Changed to calling super.
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 context there is important:
You cannot test whether an object inherits a method from its superclass by sending respondsToSelector: to the object using the super keyword. This method will still be testing the object as a whole, not just the superclass’s implementation. Therefore, sending respondsToSelector: to super is equivalent to sending it to self.
For the purposes of testing where a method's implementation lives, it's equivalent. That doesn't mean it doesn't follow actual method dispatch rules.
900069b to
2f0c506
Compare
| if (@available(iOS 17.0, *)) { | ||
| // See the comment on this method. | ||
| if (selector == @selector(insertionPointColor)) { | ||
| return NO; |
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.
We need to be careful if this breaks other functionalities that uses insertionPointColor.
|
I did some basic IME input testing and didn't notice any UI weirdness. |
stuartmorgan-g
left a comment
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.
LGTM as long as we're reasonably confident that we've manually tested all of the cases that the code being bypassed was originally intended to fix.
…136752) flutter/engine@659e68a...289f29b 2023-10-17 [email protected] Don't respond to the `insertionPointColor` selector on iOS 17+ (flutter/engine#46373) If this roll has caused a breakage, revert this CL and stop the roller using the controls here: https://autoroll.skia.org/r/flutter-engine-flutter-autoroll Please CC [email protected],[email protected],[email protected] on the revert to ensure that a human is aware of the problem. To file a bug in Flutter: https://github.com/flutter/flutter/issues/new/choose To report a problem with the AutoRoller itself, please file a bug: https://issues.skia.org/issues/new?component=1389291&template=1850622 Documentation for the AutoRoller is here: https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
Fixes flutter/flutter#132548
Pre-launch Checklist
///).If you need help, consider asking for advice on the #hackers-new channel on Discord.