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,16 +15,19 @@ void main() {
final BorderRadius borderRadius = new BorderRadius.circular(6.0);
await tester.pumpWidget(
new Material(
child: new Center(
child: new Container(
width: 200.0,
height: 60.0,
child: new InkWell(
borderRadius: borderRadius,
highlightColor: highlightColor,
splashColor: splashColor,
onTap: () { },
new Directionality(
textDirection: TextDirection.ltr,
child: new Material(
child: new Center(
child: new Container(
width: 200.0,
height: 60.0,
child: new InkWell(
borderRadius: borderRadius,
highlightColor: highlightColor,
splashColor: splashColor,
onTap: () { },
),
),
),
),
......@@ -61,18 +64,21 @@ void main() {
final BorderRadius borderRadius = new BorderRadius.circular(6.0);
await tester.pumpWidget(
new Material(
child: new Center(
child: new Container(
width: 100.0,
height: 100.0,
child: new InkWell(
borderRadius: borderRadius,
highlightColor: highlightColor,
splashColor: splashColor,
onTap: () { },
radius: 100.0,
splashFactory: InkRipple.splashFactory,
new Directionality(
textDirection: TextDirection.ltr,
child: new Material(
child: new Center(
child: new Container(
width: 100.0,
height: 100.0,
child: new InkWell(
borderRadius: borderRadius,
highlightColor: highlightColor,
splashColor: splashColor,
onTap: () { },
radius: 100.0,
splashFactory: InkRipple.splashFactory,
),
),
),
),
......@@ -138,15 +144,18 @@ void main() {
testWidgets('Does the Ink widget render anything', (WidgetTester tester) async {
await tester.pumpWidget(
new Material(
child: new Center(
child: new Ink(
color: Colors.blue,
width: 200.0,
height: 200.0,
child: new InkWell(
splashColor: Colors.green,
onTap: () { },
new Directionality(
textDirection: TextDirection.ltr,
child: new Material(
child: new Center(
child: new Ink(
color: Colors.blue,
width: 200.0,
height: 200.0,
child: new InkWell(
splashColor: Colors.green,
onTap: () { },
),
),
),
),
......@@ -167,15 +176,18 @@ void main() {
);
await tester.pumpWidget(
new Material(
child: new Center(
child: new Ink(
color: Colors.red,
width: 200.0,
height: 200.0,
child: new InkWell(
splashColor: Colors.green,
onTap: () { },
new Directionality(
textDirection: TextDirection.ltr,
child: new Material(
child: new Center(
child: new Ink(
color: Colors.red,
width: 200.0,
height: 200.0,
child: new InkWell(
splashColor: Colors.green,
onTap: () { },
),
),
),
),
......@@ -192,11 +204,14 @@ void main() {
);
await tester.pumpWidget(
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,
onTap: () { },
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,
onTap: () { },
),
),
),
),
......@@ -213,15 +228,18 @@ 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(
child: new Center(
child: new Container(
width: 100.0,
height: 100.0,
child: new InkWell(
onTap: () { },
radius: 100.0,
splashFactory: InkRipple.splashFactory,
new Directionality(
textDirection: TextDirection.ltr,
child: new Material(
child: new Center(
child: new Container(
width: 100.0,
height: 100.0,
child: new InkWell(
onTap: () { },
radius: 100.0,
splashFactory: InkRipple.splashFactory,
),
),
),
),
......@@ -246,17 +264,20 @@ void main() {
// Regression test for https://github.com/flutter/flutter/issues/14391
await tester.pumpWidget(
new Material(
child: new Center(
child: new Container(
width: 100.0,
height: 100.0,
child: new InkWell(
splashColor: splashColor,
highlightColor: highlightColor,
onTap: () { },
radius: 100.0,
splashFactory: InkRipple.splashFactory,
new Directionality(
textDirection: TextDirection.ltr,
child: new Material(
child: new Center(
child: new Container(
width: 100.0,
height: 100.0,
child: new InkWell(
splashColor: splashColor,
highlightColor: highlightColor,
onTap: () { },
radius: 100.0,
splashFactory: InkRipple.splashFactory,
),
),
),
),
......
// 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,27 +14,32 @@ void main() {
testWidgets('InkWell gestures control test', (WidgetTester tester) async {
final List<String> log = <String>[];
await tester.pumpWidget(new Material(
child: new Center(
child: new InkWell(
onTap: () {
log.add('tap');
},
onDoubleTap: () {
log.add('double-tap');
},
onLongPress: () {
log.add('long-press');
},
onTapDown: (TapDownDetails details) {
log.add('tap-down');
},
onTapCancel: () {
log.add('tap-cancel');
},
),
),
));
await tester.pumpWidget(
new Directionality(
textDirection: TextDirection.ltr,
child: new Material(
child: new Center(
child: new InkWell(
onTap: () {
log.add('tap');
},
onDoubleTap: () {
log.add('double-tap');
},
onLongPress: () {
log.add('long-press');
},
onTapDown: (TapDownDetails details) {
log.add('tap-down');
},
onTapCancel: () {
log.add('tap-cancel');
},
),
),
)
)
);
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: Center(
child: InkWell(),
),
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,10 +103,13 @@ void main() {
testWidgets('enabled (default)', (WidgetTester tester) async {
await tester.pumpWidget(new Material(
child: new Center(
child: new InkWell(
onTap: () {},
onLongPress: () {},
child: new Directionality(
textDirection: TextDirection.ltr,
child: new Center(
child: new InkWell(
onTap: () {},
onLongPress: () {},
),
),
),
));
......@@ -120,13 +131,16 @@ void main() {
testWidgets('disabled', (WidgetTester tester) async {
await tester.pumpWidget(new Material(
child: new Center(
child: new InkWell(
onTap: () {},
onLongPress: () {},
enableFeedback: false,
child: new Directionality(
textDirection: TextDirection.ltr,
child: new Center(
child: new InkWell(
onTap: () {},
onLongPress: () {},
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(
onPressed: () {
pressed++;
},
constraints: new BoxConstraints.tight(const Size(10.0, 10.0)),
materialTapTargetSize: MaterialTapTargetSize.padded,
child: const Text('+', textDirection: TextDirection.ltr),
));
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('+'),
),
)
);
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(
child: new RawMaterialButton(
onPressed: () {},
constraints: new BoxConstraints.tight(const Size(10.0, 10.0)),
materialTapTargetSize: MaterialTapTargetSize.padded,
child: const Text('+', textDirection: TextDirection.ltr),
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('+'),
),
),
),
);
......@@ -66,14 +74,17 @@ void main() {
const Color fillColor = Color(0xFFEF5350);
await tester.pumpWidget(
new Center(
child: new RawMaterialButton(
materialTapTargetSize: MaterialTapTargetSize.padded,
onPressed: () {},
fillColor: fillColor,
highlightColor: highlightColor,
splashColor: splashColor,
child: const SizedBox(),
new Directionality(
textDirection: TextDirection.ltr,
child: new Center(
child: new RawMaterialButton(
materialTapTargetSize: MaterialTapTargetSize.padded,
onPressed: () {},
fillColor: fillColor,
highlightColor: highlightColor,
splashColor: splashColor,
child: const SizedBox(),
),
),
),
);
......@@ -95,14 +106,17 @@ void main() {
const Color fillColor = Color(0xFFEF5350);
await tester.pumpWidget(
new Center(
child: new RawMaterialButton(
materialTapTargetSize: MaterialTapTargetSize.padded,
onPressed: () {},
fillColor: fillColor,
highlightColor: highlightColor,
splashColor: splashColor,
child: const SizedBox(),
new Directionality(
textDirection: TextDirection.ltr,
child: new Center(
child: new RawMaterialButton(
materialTapTargetSize: MaterialTapTargetSize.padded,
onPressed: () {},
fillColor: fillColor,
highlightColor: highlightColor,
splashColor: splashColor,
child: const SizedBox(),
),
),
),
);
......
......@@ -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(
child: new RaisedButton(
onPressed: () {
runApp(const Center(child: Text('Done', textDirection: TextDirection.ltr)));
},
child: const Text('GO', textDirection: TextDirection.ltr)
new Directionality(
textDirection: TextDirection.ltr,
child: new Material(
child: new RaisedButton(
onPressed: () {
runApp(const Center(child: Text('Done', 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