From 653b3e9d7c6e01e21773babcc7d090dace6233d7 Mon Sep 17 00:00:00 2001 From: Chris Bracken Date: Wed, 2 Nov 2022 10:15:56 -0700 Subject: [PATCH] Scroll 75% of x, y on each list scroll increment 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: https://github.com/flutter/gallery/pull/792 Related: https://github.com/flutter/flutter/issues/111131 Issue: https://github.com/flutter/flutter/issues/114025 --- test_driver/transitions_perf_test.dart | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/test_driver/transitions_perf_test.dart b/test_driver/transitions_perf_test.dart index 6d6f823116..b4679f6ecf 100644 --- a/test_driver/transitions_perf_test.dart +++ b/test_driver/transitions_perf_test.dart @@ -166,11 +166,25 @@ Future 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 demo lists. + // + // The Studies carousel has scroll physics that snap items to the left 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), );