Unverified Commit ef20f726 authored by Hans Muller's avatar Hans Muller Committed by GitHub

Gallery a11y fix: give the categories and demos pages "route" scope (#17516)

parent 6c8d5f1b
...@@ -109,47 +109,53 @@ class _CategoriesPage extends StatelessWidget { ...@@ -109,47 +109,53 @@ class _CategoriesPage extends StatelessWidget {
final List<GalleryDemoCategory> categoriesList = categories.toList(); final List<GalleryDemoCategory> categoriesList = categories.toList();
final int columnCount = (MediaQuery.of(context).orientation == Orientation.portrait) ? 2 : 3; final int columnCount = (MediaQuery.of(context).orientation == Orientation.portrait) ? 2 : 3;
return new SingleChildScrollView( return new Semantics(
key: const PageStorageKey<String>('categories'), scopesRoute: true,
child: new LayoutBuilder( namesRoute: true,
builder: (BuildContext context, BoxConstraints constraints) { label: 'categories',
final double columnWidth = constraints.biggest.width / columnCount.toDouble(); explicitChildNodes: true,
final double rowHeight = columnWidth * aspectRatio; child: new SingleChildScrollView(
final int rowCount = (categories.length + columnCount - 1) ~/ columnCount; key: const PageStorageKey<String>('categories'),
child: new LayoutBuilder(
// This repaint boundary prevents the inner contents of the front layer builder: (BuildContext context, BoxConstraints constraints) {
// from repainting when the backdrop toggle triggers a repaint on the final double columnWidth = constraints.biggest.width / columnCount.toDouble();
// LayoutBuilder. final double rowHeight = columnWidth * aspectRatio;
return new RepaintBoundary( final int rowCount = (categories.length + columnCount - 1) ~/ columnCount;
child: new Column(
mainAxisSize: MainAxisSize.min, // This repaint boundary prevents the inner contents of the front layer
crossAxisAlignment: CrossAxisAlignment.stretch, // from repainting when the backdrop toggle triggers a repaint on the
children: new List<Widget>.generate(rowCount, (int rowIndex) { // LayoutBuilder.
final int columnCountForRow = rowIndex == rowCount - 1 return new RepaintBoundary(
? categories.length - columnCount * math.max(0, rowCount - 1) child: new Column(
: columnCount; mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.stretch,
return new Row( children: new List<Widget>.generate(rowCount, (int rowIndex) {
children: new List<Widget>.generate(columnCountForRow, (int columnIndex) { final int columnCountForRow = rowIndex == rowCount - 1
final int index = rowIndex * columnCount + columnIndex; ? categories.length - columnCount * math.max(0, rowCount - 1)
final GalleryDemoCategory category = categoriesList[index]; : columnCount;
return new SizedBox( return new Row(
width: columnWidth, children: new List<Widget>.generate(columnCountForRow, (int columnIndex) {
height: rowHeight, final int index = rowIndex * columnCount + columnIndex;
child: new _CategoryItem( final GalleryDemoCategory category = categoriesList[index];
category: category,
onTap: () { return new SizedBox(
onCategoryTap(category); width: columnWidth,
}, height: rowHeight,
), child: new _CategoryItem(
); category: category,
}), onTap: () {
); onCategoryTap(category);
}), },
), ),
); );
}, }),
);
}),
),
);
},
),
), ),
); );
} }
...@@ -240,12 +246,18 @@ class _DemosPage extends StatelessWidget { ...@@ -240,12 +246,18 @@ class _DemosPage extends StatelessWidget {
Widget build(BuildContext context) { Widget build(BuildContext context) {
return new KeyedSubtree( return new KeyedSubtree(
key: const ValueKey<String>('GalleryDemoList'), // So the tests can find this ListView key: const ValueKey<String>('GalleryDemoList'), // So the tests can find this ListView
child: new ListView( child: new Semantics(
key: new PageStorageKey<String>(category.name), scopesRoute: true,
padding: const EdgeInsets.only(top: 8.0), namesRoute: true,
children: kGalleryCategoryToDemos[category].map<Widget>((GalleryDemo demo) { label: category.name,
return new _DemoItem(demo: demo); explicitChildNodes: true,
}).toList(), child: new ListView(
key: new PageStorageKey<String>(category.name),
padding: const EdgeInsets.only(top: 8.0),
children: kGalleryCategoryToDemos[category].map<Widget>((GalleryDemo demo) {
return new _DemoItem(demo: demo);
}).toList(),
),
), ),
); );
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment