Commit 7a73ddf5 authored by Michael Goderbauer's avatar Michael Goderbauer Committed by GitHub

Make TabBarView/PageView accessible (#12386)

* Make TabBarView/PageView accessible

* review fedback
parent 517315de
...@@ -290,25 +290,25 @@ abstract class RenderSliverMultiBoxAdaptor extends RenderSliver ...@@ -290,25 +290,25 @@ abstract class RenderSliverMultiBoxAdaptor extends RenderSliver
switch (constraints.normalizedGrowthDirection) { switch (constraints.normalizedGrowthDirection) {
case GrowthDirection.forward: case GrowthDirection.forward:
super.visitChildrenForSemantics((RenderObject child) { super.visitChildrenForSemantics((RenderObject child) {
// The sliver is overlapped at the leading edge. // The sliver is overlapped at the leading edge; check if trailing edge is visible.
final Offset bottomLeftInViewport = MatrixUtils.transformPoint( final Offset bottomRightInViewport = MatrixUtils.transformPoint(
child.getTransformTo(parent), child.semanticBounds.bottomLeft child.getTransformTo(parent), child.semanticBounds.bottomRight
); );
final double endOverlap = constraints.overlap; final double endOverlap = constraints.overlap;
if ((constraints.axis == Axis.vertical && bottomLeftInViewport.dy > endOverlap) || if ((constraints.axis == Axis.vertical && bottomRightInViewport.dy > endOverlap) ||
(constraints.axis == Axis.horizontal && bottomLeftInViewport.dx > endOverlap)) (constraints.axis == Axis.horizontal && bottomRightInViewport.dx > endOverlap))
visitor(child); visitor(child);
}); });
break; break;
case GrowthDirection.reverse: case GrowthDirection.reverse:
super.visitChildrenForSemantics((RenderObject child) { super.visitChildrenForSemantics((RenderObject child) {
// The sliver is overlapped at the trailing edge. // The sliver is overlapped at the trailing edge; check if leading edge is visible.
final Offset topRightInViewport = MatrixUtils.transformPoint( final Offset topLeftInViewport = MatrixUtils.transformPoint(
child.getTransformTo(parent), child.semanticBounds.topRight child.getTransformTo(parent), child.semanticBounds.topLeft
); );
final double startOverlap = constraints.remainingPaintExtent - constraints.overlap; final double startOverlap = constraints.remainingPaintExtent - constraints.overlap;
if ((constraints.axis == Axis.vertical && topRightInViewport.dy < startOverlap) || if ((constraints.axis == Axis.vertical && topLeftInViewport.dy < startOverlap) ||
(constraints.axis == Axis.horizontal && topRightInViewport.dx < startOverlap)) (constraints.axis == Axis.horizontal && topLeftInViewport.dx < startOverlap))
visitor(child); visitor(child);
}); });
break; break;
......
...@@ -4,8 +4,10 @@ ...@@ -4,8 +4,10 @@
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter/widgets.dart'; import 'package:flutter/widgets.dart';
import 'semantics_tester.dart';
import 'states.dart'; import 'states.dart';
const Duration _frameDuration = const Duration(milliseconds: 100); const Duration _frameDuration = const Duration(milliseconds: 100);
...@@ -505,4 +507,43 @@ void main() { ...@@ -505,4 +507,43 @@ void main() {
)); ));
expect(controller2.page, 0); expect(controller2.page, 0);
}); });
testWidgets('PageView exposes semantics of children', (WidgetTester tester) async {
final SemanticsTester semantics = new SemanticsTester(tester);
final PageController controller = new PageController();
await tester.pumpWidget(new Directionality(
textDirection: TextDirection.ltr,
child: new PageView(
controller: controller,
children: new List<Widget>.generate(3, (int i) {
return new Semantics(
child: new Text('Page #$i'),
container: true,
);
})
),
));
expect(controller.page, 0);
expect(semantics, includesNodeWith(label: 'Page #0'));
expect(semantics, isNot(includesNodeWith(label: 'Page #1')));
expect(semantics, isNot(includesNodeWith(label: 'Page #2')));
controller.jumpToPage(1);
await tester.pumpAndSettle();
expect(semantics, isNot(includesNodeWith(label: 'Page #0')));
expect(semantics, includesNodeWith(label: 'Page #1'));
expect(semantics, isNot(includesNodeWith(label: 'Page #2')));
controller.jumpToPage(2);
await tester.pumpAndSettle();
expect(semantics, isNot(includesNodeWith(label: 'Page #0')));
expect(semantics, isNot(includesNodeWith(label: 'Page #1')));
expect(semantics, includesNodeWith(label: 'Page #2'));
semantics.dispose();
});
} }
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