Introduce separate HitTestResults for Box and Sliver#31894
Introduce separate HitTestResults for Box and Sliver#31894goderbauer merged 7 commits intoflutter:masterfrom
Conversation
4278889 to
2ce18be
Compare
|
sector too? |
|
approach seems good to me |
|
I added an implementation for RenderSector. |
| } | ||
| } | ||
|
|
||
| /// The result of performing a hit test on [RenderSector]s. |
There was a problem hiding this comment.
Can you elaborate in the docs on what this class adds? Specifically, looking at it in isolation, it doesn't add any properties or methods over a HitTestResult, so it makes me wonder what it's used for.
There was a problem hiding this comment.
It is correct that SectorHitTestResult currently does not provide any additional functionality over HitTestResult because RenderSector is an incomplete example implementation of an alternative to RenderBox. Once we have something like RenderSectorTransform (which, changes the origin of its child to be different from the parent) we'd add methods here to implement the origin changing for hit testing. I've added added a TODO for this to the class.
| super(target); | ||
|
|
||
| @override | ||
| RenderSector get target => super.target; |
There was a problem hiding this comment.
Worth redefining HitTestEntry to be HitTestEntry<T extends HitTestTarget> and making this class be SectorHitTestEntry extends HitTestEntry<RenderSector>?
There was a problem hiding this comment.
That probably would have been a good idea when HitTestEntry was first written. This is now just copying what the existing BoxHitTestEntry and SliverHitTestEntry is doing. Changing this now would be another breaking change. This one I find really hard to justify since it doesn't provide any user value. I'll leave it as is for now.
| /// | ||
| /// The [radius] and [theta] argument must not be null. | ||
| SectorHitTestEntry(RenderSector target, { @required this.radius, @required this.theta }) | ||
| : assert(radius != null), |
There was a problem hiding this comment.
assert(radius > 0), assert(theta > 0)?
There was a problem hiding this comment.
I believe negative values for these are fine.
| /// [target]. | ||
| final double radius; | ||
|
|
||
| /// The theta component of the hit test position in the local coordinates of |
There was a problem hiding this comment.
Can you elaborate on what the theta component is or provide breadcrumbs to more info about hit testing that explains the concepts of radius and theta?
There was a problem hiding this comment.
Radius and theta are concepts of a polar coordinate system, which is implemented by RenderSector as an alternative to RenderBox, which implements a cartesian coordinate system. It is just an example (see the directory) and as such poorly documented. (These are in fact the first doc comments in the file...). Both concepts are not really specific to hit testing. I added a general comment to the file.
| /// [SliverHitTestResult] for hit testing on [RenderSliver] children. | ||
| BoxHitTestResult.wrap(HitTestResult result) : super.wrap(result); | ||
|
|
||
| /// Transforms `position` to the local coordinate system of a child before |
There was a problem hiding this comment.
It feels weird that this does the hit testing -- and that this class is now both the result and an object that performs hit testing.
It almost feels like we need a level of indirection here, with a notion of a HitTester object (that may have a transformation applied to it) to which the render box delegates.
But take with comment with a huge grain of salt, since it's a drive-by code review from someone who knows these innards much less than you do 😄
There was a problem hiding this comment.
This does not perform the hit testing. It only transforms the coordinates to the coordinate space of the child, records the necessary transform and then executes the provided callback, which is supposed to implement the actual hit testing on the child. I updated the doc comment to make this clear.
Description
Introduces a
BoxHitTestResultforRenderBoxsubtypes andSliverHitTestResultforRenderSliversubtypes. These replace the genericHitTestResultfor those subtypes and allow us to implement Sliver and Box specific hit test helpers in those new classes (see #31222 for context).Related Issues
#29916
Tests
It's mostly a refactoring of existing functionality. Added tests for the newly introduced
BoxHitTestResultandSliverHitTestResult.Checklist
Before you create this PR confirm that it meets all requirements listed below by checking the relevant checkboxes (
[x]). This will ensure a smooth and quick review process.///).flutter analyze --flutter-repo) does not report any problems on my PR.Breaking Change
Does your PR require Flutter developers to manually update their apps to accommodate your change?
HitTestResultnow take eitherBoxHitTestResultorSliverHitTestResult, https://groups.google.com/forum/#!topic/flutter-announce/CnYVAz5dR4U