Skip to content

Commit f895ad5

Browse files
[two_dimensional_scrollables] Fix pinned cells hit test (flutter#13376)
This picks up flutter#11777 by @beroso, which was closed while review comments were still open. It keeps the original commits and adds one on top. `TableView` hit-tested each cell against its full rect, so a regular cell scrolled under a trailing pinned row or column could take taps meant for the pinned cell, like a menu button in a pinned last column. The change from flutter#11777 limits each cell's hit test to the viewport band of its own section (leading pinned, regular or trailing pinned) and accounts for the alignment offsets. My commit adds the tests asked for in review: reversed vertical axis, both axes reversed, a vertically reversed table with alignment, and RTL with directional alignment. It also disposes the scroll controllers in the hit test tests, which failed leak tracking once it was enabled for this package in flutter#11653. The CHANGELOG entry uses the suggested wording. Without the change in `table.dart`, six of the twelve hit test tests fail, including the two new reversed-axis ones. The alignment and RTL tests pass either way, since they cover the alignment offset case raised in review. On Flutter 3.47.6 stable, `flutter test` passes for the package (182 tests) and the hit test group also passes with `--platform chrome`. `flutter analyze` and the repo tool's `validate` report no issues. Fixes flutter/flutter#186876 ## Pre-Review Checklist **Note**: The Flutter team is currently trialing the use of [Gemini Code Assist for GitHub](https://developers.google.com/gemini-code-assist/docs/review-github-code). Comments from the `gemini-code-assist` bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed. [^1]: Regular contributors who have demonstrated familiarity with the repository guidelines only need to comment if the PR is not auto-exempted by repo tooling.
1 parent 176df83 commit f895ad5

4 files changed

Lines changed: 793 additions & 2 deletions

File tree

‎packages/two_dimensional_scrollables/CHANGELOG.md‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.5.6
2+
3+
* Fixes an issue where trailing pinned cells in `TableView` were losing hit tests to underlying non-pinned cells.
4+
15
## 0.5.5
26

37
* Fixes `TableView` laying out and painting trailing pinned rows and columns twice, which could throw when the table was scrolled to the end.

‎packages/two_dimensional_scrollables/lib/src/table_view/table.dart‎

Lines changed: 88 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -681,7 +681,11 @@ class RenderTableViewport extends RenderTwoDimensionalViewport {
681681
continue;
682682
}
683683
final Rect cellRect = cellParentData.paintOffset! & cell.size;
684-
if (cellRect.contains(position)) {
684+
// Intersect with the section clip rect for this cell to prevent
685+
// scrollable cells from stealing hits inside the trailing pinned area.
686+
// This mirrors the pushClipRect applied to each section during painting.
687+
if (cellRect.contains(position) &&
688+
_sectionClipRectFor(cellParentData.tableVicinity).contains(position)) {
685689
result.addWithPaintOffset(
686690
offset: cellParentData.paintOffset,
687691
position: position,
@@ -707,6 +711,89 @@ class RenderTableViewport extends RenderTwoDimensionalViewport {
707711
return false;
708712
}
709713

714+
// Returns the viewport-space clip rect that painting applies to the section
715+
// a cell belongs to (leading-pinned, non-pinned, or trailing-pinned for each
716+
// axis). Intersecting the raw cell rect with this rect in hitTestChildren
717+
// prevents scrollable cells from capturing taps inside pinned areas.
718+
//
719+
// Alignment offsets must be factored in:
720+
// * Leading-pinned cells are laid out with _hAlignmentOffset /
721+
// _vAlignmentOffset applied, so their paint position (and section
722+
// boundary) shifts by those values.
723+
// * Trailing-pinned cells are always placed at the absolute viewport edge
724+
// via -(viewportDimension - trailingExtent), independent of alignment.
725+
// * Non-pinned boundaries that border the leading-pinned section inherit
726+
// the same shift; boundaries that border the trailing-pinned section
727+
// do not.
728+
Rect _sectionClipRectFor(TableVicinity vicinity) {
729+
final bool reversedH = axisDirectionIsReversed(horizontalAxisDirection);
730+
final bool reversedV = axisDirectionIsReversed(verticalAxisDirection);
731+
final Size viewportSize = viewportDimension;
732+
733+
final double colLeft, colRight;
734+
if (vicinity.column < delegate.pinnedColumnCount) {
735+
// Leading pinned column.
736+
if (reversedH) {
737+
colLeft = viewportSize.width - _leadingPinnedColumnsExtent - _hAlignmentOffset;
738+
colRight = viewportSize.width - _hAlignmentOffset;
739+
} else {
740+
colLeft = _hAlignmentOffset;
741+
colRight = _hAlignmentOffset + _leadingPinnedColumnsExtent;
742+
}
743+
} else if (_firstTrailingPinnedColumn != null &&
744+
vicinity.column >= _firstTrailingPinnedColumn!) {
745+
// Trailing pinned column.
746+
if (reversedH) {
747+
colLeft = 0.0;
748+
colRight = _trailingPinnedColumnsExtent;
749+
} else {
750+
colLeft = viewportSize.width - _trailingPinnedColumnsExtent;
751+
colRight = viewportSize.width;
752+
}
753+
} else {
754+
// Non-pinned column.
755+
if (reversedH) {
756+
colLeft = _trailingPinnedColumnsExtent;
757+
colRight = viewportSize.width - _leadingPinnedColumnsExtent - _hAlignmentOffset;
758+
} else {
759+
colLeft = _leadingPinnedColumnsExtent + _hAlignmentOffset;
760+
colRight = viewportSize.width - _trailingPinnedColumnsExtent;
761+
}
762+
}
763+
764+
final double rowTop, rowBottom;
765+
if (vicinity.row < delegate.pinnedRowCount) {
766+
// Leading pinned row.
767+
if (reversedV) {
768+
rowTop = viewportSize.height - _leadingPinnedRowsExtent - _vAlignmentOffset;
769+
rowBottom = viewportSize.height - _vAlignmentOffset;
770+
} else {
771+
rowTop = _vAlignmentOffset;
772+
rowBottom = _vAlignmentOffset + _leadingPinnedRowsExtent;
773+
}
774+
} else if (_firstTrailingPinnedRow != null && vicinity.row >= _firstTrailingPinnedRow!) {
775+
// Trailing pinned row.
776+
if (reversedV) {
777+
rowTop = 0.0;
778+
rowBottom = _trailingPinnedRowsExtent;
779+
} else {
780+
rowTop = viewportSize.height - _trailingPinnedRowsExtent;
781+
rowBottom = viewportSize.height;
782+
}
783+
} else {
784+
// Non-pinned row.
785+
if (reversedV) {
786+
rowTop = _trailingPinnedRowsExtent;
787+
rowBottom = viewportSize.height - _leadingPinnedRowsExtent - _vAlignmentOffset;
788+
} else {
789+
rowTop = _leadingPinnedRowsExtent + _vAlignmentOffset;
790+
rowBottom = viewportSize.height - _trailingPinnedRowsExtent;
791+
}
792+
}
793+
794+
return Rect.fromLTRB(colLeft, rowTop, colRight, rowBottom);
795+
}
796+
710797
// Updates the cached column metrics for the table.
711798
//
712799
// By default, existing column metrics will be updated if they have changed.

‎packages/two_dimensional_scrollables/pubspec.yaml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: two_dimensional_scrollables
22
description: Widgets that scroll using the two dimensional scrolling foundation.
3-
version: 0.5.5
3+
version: 0.5.6
44
repository: https://github.com/flutter/packages/tree/main/packages/two_dimensional_scrollables
55
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+two_dimensional_scrollables%22+
66

0 commit comments

Comments
 (0)