Add RenderSliver.getMaxPaintRect#180074
Conversation
There was a problem hiding this comment.
Code Review
This pull request extracts a shared method RenderSliver.getMaxPaintRect and adds comprehensive tests for it. The implementation appears correct and the tests cover various scenarios. I have one suggestion to improve code style and readability by renaming a local variable to avoid shadowing an instance member.
5fe6903 to
03277be
Compare
03277be to
8fad906
Compare
| @protected | ||
| Rect getMaxPaintRect() { | ||
| final SliverGeometry? sliverGeometry = geometry; | ||
| if (sliverGeometry == null) { |
There was a problem hiding this comment.
| if (sliverGeometry == null) { | |
| if (sliverGeometry == null || sliverGeometry == SliverGeometry.zero) { |
Should we short circuit the zero case here as well?
| constraints.scrollOffset + sliverGeometry.cacheExtent + constraints.cacheOrigin; | ||
| } | ||
| final double paintExtent = sliverGeometry.paintExtent; | ||
| // If sliver is pinned, the scroll offset is sticked to the edge. |
There was a problem hiding this comment.
| // If sliver is pinned, the scroll offset is sticked to the edge. | |
| // If sliver is pinned, the scroll offset is stuck to the edge. |
I think? Can you explain this a bit more?
There was a problem hiding this comment.
Done.
I've tried to make it clearer. I also renamed the variable to leadingOffset.
| -clampedScrollOffset, | ||
| 0.0, | ||
| maxPaintExtent, | ||
| constraints.crossAxisExtent, |
There was a problem hiding this comment.
Could this potentially be incorrect in the case of SliverCrossAxisGroup? The rect may not go from 0 --> crossAxisExtent if there are multiple slivers in the cross axis grouping.
There was a problem hiding this comment.
This would make for some good test cases as well.
There was a problem hiding this comment.
Could this potentially be incorrect in the case of SliverCrossAxisGroup? The rect may not go from 0 --> crossAxisExtent if there are multiple slivers in the cross axis grouping.
This is a good catch! Done!
| sliver.layout( | ||
| const SliverConstraints( | ||
| axisDirection: AxisDirection.down, | ||
| growthDirection: GrowthDirection.forward, |
There was a problem hiding this comment.
Should there be test cases that cover when GrowthDirection.reverse is used?
| } | ||
| } | ||
|
|
||
| /// Returns the [Rect] that covers the total paint extent of the sliver. |
There was a problem hiding this comment.
I might add to the docs clarity about what coordinate space this rect is, local to the viewport, global to the screen?
There was a problem hiding this comment.
I might add to the docs clarity about what coordinate space this rect is, local to the viewport, global to the screen?
Done. Let me know if that's okay.
There was a problem hiding this comment.
Actually, the resulting coordinates match the ones used in paint (via the offset parameter). So I tried to use the same terminology in the explanation.
8fad906 to
58c2388
Compare
Renzo-Olivares
left a comment
There was a problem hiding this comment.
LGTM, thank you for your patience and contribution!
|
autosubmit label was removed for flutter/flutter/180074, because The base commit of the PR is older than 7 days and can not be merged. Please merge the latest changes from the main into this branch and resubmit the PR. |
|
Rebasing to pass the check. :) |
986357d to
084e702
Compare
This PR extracts the `getMaxPaintRect` logic into a shared method in `RenderSliver`. This helper is required for upcoming changes in flutter#179003 and flutter#179802 to avoid code duplication. Cc @Piinks ## 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.
This PR extracts the
getMaxPaintRectlogic into a shared method inRenderSliver. This helper is required for upcoming changes in #179003 and #179802 to avoid code duplication.Cc @Piinks
Pre-launch Checklist
///).