Skip to content
This repository has been archived by the owner on Jun 13, 2024. It is now read-only.

Commit

Permalink
Scroll 75% of x, y on each list scroll increment
Browse files Browse the repository at this point in the history
The gallery driver test includes logic to scroll through various lists
of demos in order to transition to each one. These lists include the
horizontally-scrolling studies list at the top of the gallery home page,
as well as the vertically-scrolling Material, Cupertino, and Other
demo lists on the same page.

TestDriver.scrollUntilVisible scrolls a parent list widget in increments
of dx and/or dy until the specified list item widget is visible. The
Studies carousel list at the top of the gallery home screen has scroll
physics that snap items to the starting edge of the widget. If the dx
scroll distance is too small, the Studies list doesn't scroll far enough
and snaps back to its original position. Conversely, if it scrolls too
far, it may scroll one widget too far and snap the next widget into
place. Instead, we now scroll 75% of the carousel width (empirically
determined) as an attempt at a value in the Goldilocks Zone.

Related: #792
Related: flutter/flutter#111131

Issue: flutter/flutter#114025
  • Loading branch information
cbracken committed Nov 2, 2022
1 parent e6d42a7 commit 9138423
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions test_driver/transitions_perf_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -166,11 +166,25 @@ Future<void> runDemos(
demoItem = find.byValueKey(demo);

stdout.writeln('scrolling to demo');

// demoList below may be either the horizontally-scrolling Studies carousel
// or vertically scrolling Material/Cupertino/Other demo lists.
//
// The Studies carousel has scroll physics that snap items to the starting
// edge of the widget. TestDriver.scrollUntilVisible scrolls in increments
// along the x and y axes; if the distance is too small, the list snaps
// back to its previous position, if it's too large, it may scroll too far.
// To resolve this, we scroll 75% of the list width/height dimensions on
// each increment.
final DriverOffset topLeft = await driver.getTopLeft(demoList, timeout: const Duration(seconds: 10));
final DriverOffset bottomRight = await driver.getBottomRight(demoList, timeout: const Duration(seconds: 10));
final double listWidth = bottomRight.dx - topLeft.dx;
final double listHeight = bottomRight.dy - topLeft.dy;
await driver.scrollUntilVisible(
demoList,
demoItem,
dxScroll: -800,
dyScroll: -50,
dxScroll: -listWidth * 0.75,
dyScroll: -listHeight * 0.75,
alignment: 0.5,
timeout: const Duration(seconds: 10),
);
Expand Down

0 comments on commit 9138423

Please sign in to comment.