forked from firka/flutter
[a11y] Re-land Make sure RenderFractionalTranslation updates its semantics after the translation field is set (#49708)
Re-land Make sure RenderFractionalTranslation updates its semantics after the translation field is set
This commit is contained in:
@@ -2472,6 +2472,7 @@ class RenderFractionalTranslation extends RenderProxyBox {
|
||||
return;
|
||||
_translation = value;
|
||||
markNeedsPaint();
|
||||
markNeedsSemanticsUpdate();
|
||||
}
|
||||
|
||||
@override
|
||||
|
||||
@@ -481,6 +481,18 @@ void main() {
|
||||
..onHover = (_) {};
|
||||
// Passes if no error is thrown
|
||||
});
|
||||
|
||||
test('RenderFractionalTranslation updates its semantics after its translation value is set', () {
|
||||
final _TestSemanticsUpdateRenderFractionalTranslation box = _TestSemanticsUpdateRenderFractionalTranslation(
|
||||
translation: const Offset(0.5, 0.5),
|
||||
);
|
||||
layout(box, constraints: BoxConstraints.tight(const Size(200.0, 200.0)));
|
||||
expect(box.markNeedsSemanticsUpdateCallCount, 1);
|
||||
box.translation = const Offset(0.4, 0.4);
|
||||
expect(box.markNeedsSemanticsUpdateCallCount, 2);
|
||||
box.translation = const Offset(0.3, 0.3);
|
||||
expect(box.markNeedsSemanticsUpdateCallCount, 3);
|
||||
});
|
||||
}
|
||||
|
||||
class _TestRectClipper extends CustomClipper<Rect> {
|
||||
@@ -537,3 +549,18 @@ class _TestPathClipper extends CustomClipper<Path> {
|
||||
@override
|
||||
bool shouldReclip(_TestPathClipper oldClipper) => false;
|
||||
}
|
||||
|
||||
class _TestSemanticsUpdateRenderFractionalTranslation extends RenderFractionalTranslation {
|
||||
_TestSemanticsUpdateRenderFractionalTranslation({
|
||||
@required Offset translation,
|
||||
RenderBox child,
|
||||
}) : super(translation: translation, child: child);
|
||||
|
||||
int markNeedsSemanticsUpdateCallCount = 0;
|
||||
|
||||
@override
|
||||
void markNeedsSemanticsUpdate() {
|
||||
markNeedsSemanticsUpdateCallCount++;
|
||||
super.markNeedsSemanticsUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -145,6 +145,69 @@ void main() {
|
||||
await tester.tap(find.byKey(key1));
|
||||
expect(_pointerDown, isTrue);
|
||||
});
|
||||
|
||||
testWidgets('semantics bounds are updated', (WidgetTester tester) async {
|
||||
final GlobalKey fractionalTranslationKey = GlobalKey();
|
||||
final GlobalKey textKey = GlobalKey();
|
||||
Offset offset = const Offset(0.4, 0.4);
|
||||
|
||||
await tester.pumpWidget(
|
||||
StatefulBuilder(
|
||||
builder: (BuildContext context, StateSetter setState) {
|
||||
return Directionality(
|
||||
textDirection: TextDirection.ltr,
|
||||
child: Center(
|
||||
child: Semantics(
|
||||
explicitChildNodes: true,
|
||||
child: FractionalTranslation(
|
||||
key: fractionalTranslationKey,
|
||||
translation: offset,
|
||||
transformHitTests: true,
|
||||
child: GestureDetector(
|
||||
onTap: () {
|
||||
setState(() {
|
||||
offset = const Offset(0.8, 0.8);
|
||||
});
|
||||
},
|
||||
child: SizedBox(
|
||||
width: 100.0,
|
||||
height: 100.0,
|
||||
child: Text(
|
||||
'foo',
|
||||
key: textKey,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
)
|
||||
);
|
||||
|
||||
expect(
|
||||
tester.getSemantics(find.byKey(textKey)).transform,
|
||||
Matrix4(
|
||||
3.0, 0.0, 0.0, 0.0,
|
||||
0.0, 3.0, 0.0, 0.0,
|
||||
0.0, 0.0, 1.0, 0.0,
|
||||
1170.0, 870.0, 0.0, 1.0,
|
||||
),
|
||||
);
|
||||
|
||||
await tester.tap(find.byKey(fractionalTranslationKey));
|
||||
await tester.pump();
|
||||
expect(
|
||||
tester.getSemantics(find.byKey(textKey)).transform,
|
||||
Matrix4(
|
||||
3.0, 0.0, 0.0, 0.0,
|
||||
0.0, 3.0, 0.0, 0.0,
|
||||
0.0, 0.0, 1.0, 0.0,
|
||||
1290.0, 990.0, 0.0, 1.0,
|
||||
),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
group('Row', () {
|
||||
|
||||
Reference in New Issue
Block a user