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
switch (constraints.normalizedGrowthDirection) {
case GrowthDirection.forward:
super.visitChildrenForSemantics((RenderObject child) {
// The sliver is overlapped at the leading edge.
final Offset bottomLeftInViewport = MatrixUtils.transformPoint(
child.getTransformTo(parent), child.semanticBounds.bottomLeft
// The sliver is overlapped at the leading edge; check if trailing edge is visible.
final Offset bottomRightInViewport = MatrixUtils.transformPoint(
child.getTransformTo(parent), child.semanticBounds.bottomRight
);
final double endOverlap = constraints.overlap;
if ((constraints.axis == Axis.vertical && bottomLeftInViewport.dy > endOverlap) ||
(constraints.axis == Axis.horizontal && bottomLeftInViewport.dx > endOverlap))
if ((constraints.axis == Axis.vertical && bottomRightInViewport.dy > endOverlap) ||
(constraints.axis == Axis.horizontal && bottomRightInViewport.dx > endOverlap))
visitor(child);
});
break;
case GrowthDirection.reverse:
super.visitChildrenForSemantics((RenderObject child) {
// The sliver is overlapped at the trailing edge.
final Offset topRightInViewport = MatrixUtils.transformPoint(
child.getTransformTo(parent), child.semanticBounds.topRight
// The sliver is overlapped at the trailing edge; check if leading edge is visible.
final Offset topLeftInViewport = MatrixUtils.transformPoint(
child.getTransformTo(parent), child.semanticBounds.topLeft
);
final double startOverlap = constraints.remainingPaintExtent - constraints.overlap;
if ((constraints.axis == Axis.vertical && topRightInViewport.dy < startOverlap) ||
(constraints.axis == Axis.horizontal && topRightInViewport.dx < startOverlap))
if ((constraints.axis == Axis.vertical && topLeftInViewport.dy < startOverlap) ||
(constraints.axis == Axis.horizontal && topLeftInViewport.dx < startOverlap))
visitor(child);
});
break;
......
......@@ -4,8 +4,10 @@
import 'package:flutter_test/flutter_test.dart';
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter/widgets.dart';
import 'semantics_tester.dart';
import 'states.dart';
const Duration _frameDuration = const Duration(milliseconds: 100);
......@@ -505,4 +507,43 @@ void main() {
));
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