From 4e7a38b11889946e1be09b87caed263b692ce00a Mon Sep 17 00:00:00 2001 From: Mehmet Fidanboylu Date: Wed, 26 Apr 2017 14:22:11 -0700 Subject: [PATCH] Add a tile scrolling test to complex_layout app (#9537) * Add a tile scrolling test to complex_layout app * - Review comments and fix analyzer failures. * Use ListView.builder pattern. --- dev/benchmarks/complex_layout/lib/main.dart | 51 +++++++++++++++++-- .../test_driver/scroll_perf_test.dart | 24 ++++++--- 2 files changed, 65 insertions(+), 10 deletions(-) diff --git a/dev/benchmarks/complex_layout/lib/main.dart b/dev/benchmarks/complex_layout/lib/main.dart index 2075262c4a5..ec8e370b9c6 100644 --- a/dev/benchmarks/complex_layout/lib/main.dart +++ b/dev/benchmarks/complex_layout/lib/main.dart @@ -11,6 +11,8 @@ void main() { ); } +enum ScrollMode { complex, tile } + class ComplexLayoutApp extends StatefulWidget { @override ComplexLayoutAppState createState() => new ComplexLayoutAppState(); @@ -24,8 +26,7 @@ class ComplexLayoutAppState extends State { return new MaterialApp( theme: lightTheme ? new ThemeData.light() : new ThemeData.dark(), title: 'Advanced Layout', - home: const ComplexLayout() - ); + home: scrollMode == ScrollMode.complex ? const ComplexLayout() : const TileScrollLayout()); } bool _lightTheme = true; @@ -36,6 +37,14 @@ class ComplexLayoutAppState extends State { }); } + ScrollMode _scrollMode = ScrollMode.complex; + ScrollMode get scrollMode => _scrollMode; + set scrollMode(ScrollMode mode) { + setState(() { + _scrollMode = mode; + }); + } + void toggleAnimationSpeed() { setState(() { timeDilation = (timeDilation != 1.0) ? 1.0 : 5.0; @@ -43,6 +52,32 @@ class ComplexLayoutAppState extends State { } } +class TileScrollLayout extends StatelessWidget { + const TileScrollLayout({ Key key }) : super(key: key); + + @override + Widget build(BuildContext context) { + return new Scaffold( + appBar: new AppBar(title: const Text('Tile Scrolling Layout')), + body: new ListView.builder( + key: const Key('tiles-scroll'), + itemCount: 200, + itemBuilder: (BuildContext context, int index) { + return new Padding( + padding:const EdgeInsets.all(5.0), + child: new Material( + elevation: index % 5 + 1, + color: Colors.white, + child: new IconBar(), + ), + ); + } + ), + drawer: const GalleryDrawer(), + ); + } +} + class ComplexLayout extends StatefulWidget { const ComplexLayout({ Key key }) : super(key: key); @@ -73,7 +108,7 @@ class ComplexLayoutState extends State { children: [ new Expanded( child: new ListView.builder( - key: const Key('main-scroll'), // this key is used by the driver test + key: const Key('complex-scroll'), // this key is used by the driver test itemBuilder: (BuildContext context, int index) { if (index % 2 == 0) return new FancyImageItem(index, key: new ValueKey(index)); @@ -571,12 +606,22 @@ class GalleryDrawer extends StatelessWidget { ComplexLayoutApp.of(context).lightTheme = value; } + void _changeScrollMode(BuildContext context, ScrollMode mode) { + ComplexLayoutApp.of(context).scrollMode = mode; + } + @override Widget build(BuildContext context) { + final ScrollMode currentMode = ComplexLayoutApp.of(context).scrollMode; return new Drawer( child: new ListView( children: [ new FancyDrawerHeader(), + new ListTile( + key: const Key('scroll-switcher'), + onTap: () { _changeScrollMode(context, currentMode == ScrollMode.complex ? ScrollMode.tile : ScrollMode.complex); }, + trailing: new Text(currentMode == ScrollMode.complex ? 'Tile' : 'Complex') + ), new ListTile( leading: const Icon(Icons.brightness_5), title: const Text('Light'), diff --git a/dev/benchmarks/complex_layout/test_driver/scroll_perf_test.dart b/dev/benchmarks/complex_layout/test_driver/scroll_perf_test.dart index 29e97d6ba12..1f47c7f079d 100644 --- a/dev/benchmarks/complex_layout/test_driver/scroll_perf_test.dart +++ b/dev/benchmarks/complex_layout/test_driver/scroll_perf_test.dart @@ -19,28 +19,38 @@ void main() { driver.close(); }); - test('measure', () async { + Future testScrollPerf(String listKey, String summaryName) async { final Timeline timeline = await driver.traceAction(() async { // Find the scrollable stock list - final SerializableFinder stockList = find.byValueKey('main-scroll'); - expect(stockList, isNotNull); + final SerializableFinder list = find.byValueKey(listKey); + expect(list, isNotNull); // Scroll down for (int i = 0; i < 5; i++) { - await driver.scroll(stockList, 0.0, -300.0, const Duration(milliseconds: 300)); + await driver.scroll(list, 0.0, -300.0, const Duration(milliseconds: 300)); await new Future.delayed(const Duration(milliseconds: 500)); } // Scroll up for (int i = 0; i < 5; i++) { - await driver.scroll(stockList, 0.0, 300.0, const Duration(milliseconds: 300)); + await driver.scroll(list, 0.0, 300.0, const Duration(milliseconds: 300)); await new Future.delayed(const Duration(milliseconds: 500)); } }); final TimelineSummary summary = new TimelineSummary.summarize(timeline); - summary.writeSummaryToFile('complex_layout_scroll_perf', pretty: true); - summary.writeTimelineToFile('complex_layout_scroll_perf', pretty: true); + summary.writeSummaryToFile(summaryName, pretty: true); + summary.writeTimelineToFile(summaryName, pretty: true); + } + + test('complex_layout_scroll_perf', () async { + await testScrollPerf('complex-scroll', 'complex_layout_scroll_perf'); + }); + + test('tiles_scroll_perf', () async { + await driver.tap(find.byTooltip('Open navigation menu')); + await driver.tap(find.byValueKey('scroll-switcher')); + await testScrollPerf('tiles-scroll', 'tiles_scroll_perf'); }); }); }