Fix hit test always returning false - #14
Open
ndelanou wants to merge 1 commit into
Open
Conversation
hitTestChildren visits the onstage children, but it always returns false. The RenderOverflowView never reports a hit. An ancestor which defers the hit test to its child, like a GestureDetector, never receives the pointer event. The children are also visited in paint order, and the visit does not stop at the first hit. With a negative spacing, the children overlap and the bottom child wins instead of the top one. Visit the onstage children in reverse paint order. Return true at the first child which is hit. Fixes letsar#10 Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
RenderOverflowView.hitTestChildrennow visits the onstage children in reverse paint order. It returnstrueat the first child which is hit.Why
Fixes #10.
hitTestChildrenvisited the onstage children, but it always returnedfalse.RenderOverflowViewnever reported a hit. Descendant gesture detectors still worked, because their entries stay in the hit test result path. But an ancestor which defers the hit test to its child never received the pointer event. AGestureDetectoraround anOverflowViewusesHitTestBehavior.deferToChildby default. ItsonTapcallback never ran.The old code had a second defect. It visited the children in paint order, and it did not stop at the first hit. The
spacingparameter can be negative to make the children overlap. In that case the bottom child won the gesture arena instead of the top child.The new code follows
RenderBoxContainerDefaultsMixin.defaultHitTestChildren, restricted to the onstage children.A shorter fix is to return
trueat the end of the method. That fix makes the whole box opaque. A tap on empty space inside theOverflowViewthen reports a hit. The gap fromspacingand the area below the children are two such places. One of the new tests covers this case._hasOverflowneeds no extra clip for the hit test.RenderBox.hitTestalready checkssize.contains(position), and the clip rect isOffset.zero & size.Test plan
5 new tests in a
hit testgroup:GestureDetector, forOverflowViewand forOverflowView.flexible.GestureDetector.Two of these tests fail on
master:All 13 tests pass with the fix.
flutter analyzereports no issues. I ran the suite with Flutter 3.44.8.Notes
I set the version to
0.5.1and added a CHANGELOG entry. Change the number if you prefer another one.dart formatwith Dart 3.12 wants to reformatlib/src/widgets/overflow_view.dartandtest/overflow_view_test.dart. This is already true onmaster, so I left the formatting alone to keep the diff small.lib/src/rendering/overflow_view.dartneeds no format change.🤖 Generated with Claude Code