Skip to content

Commit

Permalink
[two_dimensional_scrollables] Fix paint bug when rows/columns are pin…
Browse files Browse the repository at this point in the history
…ned and axes are reversed (#5038)

Fixes flutter/flutter#135386

This adds one more golden to verify the painting, but once public mock_canvas rolls to stable in flutter_test, we can remove all of the goldens and just verify using the `paints` method.
  • Loading branch information
Piinks committed Oct 10, 2023
1 parent bb9de56 commit bec2c95
Show file tree
Hide file tree
Showing 7 changed files with 108 additions and 27 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.0.3

* Fixes paint issue when axes are reversed and TableView has pinned rows and columns.

## 0.0.2

* Fixes override of default TwoDimensionalChildBuilderDelegate.addRepaintBoundaries.
Expand Down
24 changes: 18 additions & 6 deletions packages/two_dimensional_scrollables/lib/src/table_view/table.dart
Original file line number Diff line number Diff line change
Expand Up @@ -723,8 +723,12 @@ class RenderTableViewport extends RenderTwoDimensionalViewport {
needsCompositing,
offset,
Rect.fromLTWH(
_pinnedColumnsExtent,
_pinnedRowsExtent,
axisDirectionIsReversed(horizontalAxisDirection)
? 0.0
: _pinnedColumnsExtent,
axisDirectionIsReversed(verticalAxisDirection)
? 0.0
: _pinnedRowsExtent,
viewportDimension.width - _pinnedColumnsExtent,
viewportDimension.height - _pinnedRowsExtent,
),
Expand All @@ -750,8 +754,12 @@ class RenderTableViewport extends RenderTwoDimensionalViewport {
needsCompositing,
offset,
Rect.fromLTWH(
0.0,
_pinnedRowsExtent,
axisDirectionIsReversed(horizontalAxisDirection)
? viewportDimension.width - _pinnedColumnsExtent
: 0.0,
axisDirectionIsReversed(verticalAxisDirection)
? 0.0
: _pinnedRowsExtent,
_pinnedColumnsExtent,
viewportDimension.height - _pinnedRowsExtent,
),
Expand All @@ -778,8 +786,12 @@ class RenderTableViewport extends RenderTwoDimensionalViewport {
needsCompositing,
offset,
Rect.fromLTWH(
_pinnedColumnsExtent,
0.0,
axisDirectionIsReversed(horizontalAxisDirection)
? 0.0
: _pinnedColumnsExtent,
axisDirectionIsReversed(horizontalAxisDirection)
? viewportDimension.height - _pinnedRowsExtent
: 0.0,
viewportDimension.width - _pinnedColumnsExtent,
_pinnedRowsExtent,
),
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.0.2
version: 0.0.3
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
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
105 changes: 85 additions & 20 deletions packages/two_dimensional_scrollables/test/table_view/table_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -957,23 +957,27 @@ void main() {
columnBuilder: (int index) => TableSpan(
extent: const FixedTableSpanExtent(200.0),
foregroundDecoration: const TableSpanDecoration(
border: TableSpanBorder(
trailing: BorderSide(
color: Colors.orange,
width: 3,
))),
border: TableSpanBorder(
trailing: BorderSide(
color: Colors.orange,
width: 3,
),
),
),
backgroundDecoration: TableSpanDecoration(
color: index.isEven ? Colors.red : null,
),
),
rowBuilder: (int index) => TableSpan(
extent: const FixedTableSpanExtent(200.0),
foregroundDecoration: const TableSpanDecoration(
border: TableSpanBorder(
leading: BorderSide(
color: Colors.green,
width: 3,
))),
border: TableSpanBorder(
leading: BorderSide(
color: Colors.green,
width: 3,
),
),
),
backgroundDecoration: TableSpanDecoration(
color: index.isOdd ? Colors.blue : null,
),
Expand Down Expand Up @@ -1002,23 +1006,27 @@ void main() {
columnBuilder: (int index) => TableSpan(
extent: const FixedTableSpanExtent(200.0),
foregroundDecoration: const TableSpanDecoration(
border: TableSpanBorder(
trailing: BorderSide(
color: Colors.orange,
width: 3,
))),
border: TableSpanBorder(
trailing: BorderSide(
color: Colors.orange,
width: 3,
),
),
),
backgroundDecoration: TableSpanDecoration(
color: index.isEven ? Colors.red : null,
),
),
rowBuilder: (int index) => TableSpan(
extent: const FixedTableSpanExtent(200.0),
foregroundDecoration: const TableSpanDecoration(
border: TableSpanBorder(
leading: BorderSide(
color: Colors.green,
width: 3,
))),
border: TableSpanBorder(
leading: BorderSide(
color: Colors.green,
width: 3,
),
),
),
backgroundDecoration: TableSpanDecoration(
color: index.isOdd ? Colors.blue : null,
),
Expand All @@ -1040,6 +1048,63 @@ void main() {
);
});

testWidgets('paint rects are correct when reversed and pinned',
(WidgetTester tester) async {
// TODO(Piinks): Rewrite this to remove golden files from this repo when
// mock_canvas is public - https://github.com/flutter/flutter/pull/131631
// foreground, background, and precedence per mainAxis
final TableView tableView = TableView.builder(
verticalDetails: const ScrollableDetails.vertical(reverse: true),
horizontalDetails: const ScrollableDetails.horizontal(reverse: true),
rowCount: 2,
pinnedRowCount: 1,
columnCount: 2,
pinnedColumnCount: 1,
columnBuilder: (int index) => TableSpan(
extent: const FixedTableSpanExtent(200.0),
foregroundDecoration: const TableSpanDecoration(
border: TableSpanBorder(
trailing: BorderSide(
color: Colors.orange,
width: 3,
),
),
),
backgroundDecoration: TableSpanDecoration(
color: index.isEven ? Colors.red : null,
),
),
rowBuilder: (int index) => TableSpan(
extent: const FixedTableSpanExtent(200.0),
foregroundDecoration: const TableSpanDecoration(
border: TableSpanBorder(
leading: BorderSide(
color: Colors.green,
width: 3,
),
),
),
backgroundDecoration: TableSpanDecoration(
color: index.isOdd ? Colors.blue : null,
),
),
cellBuilder: (_, TableVicinity vicinity) {
return const SizedBox.square(
dimension: 200,
child: Center(child: FlutterLogo()),
);
},
);

await tester.pumpWidget(MaterialApp(home: tableView));
await tester.pumpAndSettle();
await expectLater(
find.byType(TableView),
matchesGoldenFile('goldens/reversed.pinned.painting.png'),
skip: !runGoldens,
);
});

testWidgets('mouse handling', (WidgetTester tester) async {
int enterCounter = 0;
int exitCounter = 0;
Expand Down

0 comments on commit bec2c95

Please sign in to comment.