Skip to content

Commit 52b7d1b

Browse files
authored
[two_dimensional_scrollables] Fix missing leading cache extent for TableView (flutter#9636)
Fixes flutter/flutter#167813 The cache extent was not being applied to leading children, only trailing. This fixes that. Will check TreeView to see if the same issue applies after this. ## Pre-Review Checklist [^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 6472c94 commit 52b7d1b

File tree

4 files changed

+163
-75
lines changed

4 files changed

+163
-75
lines changed

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.3.7
2+
3+
* Fixes missing leading cache extent in TableView.
4+
15
## 0.3.6
26

37
* Fixes typo in API docs.

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

Lines changed: 34 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -333,8 +333,17 @@ class RenderTableViewport extends RenderTwoDimensionalViewport {
333333

334334
int? _columnNullTerminatedIndex;
335335
bool get _columnsAreInfinite => delegate.columnCount == null;
336+
// Where column layout begins, potentially outside of the visible area.
337+
double get _targetLeadingColumnPixel {
338+
return clampDouble(
339+
horizontalOffset.pixels - cacheExtent,
340+
0,
341+
double.infinity,
342+
);
343+
}
344+
336345
// How far columns should be laid out in a given frame.
337-
double get _targetColumnPixel {
346+
double get _targetTrailingColumnPixel {
338347
return cacheExtent +
339348
horizontalOffset.pixels +
340349
viewportDimension.width -
@@ -343,8 +352,17 @@ class RenderTableViewport extends RenderTwoDimensionalViewport {
343352

344353
int? _rowNullTerminatedIndex;
345354
bool get _rowsAreInfinite => delegate.rowCount == null;
355+
// Where row layout begins, potentially outside of the visible area.
356+
double get _targetLeadingRowPixel {
357+
return clampDouble(
358+
verticalOffset.pixels - cacheExtent,
359+
0,
360+
double.infinity,
361+
);
362+
}
363+
346364
// How far rows should be laid out in a given frame.
347-
double get _targetRowPixel {
365+
double get _targetTrailingRowPixel {
348366
return cacheExtent +
349367
verticalOffset.pixels +
350368
viewportDimension.height -
@@ -535,11 +553,11 @@ class RenderTableViewport extends RenderTwoDimensionalViewport {
535553
);
536554
_columnMetrics[column] = span;
537555
if (!isPinned) {
538-
if (span.trailingOffset >= horizontalOffset.pixels &&
556+
if (span.trailingOffset >= _targetLeadingColumnPixel &&
539557
_firstNonPinnedColumn == null) {
540558
_firstNonPinnedColumn = column;
541559
}
542-
if (span.trailingOffset >= _targetColumnPixel &&
560+
if (span.trailingOffset >= _targetTrailingColumnPixel &&
543561
_lastNonPinnedColumn == null) {
544562
_lastNonPinnedColumn = column;
545563
}
@@ -637,11 +655,11 @@ class RenderTableViewport extends RenderTwoDimensionalViewport {
637655
);
638656
_rowMetrics[row] = span;
639657
if (!isPinned) {
640-
if (span.trailingOffset >= verticalOffset.pixels &&
658+
if (span.trailingOffset >= _targetLeadingRowPixel &&
641659
_firstNonPinnedRow == null) {
642660
_firstNonPinnedRow = row;
643661
}
644-
if (span.trailingOffset > _targetRowPixel &&
662+
if (span.trailingOffset >= _targetTrailingRowPixel &&
645663
_lastNonPinnedRow == null) {
646664
_lastNonPinnedRow = row;
647665
}
@@ -723,13 +741,13 @@ class RenderTableViewport extends RenderTwoDimensionalViewport {
723741
if (_columnMetrics.isNotEmpty) {
724742
_Span lastKnownColumn = _columnMetrics[_columnMetrics.length - 1]!;
725743
if (_columnsAreInfinite &&
726-
lastKnownColumn.trailingOffset < _targetColumnPixel) {
744+
lastKnownColumn.trailingOffset < _targetTrailingColumnPixel) {
727745
// This will add the column metrics we do not know about up to the
728746
// _targetColumnPixel, while keeping the ones we already know about.
729747
_updateColumnMetrics(appendColumns: true);
730748
lastKnownColumn = _columnMetrics[_columnMetrics.length - 1]!;
731749
assert(_columnMetrics.length == delegate.columnCount ||
732-
lastKnownColumn.trailingOffset >= _targetColumnPixel ||
750+
lastKnownColumn.trailingOffset >= _targetTrailingColumnPixel ||
733751
_columnNullTerminatedIndex != null);
734752
}
735753
}
@@ -740,11 +758,12 @@ class RenderTableViewport extends RenderTwoDimensionalViewport {
740758
continue;
741759
}
742760
final double endOfColumn = _columnMetrics[column]!.trailingOffset;
743-
if (endOfColumn >= horizontalOffset.pixels &&
761+
if (endOfColumn >= _targetLeadingColumnPixel &&
744762
_firstNonPinnedColumn == null) {
745763
_firstNonPinnedColumn = column;
746764
}
747-
if (endOfColumn >= _targetColumnPixel && _lastNonPinnedColumn == null) {
765+
if (endOfColumn >= _targetTrailingColumnPixel &&
766+
_lastNonPinnedColumn == null) {
748767
_lastNonPinnedColumn = column;
749768
break;
750769
}
@@ -755,13 +774,14 @@ class RenderTableViewport extends RenderTwoDimensionalViewport {
755774

756775
if (_rowMetrics.isNotEmpty) {
757776
_Span lastKnownRow = _rowMetrics[_rowMetrics.length - 1]!;
758-
if (_rowsAreInfinite && lastKnownRow.trailingOffset < _targetRowPixel) {
777+
if (_rowsAreInfinite &&
778+
lastKnownRow.trailingOffset < _targetTrailingRowPixel) {
759779
// This will add the row metrics we do not know about up to the
760780
// _targetRowPixel, while keeping the ones we already know about.
761781
_updateRowMetrics(appendRows: true);
762782
lastKnownRow = _rowMetrics[_rowMetrics.length - 1]!;
763783
assert(_rowMetrics.length == delegate.rowCount ||
764-
lastKnownRow.trailingOffset >= _targetRowPixel ||
784+
lastKnownRow.trailingOffset >= _targetTrailingRowPixel ||
765785
_rowNullTerminatedIndex != null);
766786
}
767787
}
@@ -772,10 +792,10 @@ class RenderTableViewport extends RenderTwoDimensionalViewport {
772792
continue;
773793
}
774794
final double endOfRow = _rowMetrics[row]!.trailingOffset;
775-
if (endOfRow >= verticalOffset.pixels && _firstNonPinnedRow == null) {
795+
if (endOfRow >= _targetLeadingRowPixel && _firstNonPinnedRow == null) {
776796
_firstNonPinnedRow = row;
777797
}
778-
if (endOfRow >= _targetRowPixel && _lastNonPinnedRow == null) {
798+
if (endOfRow >= _targetTrailingRowPixel && _lastNonPinnedRow == null) {
779799
_lastNonPinnedRow = row;
780800
break;
781801
}
@@ -831,7 +851,6 @@ class RenderTableViewport extends RenderTwoDimensionalViewport {
831851
_rowMetrics[_firstNonPinnedRow]!.leadingOffset -
832852
_pinnedRowsExtent
833853
: null;
834-
835854
if (_lastPinnedRow != null && _lastPinnedColumn != null) {
836855
// Layout cells that are contained in both pinned rows and columns
837856
_layoutCells(

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.3.6
3+
version: 0.3.7
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)