-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Fix hit-testing order in semantics #167522
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
2dd4595 to
252e1dd
Compare
| for (int i = childCount - 1; i >= 0; i -= 1) { | ||
| childrenInHitTestOrder[i] = _children![childCount - i - 1].id; | ||
| for (int i = 0; i < childCount; i += 1) { | ||
| childrenInHitTestOrder[i] = _children![i].id; |
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.
This is surprising, does this mean we always get it wrong?
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.
after reading the code more I think the original documentation may be wrong
_children is assigned with the childrenInInversePaintOrder in SemanticsNode.updateWith.
which is called in _buildSemanticsSubtree where the children is the same as _childrenAndElevationAdjustments order and I think by default the _childrenAndElevationAdjustments order is insertion order which will be RenderObject.visitChildForSemantics, which is the paint order.
so the the original code should be correct but just bad name.
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.
Just an update. Talked with @chunhtai offline. It seems the hit test order was incorrect all the time. But previously when we haven't applied OverlayPortal to any widgets, if we push a new route, the items underneath the new route will be thrown away so the hit test only need to handle one "layer" of items and everything is okay. After OverlayPortal is applied to Autocomplete, the items underneath the popup still stay in the tree, and the hit test order starts show problems.
252e1dd to
4eb6771
Compare
4eb6771 to
da4515c
Compare
chunhtai
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
|
Thanks for the semantics fix, the attention to a11y is appreciated. |
…#168235) This reverts commit d9cbff2. Fixes flutter#168164
…#168235) This reverts commit d9cbff2. Fixes flutter#168164
Fixes flutter#163576 In `updateWith()` method, `_replaceChildren()` is called to generate `_children` list. `_children` list is used to generate the hit test order (`childrenInHitTestOrder`). In `_replaceChildren()`, `childrenIn**Inverse**PaintOrder` is directly assigned to _children, so _children itself follows hit test order. So when we generate the `childrenInHitTestOrder`, we don't need to reverse the children again. https://github.com/user-attachments/assets/df9d852f-231e-4480-8d8b-10c1d406f120 ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [x] I signed the [CLA]. - [x] I listed at least one issue that this PR fixes in the description above. - [x] I updated/added relevant documentation (doc comments with `///`). - [x] I added new tests to check the change I am making, or this PR is [test-exempt]. - [x] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [x] All existing and new tests are passing.
Fixes #163576
In
updateWith()method,_replaceChildren()is called to generate_childrenlist._childrenlist is used to generate the hit test order (childrenInHitTestOrder).In
_replaceChildren(),childrenIn**Inverse**PaintOrderis directly assigned to _children, so _children itself follows hit test order. So when we generate thechildrenInHitTestOrder, we don't need to reverse the children again.Screen.Recording.2025-04-21.at.6.41.37.PM.mov
Pre-launch Checklist
///).