8000 Add a [valid] property of [MouseTrackerAnnotation] indicates the annotation states. by xu-baolin · Pull Request #69866 · flutter/flutter · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Add a [valid] property of [MouseTrackerAnnotation] indicates the annotation states. #69866

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

Merged
merged 7 commits into from
Nov 17, 2020

Conversation

xu-baolin
Copy link
Member
@xu-baolin xu-baolin commented Nov 5, 2020

Description

When the mouse long-press and drag the Draggable child will trigger replace the child with childWhenDragging. If the old child has listened the mouse event will trigger using disposed object when continue to move the mouse.

Solution

Add a valid property of MouseTrackerAnnotationto prevent the callbacks from being called when valid is false.

Set the valid false when the RenderMouseRegion detached and set it true when the RO attached.

@dnfield @dkwingsmt Hi, please review, thanks very much.

Related Issues

Fixes #69774
Fixes #67044
Fixes #70295

Tests

I added the following tests:

See files.

@flutter-dashboard flutter-dashboard bot added the framework flutter/packages/flutter repository. See also f: labels. label Nov 5, 2020
@google-cla google-cla bot added the cla: yes label Nov 5, 2020
@dnfield dnfield requested a review from dkwingsmt November 5, 2020 18:42
if (target is MouseTrackerAnnotation) {
if (target is RenderObject) {
// We should ignore the detached renderObject, otherwise, may trigger using the disposed object.
if (!target.attached)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

!attached is not quite the same as disposed.

@goderbauer WDYT of this?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, what you pointed out is correct, the range of detached is greater than and includes disposed, so here we need to consider whether it is reasonable to ignore the detached renderObject mouse event handling

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this behavior is reasonable. If an RO has detached from the tree, it should not respond to any mouse events. The particularity of this problem is that the RO was detached after the hittest, so it is reasonable and controllable to ignore the handling of this event here. Additionally, if the RO is retaken later for some reasons, this change will not affect it, because it is a real-time conditional control and does not remove the callback.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes sense to me - we may want to update the comment to explain this rather than refering to disposal, which isn't really a thing for RenderObjects.

I'd also defer to @goderbauer or @dkwingsmt on this - I think they're more familiar with this area.

if (target is MouseTrackerAnnotation) {
if (target is RenderObject) {
// It's possible that the renderObject was detached after hitTest, so we should ignore it.
// https://github.com/flutter/flutter/issues/67044
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of linking to an issue here we should just include the relevant information right here in the comment.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK

annotations[entry.target as MouseTrackerAnnotation] = entry.transform!;
final HitTestTarget target = entry.target;
if (target is MouseTrackerAnnotation) {
if (target is RenderObject) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is odd that we have to special case RenderObjects here. What about other MouseTrackerAnnotations that have become "invalid"?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have a situation where the MouseTrackerAnnotations is not renderObject?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're about to. #68674 is introducing a subclass of TextSpan to be a MouseTrackerAnnotations. Although there is no way for that to be turned off. I'm thinking if we should have a generalized way of turning it off.

Copy link
Member Author
@xu-baolin xu-baolin Nov 6, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we introduce a new property of MouseTrackerAnnotation to indicate whether it is valid, does the Span have chance to set it?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dkwingsmt Hi, Sorry to bother you again :)
WDYT of a generalized way of turning it off without breaking any API?

@xu-baolin xu-baolin changed the title Ignore the detached MouseTrackerAnnotation events when handle mouse event Add a [valid] property of [MouseTrackerAnnotation] indicates the annotation states. Nov 9, 2020
@xu-baolin
Copy link
Member Author

If we introduce a new property of MouseTrackerAnnotation, it will be a breaking change, someone who used MouseTrackerAnnotation must modify their code .
It seems that this solution is not very good, looking forward to your thoughts.

Copy link
Contributor
@dkwingsmt dkwingsmt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried to think of other solutions but they're no better despite being more complicated. Requested changes are mostly renaming the property to leave namespace for general purposes and reverting the removal of const which is not necessary.

@@ -112,6 +116,7 @@ class MouseTrackerAnnotation with Diagnosticable {
ifEmpty: '<none>',
));
properties.add(DiagnosticsProperty<MouseCursor>('cursor', cursor, defaultValue: MouseCursor.defer));
properties.add(DiagnosticsProperty<bool>('valid', valid, defaultValue: true));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make it a FlagProperty and ifFalse: 'invalid for MouseTracker'

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually let's not add it here, since MouseTrackerAnnotation always return valid: true. Classes with a mutable valid will always have to implement MouseTrackerAnnotation and have to reimplement this method. Add this line to RenderMouseRegion instead.

@@ -732,6 +732,9 @@ mixin _PlatformViewGestureMixin on RenderBox implements MouseTrackerAnnotation {
@override
MouseCursor get cursor => MouseCursor.uncontrolled;

@override
bool valid = true;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

final

@xu-baolin xu-baolin requested a review from dkwingsmt November 13, 2020 03:32
Copy link
Contributor
@dkwingsmt dkwingsmt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks for the change

@xu-baolin
Copy link
Member Author

@dkwingsmt Hi,
Thank you for reviewing, I'm sorry I don't have permission to merge, can you merge this for me, thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
framework flutter/packages/flutter repository. See also f: labels.
Projects
None yet
5 participants
0