Unverified Commit 3821c35d authored by Jonah Williams's avatar Jonah Williams Committed by GitHub

Ensure that textDirection is always passed to ShapeBorder.getOuterPath (#21532)

parent 9a290c17
......@@ -39,6 +39,7 @@ class InkHighlight extends InteractiveInkFeature {
@required MaterialInkController controller,
@required RenderBox referenceBox,
@required Color color,
@required TextDirection textDirection,
BoxShape shape = BoxShape.rectangle,
BorderRadius borderRadius,
ShapeBorder customBorder,
......@@ -46,9 +47,11 @@ class InkHighlight extends InteractiveInkFeature {
VoidCallback onRemoved,
}) : assert(color != null),
assert(shape != null),
assert(textDirection != null),
_shape = shape,
_borderRadius = borderRadius ?? BorderRadius.zero,
_customBorder = customBorder,
_textDirection = textDirection,
_rectCallback = rectCallback,
super(controller: controller, referenceBox: referenceBox, color: color, onRemoved: onRemoved) {
_alphaController = new AnimationController(duration: _kHighlightFadeDuration, vsync: controller.vsync)
......@@ -67,6 +70,7 @@ class InkHighlight extends InteractiveInkFeature {
final BorderRadius _borderRadius;
final ShapeBorder _customBorder;
final RectCallback _rectCallback;
final TextDirection _textDirection;
Animation<int> _alpha;
AnimationController _alphaController;
......@@ -102,7 +106,7 @@ class InkHighlight extends InteractiveInkFeature {
assert(_shape != null);
canvas.save();
if (_customBorder != null) {
canvas.clipPath(_customBorder.getOuterPath(rect));
canvas.clipPath(_customBorder.getOuterPath(rect, textDirection: _textDirection));
}
switch (_shape) {
case BoxShape.circle:
......
......@@ -45,6 +45,7 @@ class _InkRippleFactory extends InteractiveInkFeatureFactory {
@required RenderBox referenceBox,
@required Offset position,
@required Color color,
@required TextDirection textDirection,
bool containedInkWell = false,
RectCallback rectCallback,
BorderRadius borderRadius,
......@@ -63,6 +64,7 @@ class _InkRippleFactory extends InteractiveInkFeatureFactory {
customBorder: customBorder,
radius: radius,
onRemoved: onRemoved,
textDirection: textDirection,
);
}
}
......@@ -114,6 +116,7 @@ class InkRipple extends InteractiveInkFeature {
@required RenderBox referenceBox,
@required Offset position,
@required Color color,
@required TextDirection textDirection,
bool containedInkWell = false,
RectCallback rectCallback,
BorderRadius borderRadius,
......@@ -122,9 +125,11 @@ class InkRipple extends InteractiveInkFeature {
VoidCallback onRemoved,
}) : assert(color != null),
assert(position != null),
assert(textDirection != null),
_position = position,
_borderRadius = borderRadius ?? BorderRadius.zero,
_customBorder = customBorder,
_textDirection = textDirection,
_targetRadius = radius ?? _getTargetRadius(referenceBox, containedInkWell, rectCallback, position),
_clipCallback = _getClipCallback(referenceBox, containedInkWell, rectCallback),
super(controller: controller, referenceBox: referenceBox, color: color, onRemoved: onRemoved)
......@@ -179,6 +184,7 @@ class InkRipple extends InteractiveInkFeature {
final ShapeBorder _customBorder;
final double _targetRadius;
final RectCallback _clipCallback;
final TextDirection _textDirection;
Animation<double> _radius;
AnimationController _radiusController;
......@@ -245,7 +251,7 @@ class InkRipple extends InteractiveInkFeature {
if (_clipCallback != null) {
final Rect rect = _clipCallback();
if (_customBorder != null) {
canvas.clipPath(_customBorder.getOuterPath(rect));
canvas.clipPath(_customBorder.getOuterPath(rect, textDirection: _textDirection));
} else if (_borderRadius != BorderRadius.zero) {
canvas.clipRRect(new RRect.fromRectAndCorners(
rect,
......
......@@ -51,6 +51,7 @@ class _InkSplashFactory extends InteractiveInkFeatureFactory {
@required RenderBox referenceBox,
@required Offset position,
@required Color color,
@required TextDirection textDirection,
bool containedInkWell = false,
RectCallback rectCallback,
BorderRadius borderRadius,
......@@ -69,6 +70,7 @@ class _InkSplashFactory extends InteractiveInkFeatureFactory {
customBorder: customBorder,
radius: radius,
onRemoved: onRemoved,
textDirection: textDirection,
);
}
}
......@@ -116,6 +118,7 @@ class InkSplash extends InteractiveInkFeature {
InkSplash({
@required MaterialInkController controller,
@required RenderBox referenceBox,
@required TextDirection textDirection,
Offset position,
Color color,
bool containedInkWell = false,
......@@ -124,12 +127,14 @@ class InkSplash extends InteractiveInkFeature {
ShapeBorder customBorder,
double radius,
VoidCallback onRemoved,
}) : _position = position,
}) : assert(textDirection != null),
_position = position,
_borderRadius = borderRadius ?? BorderRadius.zero,
_customBorder = customBorder,
_targetRadius = radius ?? _getTargetRadius(referenceBox, containedInkWell, rectCallback, position),
_clipCallback = _getClipCallback(referenceBox, containedInkWell, rectCallback),
_repositionToReferenceBox = !containedInkWell,
_textDirection = textDirection,
super(controller: controller, referenceBox: referenceBox, color: color, onRemoved: onRemoved) {
assert(_borderRadius != null);
_radiusController = new AnimationController(duration: _kUnconfirmedSplashDuration, vsync: controller.vsync)
......@@ -156,6 +161,7 @@ class InkSplash extends InteractiveInkFeature {
final double _targetRadius;
final RectCallback _clipCallback;
final bool _repositionToReferenceBox;
final TextDirection _textDirection;
Animation<double> _radius;
AnimationController _radiusController;
......@@ -206,7 +212,7 @@ class InkSplash extends InteractiveInkFeature {
if (_clipCallback != null) {
final Rect rect = _clipCallback();
if (_customBorder != null) {
canvas.clipPath(_customBorder.getOuterPath(rect));
canvas.clipPath(_customBorder.getOuterPath(rect, textDirection: _textDirection));
} else if (_borderRadius != BorderRadius.zero) {
canvas.clipRRect(new RRect.fromRectAndCorners(
rect,
......
......@@ -92,6 +92,7 @@ abstract class InteractiveInkFeatureFactory {
@required RenderBox referenceBox,
@required Offset position,
@required Color color,
@required TextDirection textDirection,
bool containedInkWell = false,
RectCallback rectCallback,
BorderRadius borderRadius,
......@@ -372,6 +373,7 @@ class InkResponse extends StatefulWidget {
@mustCallSuper
bool debugCheckContext(BuildContext context) {
assert(debugCheckHasMaterial(context));
assert(debugCheckHasDirectionality(context));
return true;
}
......@@ -426,6 +428,7 @@ class _InkResponseState<T extends InkResponse> extends State<T> with AutomaticKe
customBorder: widget.customBorder,
rectCallback: widget.getRectCallback(referenceBox),
onRemoved: _handleInkHighlightRemoval,
textDirection: Directionality.of(context),
);
updateKeepAlive();
} else {
......@@ -476,6 +479,7 @@ class _InkResponseState<T extends InkResponse> extends State<T> with AutomaticKe
borderRadius: borderRadius,
customBorder: customBorder,
onRemoved: onRemoved,
textDirection: Directionality.of(context),
);
return splash;
......
......@@ -497,7 +497,7 @@ class _OutlineBorder extends ShapeBorder {
case BorderStyle.none:
break;
case BorderStyle.solid:
canvas.drawPath(shape.getOuterPath(rect), side.toPaint());
canvas.drawPath(shape.getOuterPath(rect, textDirection: textDirection), side.toPaint());
}
}
......
......@@ -473,6 +473,7 @@ class _TextFieldState extends State<TextField> with AutomaticKeepAliveClientMixi
// TODO(hansmuller): splash clip borderRadius should match the input decorator's border.
borderRadius: BorderRadius.zero,
onRemoved: handleRemoved,
textDirection: Directionality.of(context),
);
return splash;
......@@ -539,6 +540,7 @@ class _TextFieldState extends State<TextField> with AutomaticKeepAliveClientMixi
Widget build(BuildContext context) {
super.build(context); // See AutomaticKeepAliveClientMixin.
assert(debugCheckHasMaterial(context));
assert(debugCheckHasDirectionality(context));
final ThemeData themeData = Theme.of(context);
final TextStyle style = widget.style ?? themeData.textTheme.subhead;
final Brightness keyboardAppearance = widget.keyboardAppearance ?? themeData.primaryColorBrightness;
......
......@@ -15,7 +15,9 @@ void main() {
final BorderRadius borderRadius = new BorderRadius.circular(6.0);
await tester.pumpWidget(
new Material(
new Directionality(
textDirection: TextDirection.ltr,
child: new Material(
child: new Center(
child: new Container(
width: 200.0,
......@@ -29,6 +31,7 @@ void main() {
),
),
),
),
);
final Offset center = tester.getCenter(find.byType(InkWell));
......@@ -61,7 +64,9 @@ void main() {
final BorderRadius borderRadius = new BorderRadius.circular(6.0);
await tester.pumpWidget(
new Material(
new Directionality(
textDirection: TextDirection.ltr,
child: new Material(
child: new Center(
child: new Container(
width: 100.0,
......@@ -77,6 +82,7 @@ void main() {
),
),
),
),
);
final Offset tapDownOffset = tester.getTopLeft(find.byType(InkWell));
......@@ -138,7 +144,9 @@ void main() {
testWidgets('Does the Ink widget render anything', (WidgetTester tester) async {
await tester.pumpWidget(
new Material(
new Directionality(
textDirection: TextDirection.ltr,
child: new Material(
child: new Center(
child: new Ink(
color: Colors.blue,
......@@ -151,6 +159,7 @@ void main() {
),
),
),
),
);
final Offset center = tester.getCenter(find.byType(InkWell));
......@@ -167,7 +176,9 @@ void main() {
);
await tester.pumpWidget(
new Material(
new Directionality(
textDirection: TextDirection.ltr,
child: new Material(
child: new Center(
child: new Ink(
color: Colors.red,
......@@ -180,6 +191,7 @@ void main() {
),
),
),
),
);
expect(Material.of(tester.element(find.byType(InkWell))), same(box));
......@@ -192,7 +204,9 @@ void main() {
);
await tester.pumpWidget(
new Material(
new Directionality(
textDirection: TextDirection.ltr,
child: new Material(
child: new Center(
child: new InkWell( // this is at a different depth in the tree so it's now a new InkWell
splashColor: Colors.green,
......@@ -200,6 +214,7 @@ void main() {
),
),
),
),
);
expect(Material.of(tester.element(find.byType(InkWell))), same(box));
......@@ -213,7 +228,9 @@ void main() {
testWidgets('Cancel an InkRipple that was disposed when its animation ended', (WidgetTester tester) async {
// Regression test for https://github.com/flutter/flutter/issues/14391
await tester.pumpWidget(
new Material(
new Directionality(
textDirection: TextDirection.ltr,
child: new Material(
child: new Center(
child: new Container(
width: 100.0,
......@@ -226,6 +243,7 @@ void main() {
),
),
),
),
);
final Offset tapDownOffset = tester.getTopLeft(find.byType(InkWell));
......@@ -246,7 +264,9 @@ void main() {
// Regression test for https://github.com/flutter/flutter/issues/14391
await tester.pumpWidget(
new Material(
new Directionality(
textDirection: TextDirection.ltr,
child: new Material(
child: new Center(
child: new Container(
width: 100.0,
......@@ -261,6 +281,7 @@ void main() {
),
),
),
),
);
final Offset tapDownOffset = tester.getTopLeft(find.byType(InkWell));
......
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
void main() {
// Regression test for https://github.com/flutter/flutter/issues/21506.
testWidgets('InkSplash receives textDirection', (WidgetTester tester) async {
await tester.pumpWidget(new MaterialApp(
home: new Scaffold(
appBar: new AppBar(title: const Text('Button Border Test')),
body: new Center(
child: new RaisedButton(
child: const Text('Test'),
onPressed: () {},
shape: new Border.all(
color: Colors.blue,
),
),
),
)));
await tester.tap(find.text('Test'));
// start ink animation which asserts for a textDirection.
await tester.pumpAndSettle(const Duration(milliseconds: 30));
expect(tester.takeException(), isNull);
});
}
......@@ -14,7 +14,10 @@ void main() {
testWidgets('InkWell gestures control test', (WidgetTester tester) async {
final List<String> log = <String>[];
await tester.pumpWidget(new Material(
await tester.pumpWidget(
new Directionality(
textDirection: TextDirection.ltr,
child: new Material(
child: new Center(
child: new InkWell(
onTap: () {
......@@ -34,7 +37,9 @@ void main() {
},
),
),
));
)
)
);
await tester.tap(find.byType(InkWell), pointer: 1);
......@@ -72,9 +77,12 @@ void main() {
testWidgets('long-press and tap on disabled should not throw', (WidgetTester tester) async {
await tester.pumpWidget(const Material(
child: Directionality(
textDirection: TextDirection.ltr,
child: Center(
child: InkWell(),
),
)
));
await tester.tap(find.byType(InkWell), pointer: 1);
await tester.pump(const Duration(seconds: 1));
......@@ -95,12 +103,15 @@ void main() {
testWidgets('enabled (default)', (WidgetTester tester) async {
await tester.pumpWidget(new Material(
child: new Directionality(
textDirection: TextDirection.ltr,
child: new Center(
child: new InkWell(
onTap: () {},
onLongPress: () {},
),
),
),
));
await tester.tap(find.byType(InkWell), pointer: 1);
await tester.pump(const Duration(seconds: 1));
......@@ -120,6 +131,8 @@ void main() {
testWidgets('disabled', (WidgetTester tester) async {
await tester.pumpWidget(new Material(
child: new Directionality(
textDirection: TextDirection.ltr,
child: new Center(
child: new InkWell(
onTap: () {},
......@@ -127,6 +140,7 @@ void main() {
enableFeedback: false,
),
),
)
));
await tester.tap(find.byType(InkWell), pointer: 1);
await tester.pump(const Duration(seconds: 1));
......
......@@ -9,14 +9,19 @@ void main() {
testWidgets('materialTapTargetSize.padded expands hit test area', (WidgetTester tester) async {
int pressed = 0;
await tester.pumpWidget(new RawMaterialButton(
await tester.pumpWidget(
new Directionality(
textDirection: TextDirection.ltr,
child: new RawMaterialButton(
onPressed: () {
pressed++;
},
constraints: new BoxConstraints.tight(const Size(10.0, 10.0)),
materialTapTargetSize: MaterialTapTargetSize.padded,
child: const Text('+', textDirection: TextDirection.ltr),
));
child: const Text('+'),
),
)
);
await tester.tapAt(const Offset(40.0, 400.0));
......@@ -26,12 +31,15 @@ void main() {
testWidgets('materialTapTargetSize.padded expands semantics area', (WidgetTester tester) async {
final SemanticsTester semantics = new SemanticsTester(tester);
await tester.pumpWidget(
new Center(
new Directionality(
textDirection: TextDirection.ltr,
child: new Center(
child: new RawMaterialButton(
onPressed: () {},
constraints: new BoxConstraints.tight(const Size(10.0, 10.0)),
materialTapTargetSize: MaterialTapTargetSize.padded,
child: const Text('+', textDirection: TextDirection.ltr),
child: const Text('+'),
),
),
),
);
......@@ -66,7 +74,9 @@ void main() {
const Color fillColor = Color(0xFFEF5350);
await tester.pumpWidget(
new Center(
new Directionality(
textDirection: TextDirection.ltr,
child: new Center(
child: new RawMaterialButton(
materialTapTargetSize: MaterialTapTargetSize.padded,
onPressed: () {},
......@@ -76,6 +86,7 @@ void main() {
child: const SizedBox(),
),
),
),
);
final Offset center = tester.getCenter(find.byType(InkWell));
......@@ -95,7 +106,9 @@ void main() {
const Color fillColor = Color(0xFFEF5350);
await tester.pumpWidget(
new Center(
new Directionality(
textDirection: TextDirection.ltr,
child: new Center(
child: new RawMaterialButton(
materialTapTargetSize: MaterialTapTargetSize.padded,
onPressed: () {},
......@@ -105,6 +118,7 @@ void main() {
child: const SizedBox(),
),
),
),
);
final Offset top = tester.getRect(find.byType(InkWell)).topCenter;
......
......@@ -22,6 +22,7 @@ class TestInkSplash extends InkSplash {
ShapeBorder customBorder,
double radius,
VoidCallback onRemoved,
TextDirection textDirection
}) : super(
controller: controller,
referenceBox: referenceBox,
......@@ -33,6 +34,7 @@ class TestInkSplash extends InkSplash {
customBorder: customBorder,
radius: radius,
onRemoved: onRemoved,
textDirection: textDirection,
);
@override
......@@ -63,6 +65,7 @@ class TestInkSplashFactory extends InteractiveInkFeatureFactory {
ShapeBorder customBorder,
double radius,
VoidCallback onRemoved,
TextDirection textDirection,
}) {
return new TestInkSplash(
controller: controller,
......@@ -75,6 +78,7 @@ class TestInkSplashFactory extends InteractiveInkFeatureFactory {
customBorder: customBorder,
radius: radius,
onRemoved: onRemoved,
textDirection: textDirection,
);
}
}
......
......@@ -8,12 +8,15 @@ import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('runApp inside onPressed does not throw', (WidgetTester tester) async {
await tester.pumpWidget(
new Material(
new Directionality(
textDirection: TextDirection.ltr,
child: new Material(
child: new RaisedButton(
onPressed: () {
runApp(const Center(child: Text('Done', textDirection: TextDirection.ltr)));
runApp(const Center(child: Text('Done', textDirection: TextDirection.ltr,)));
},
child: const Text('GO', textDirection: TextDirection.ltr)
child: const Text('GO')
)
)
)
);
......
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