Skip to content

Commit

Permalink
[two_dimensional_scrollables] Fix layout offset of merged pinned cells (
Browse files Browse the repository at this point in the history
flutter#6178)

Fixes flutter/flutter#143526

This fixes the layout offset computation when there are merged cells within pinned rows and/or columns in TableView.
  • Loading branch information
Piinks authored Feb 22, 2024
1 parent ff587b7 commit 67470fc
Show file tree
Hide file tree
Showing 4 changed files with 509 additions and 3 deletions.
4 changes: 4 additions & 0 deletions packages/two_dimensional_scrollables/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.1.1

* Fixes a layout issue when pinned cells are merged.

## 0.1.0

* [Breaking change] Adds support for merged cells in the TableView.
Expand Down
30 changes: 28 additions & 2 deletions packages/two_dimensional_scrollables/lib/src/table_view/table.dart
Original file line number Diff line number Diff line change
Expand Up @@ -801,15 +801,41 @@ class RenderTableViewport extends RenderTwoDimensionalViewport {
// | <--------- extent of merged cell ---------> |

// Compute height and layout offset for merged rows.
mergedRowOffset = -verticalOffset.pixels +
final bool rowIsInPinnedColumn = _lastPinnedColumn != null &&
vicinity.column <= _lastPinnedColumn!;
final bool rowIsPinned =
_lastPinnedRow != null && firstRow <= _lastPinnedRow!;
final double baseRowOffset =
switch ((rowIsInPinnedColumn, rowIsPinned)) {
// Both row and column are pinned at this cell, or just pinned row.
(true, true) || (false, true) => 0.0,
// Cell is within a pinned column
(true, false) => _pinnedRowsExtent - verticalOffset.pixels,
// Cell is within a pinned row, or no pinned portion.
(false, false) => -verticalOffset.pixels,
};
mergedRowOffset = baseRowOffset +
_rowMetrics[firstRow]!.leadingOffset +
_rowMetrics[firstRow]!.configuration.padding.leading;
mergedRowHeight = _rowMetrics[lastRow]!.trailingOffset -
_rowMetrics[firstRow]!.leadingOffset -
_rowMetrics[lastRow]!.configuration.padding.trailing -
_rowMetrics[firstRow]!.configuration.padding.leading;
// Compute width and layout offset for merged columns.
mergedColumnOffset = -horizontalOffset.pixels +
final bool columnIsInPinnedRow =
_lastPinnedRow != null && vicinity.row <= _lastPinnedRow!;
final bool columnIsPinned =
_lastPinnedColumn != null && firstColumn <= _lastPinnedColumn!;
final double baseColumnOffset =
switch ((columnIsInPinnedRow, columnIsPinned)) {
// Both row and column are pinned at this cell, or just pinned column.
(true, true) || (false, true) => 0.0,
// Cell is within a pinned row.
(true, false) => _pinnedColumnsExtent - horizontalOffset.pixels,
// No pinned portion.
(false, false) => -horizontalOffset.pixels,
};
mergedColumnOffset = baseColumnOffset +
_columnMetrics[firstColumn]!.leadingOffset +
_columnMetrics[firstColumn]!.configuration.padding.leading;
mergedColumnWidth = _columnMetrics[lastColumn]!.trailingOffset -
Expand Down
2 changes: 1 addition & 1 deletion packages/two_dimensional_scrollables/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: two_dimensional_scrollables
description: Widgets that scroll using the two dimensional scrolling foundation.
version: 0.1.0
version: 0.1.1
repository: https://github.com/flutter/packages/tree/main/packages/two_dimensional_scrollables
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+two_dimensional_scrollables%22+

Expand Down
Loading

0 comments on commit 67470fc

Please sign in to comment.