-
Notifications
You must be signed in to change notification settings - Fork 24.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[iOS] Resubmit #24714 and fixes kvo crash #24840
Conversation
Hi @zhongwuzw, thanks for working on this. Do you think it's possible to do this without KVO, or without KVO on unowned objects? KVO has a lot of pitfalls and this use-case is tricky. Could we, for example, have the |
@JoshuaGross Agree! 👍 Here we go! no KVO and override |
Can you squash your commits? |
@@ -176,6 +176,16 @@ - (CGRect)editingRectForBounds:(CGRect)bounds | |||
|
|||
#pragma mark - Overrides | |||
|
|||
#pragma clang diagnostic push | |||
#pragma clang diagnostic ignored "-Wdeprecated-implementations" |
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.
Hmm, why do we need these pragmas? This seems like a sign that this might not be the right solution.
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.
Yeah, we need it to suppress warning, warning because we mark setSelectedTextRange
as unavailable, please see :
// This protocol disallows direct access to `selectedTextRange` property because | |
// unwise usage of it can break the `delegate` behavior. So, we always have to | |
// explicitly specify should `delegate` be notified about the change or not. | |
// If the change was initiated programmatically, we must NOT notify the delegate. | |
// If the change was a result of user actions (like typing or touches), we MUST notify the delegate. | |
- (void)setSelectedTextRange:(nullable UITextRange *)selectedTextRange NS_UNAVAILABLE; | |
- (void)setSelectedTextRange:(nullable UITextRange *)selectedTextRange notifyDelegate:(BOOL)notifyDelegate; |
We disallow access setSelectedTextRange
directly, but Apple framework would call it, and this is how KVO works :).
- (void)setSelectedTextRange:(UITextRange *)selectedTextRange | ||
{ | ||
[super setSelectedTextRange:selectedTextRange]; | ||
[_textInputDelegateAdapter selectedTextRangeWasSet]; |
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.
Should we try to call delegates in the same order? In the method below this one, we call the delegate method and then we call super; here, it's reversed.
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.
🤔 Emm, may not have much difference IMO, but I can consolidate them.
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.
@JoshuaGross I reverted to this change, we need to call super first, otherwise, onSelectionChange
would be called with last args, not latest args.
Thanks again for doing this! I have some specific concerns but I'm excited to get this in once we know we're doing everything the right way :) |
40e9923
to
e7d6441
Compare
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.
@JoshuaGross has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
Hi @zhongwuzw, I'm testing this PR with the following example and seeing that selection changes are happening, but not really getting useful information about the selection changes that I can tell. Is this what you would expect? Is there a better test-case for this?
|
@JoshuaGross I amended the code based yours, please see:
|
2e5dc90
to
d7f5c61
Compare
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.
@JoshuaGross has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
This pull request was successfully merged by @zhongwuzw in c38f167. When will my fix make it into a release? | Upcoming Releases |
Summary: Resubmit facebook#24714. From the facebook#24714 (comment), seems it would crash sometimes. JoshuaGross Hi :) I added a method to let `UITextField` call the cleanup explicitly. Please check again, thanks! ## Changelog [iOS] [Fixed] - Fixes selection of single line text input Pull Request resolved: facebook#24840 Differential Revision: D15415793 Pulled By: JoshuaGross fbshipit-source-id: 2bb32aa8a1fd8fad116177aac760509649c4a423
Would be nice to update the docs that |
Summary
Resubmit #24714.
From the #24714 (comment), seems it would crash sometimes. @JoshuaGross Hi :) I added a method to let
UITextField
call the cleanup explicitly. Please check again, thanks!Changelog
[iOS] [Fixed] - Fixes selection of single line text input
Test Plan
Create a single line textInput, then do some selection,
onSelectionChange
can be called.