Fix hit-testing order in semantics#167522
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.
This is surprising, does this mean we always get it wrong?
There was a problem hiding this comment.
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.
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
|
Thanks for the semantics fix, the attention to a11y is appreciated. |
This reverts commit d9cbff2.
…#168235) This reverts commit d9cbff2. Fixes flutter#168164
…#168235) This reverts commit d9cbff2. Fixes flutter#168164
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
///).