-
Notifications
You must be signed in to change notification settings - Fork 29.2k
Reland: MouseRegion enter/exit event can be triggered with button pressed #83253
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
Conversation
…tton pressed (flutter#81148)" (flutter#81557)" This reverts commit d97f41c.
(PR triage) @dkwingsmt Do you still need this? |
It seems that this PR does bring behavioral changes to internal tests in an unexpected way. I would investigate further but still haven't got time for it. |
Thanks. |
@@ -282,7 +282,14 @@ mixin RendererBinding on BindingBase, ServicesBinding, SchedulerBinding, Gesture | |||
event is PointerAddedEvent || | |||
event is PointerRemovedEvent) { | |||
assert(event.position != null); | |||
_mouseTracker!.updateWithEvent(event, () => hitTestResult ?? renderView.hitTestMouseTrackers(event.position)); | |||
_mouseTracker!.updateWithEvent( |
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.
Could we only call _mouseTracker!.updateWithEven
when it is a mouse event?
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.
+1
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 idea is that RendererBinding
provides all events and a way to compute hit test result for MouseTracker
to retrieve when needed. In this way most logic is hidden in MouseTracker
. Nevertheless I agree that the hit testing function is a little cumbersome. I'll take a moment to think if there's a better way but I'm probably sticking to it in the end.
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.
It turns out that the if
clause is unnecessary at all (according to the documentation, which I trust). Several assertions can also be removed since the NNBD. This should feel much cleaner.
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.
@@ -282,7 +282,14 @@ mixin RendererBinding on BindingBase, ServicesBinding, SchedulerBinding, Gesture | |||
event is PointerAddedEvent || | |||
event is PointerRemovedEvent) { | |||
assert(event.position != null); | |||
_mouseTracker!.updateWithEvent(event, () => hitTestResult ?? renderView.hitTestMouseTrackers(event.position)); | |||
_mouseTracker!.updateWithEvent( |
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.
+1
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
void updateWithEvent(PointerEvent event, ValueGetter<HitTestResult> getResult) { | ||
assert(event != null); | ||
final HitTestResult result = event is PointerRemovedEvent ? HitTestResult() : getResult(); | ||
assert(result != null); | ||
if (event.kind != PointerDeviceKind.mouse) | ||
return; | ||
if (event is PointerSignalEvent) | ||
return; |
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.
small nit:
if (event.kind != PointerDeviceKind.mouse || event is PointerSignalEvent)
return;
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 slightly prefer the current way since they're describing 2 different things and splitting them is clearer.
@@ -278,12 +278,14 @@ mixin RendererBinding on BindingBase, ServicesBinding, SchedulerBinding, Gesture | |||
|
|||
@override // from GestureBinding | |||
void dispatchEvent(PointerEvent event, HitTestResult? hitTestResult) { | |||
if (hitTestResult != null || | |||
event is PointerAddedEvent || | |||
event is PointerRemovedEvent) { |
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 did you think that this clause is unnecessary ?
For example hitTestResult == null && event is PointerMoveEvent
, it seems that change some behaviours , right?
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 https://github.com/flutter/flutter/blob/master/packages/flutter/lib/src/gestures/binding.dart#L390,
/// The `hitTestResult` argument may only be null for [PointerAddedEvent]s or
/// [PointerRemovedEvent]s.
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.
Thanks for explanation, LGTM again!
This PR relands #81148, which fixes a bug where mouse pointers can't trigger enter/exit events when pressed, credit to @xu-baolin .
Additionally, this PR also fixes
MouseTracker
to no longer trigger hit tests for non-mouse pointers.Pre-launch Checklist
///
).If you need help, consider asking for advice on the #hackers-new channel on Discord.