-
Notifications
You must be signed in to change notification settings - Fork 6k
fix: TapTextFieldTapRegion not working on ios safari/chrome/webview #53249
Conversation
It looks like this pull request may not have tests. Please make sure to add tests before merging. If you need an exemption to this rule, contact "@test-exemption-reviewer" in the #hackers channel in Chat (don't just cc them here, they won't see it! Use Discord!). If you are not sure if you need tests, consider this rule of thumb: the purpose of a test is to make sure someone doesn't accidentally revert the fix. Ask yourself, is there anything in your PR that you feel it is important we not accidentally revert back to how it was before your fix? Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing. |
@@ -1707,7 +1707,7 @@ class IOSTextEditingStrategy extends GloballyPositionedTextEditingStrategy { | |||
subscriptions.add(DomSubscription(activeDomElement, 'blur', | |||
(_) { | |||
final bool isFastCallback = blurWatch.elapsed < _blurFastCallbackInterval; | |||
if (windowHasFocus && isFastCallback) { | |||
if (windowHasFocus || isFastCallback) { |
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.
Given the original introduction of isFastCallback
here #31718 , it is a bit strange that this code does not cause any test to fail.
From the explanation given here #31718 (comment) it sounds like we want to close the input connection when the "done" button is pressed on a keyboard. The logic without isFastCallback
was only checking if the window had focus before refocusing the textfield. In the case of the "done" button this would cause the keyboard to stay open because the window has focus so the textfield is refocused. With windowHasFocus && isFastCallback
, pressing the "done" button will close the input connection because it was not a fast callback. With windowHasFocus || isFastCallback
it sounds like the "done" button would once again fall under the same issue where the keyboard can't hide because the window has focus. What do you think about this?
cc @mdebbar if you had any context on this issue.
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 didn't know this before. So we should find a way to detect the difference between clicking the done
or TapTextFieldTapRegion
.
… has touched just before the blur event
Added test for this. However, it seems to the test platform don't work on |
Hi @Renzo-Olivares @Satsrag |
@Satsrag Apologies for the long silence on this PR. Are you still interested in moving forward with this PR? If so, this PR will need to be re-opened in https://github.com/flutter/flutter. If I understand correctly the proposed solution is to add a new timer that detects touches on the active window. If there was a touch before the blur callback was triggered then we refocus the input field and let the framework manage the focus. If there is no touch before the blur callback was triggered then we close the input connection. This is my understanding of the issue:
Pressing "done" on the iOS keyboard triggers a blur event, but it is indistinguishable from other blur events. So before the fast callback fix was implemented it would always fall under the case of refocusing the input field which would prevent the keyboard from hiding. The fix was to implement a check for a "fast callback", which differentiates the blur event sent by Safari right after input, and the blur event sent when "done" is pressed, the former being the "fast callback" case. I think the issue with the "fast callback" fix is that now when the user taps on another focusable element, it is considered not a "fast callback" and as a result causes the input connection to close.
Now with your proposal we are adding another level of differentiation by detecting taps on the window right before the blur event. I think this is reasonable though I wonder if we should also check for mouse clicks and other pointer devices that aren't covered in |
Monorepo Migration Completed
The
This is a canned message |
@Renzo-Olivares You are right. Other events that aren't covered in |
For this issue and this
engine/lib/web_ui/lib/src/engine/text_editing/text_editing.dart
Line 1710 in 47b15df
There should be use
||
instead of&&
. The fourth comment above, ifisFastCallback
will remain the focus, so we callactiveDomElement.focus()
.If it is not fast callback >= 200ms and
windowHasFocus
is true, we also callactiveDomElement.focus()
to remain focused to wait for the framework to manage the focus change. In this case, if the user taps theTapTextFieldTapRegion
, the active element should not lose focus. If we use&&
, in this case, theengine
sendsTextConnectionClose
to theframework
to lose focus. So, theframework
has no chance to manage the focus.