-
Notifications
You must be signed in to change notification settings - Fork 30.6k
Fix PinnedHeaderSliver semantics focus capture #179023
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,9 +2,11 @@ | |
| // Use of this source code is governed by a BSD-style license that can be | ||
| // found in the LICENSE file. | ||
|
|
||
| import 'package:flutter/rendering.dart'; | ||
| import 'package:flutter/widgets.dart'; | ||
| import 'package:flutter_test/flutter_test.dart'; | ||
|
|
||
| import 'semantics_tester.dart'; | ||
| import 'widgets_app_tester.dart'; | ||
|
|
||
| void main() { | ||
|
|
@@ -244,4 +246,73 @@ void main() { | |
| expect(tester.getRect(find.text('PinnedHeaderSliver 1')), rect1); | ||
| expect(tester.getRect(find.text('PinnedHeaderSliver 2')), rect2); | ||
| }); | ||
|
|
||
| // Regression test for https://github.com/flutter/flutter/issues/179022. | ||
| testWidgets( | ||
| 'PinnedHeaderSliver: presence of RenderViewport.excludeFromScrolling tag when pinned', | ||
| (WidgetTester tester) async { | ||
| final semantics = SemanticsTester(tester); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would add the following to the top of this test.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
|
|
||
| await tester.pumpWidget( | ||
| TestWidgetsApp( | ||
| home: CustomScrollView( | ||
| slivers: <Widget>[ | ||
| const SliverToBoxAdapter(child: SizedBox(height: 100, child: Text('First child'))), | ||
| const PinnedHeaderSliver(child: Text('PinnedHeaderSliver')), | ||
| SliverList.builder( | ||
| itemCount: 50, | ||
| itemBuilder: (BuildContext context, int index) => Text('Item $index'), | ||
| ), | ||
| ], | ||
| ), | ||
| ), | ||
| ); | ||
|
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe we should verify if the sliver actually gets pinned after the drag similar to other tests in this file. Rect getHeaderRect() => tester.getRect(find.text('PinnedHeaderSliver'));
Rect getFirstChildRect() => tester.getRect(find.text('First child'));
// Pinned header appears after first child initially.
final Rect firstChildRect = getFirstChildRect();
expect(firstChildRect.top, 0.0);
expect(firstChildRect.height, 100.0);
expect(getHeaderRect().top, 100.0);
.....
....
...
..
. after drag....
// Pinned header should be pinned to the top after drag.
expect(getHeaderRect().top, 0.0);
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hi @Renzo-Olivares, I'm back from holidays 😄 ⛷️ Done. |
||
| Rect getHeaderRect() => tester.getRect(find.text('PinnedHeaderSliver')); | ||
| Rect getFirstChildRect() => tester.getRect(find.text('First child')); | ||
|
|
||
| // Pinned header appears after first child initially. | ||
| final Rect firstChildRect = getFirstChildRect(); | ||
| expect(firstChildRect.top, 0.0); | ||
| expect(firstChildRect.height, 100.0); | ||
| expect(getHeaderRect().top, 100.0); | ||
|
|
||
| expect( | ||
| semantics, | ||
| isNot( | ||
| includesNodeWith( | ||
| tags: {RenderViewport.excludeFromScrolling, RenderViewport.useTwoPaneSemantics}, | ||
| ), | ||
| ), | ||
| ); | ||
|
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should verify that before the drag the sliver is not pinned and the exclude tag is not present and after the drag that it is pinned.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
| await tester.drag(find.byType(CustomScrollView), const Offset(0, -100)); | ||
| await tester.pumpAndSettle(); | ||
|
|
||
| // Pinned header should be pinned to the top after drag. | ||
| expect(getHeaderRect().top, 0.0); | ||
|
|
||
| expect( | ||
| semantics, | ||
| isNot( | ||
| includesNodeWith( | ||
| tags: {RenderViewport.excludeFromScrolling, RenderViewport.useTwoPaneSemantics}, | ||
| ), | ||
| ), | ||
| ); | ||
|
|
||
| await tester.drag(find.byType(CustomScrollView), const Offset(0, -20)); | ||
| await tester.pumpAndSettle(); | ||
|
|
||
| final SemanticsNode? semanticNode = semantics | ||
| .nodesWith(label: 'PinnedHeaderSliver') | ||
| .firstOrNull; | ||
| expect(semanticNode?.parent?.tags, { | ||
| RenderViewport.excludeFromScrolling, | ||
| RenderViewport.useTwoPaneSemantics, | ||
| }); | ||
|
|
||
| semantics.dispose(); | ||
| }, | ||
| ); | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.