Commit b944cd71 authored by Stefano Rodriguez's avatar Stefano Rodriguez Committed by Ian Hickson

Plug TextDirection into box_decoration background gradient (#14810)

* Plug TextDirection into box_decoration background gradient

* Add test
parent afabdfec
......@@ -325,7 +325,7 @@ class _BoxDecorationPainter extends BoxPainter {
Paint _cachedBackgroundPaint;
Rect _rectForCachedBackgroundPaint;
Paint _getBackgroundPaint(Rect rect) {
Paint _getBackgroundPaint(Rect rect, TextDirection textDirection) {
assert(rect != null);
assert(_decoration.gradient != null || _rectForCachedBackgroundPaint == null);
......@@ -335,7 +335,7 @@ class _BoxDecorationPainter extends BoxPainter {
if (_decoration.color != null)
paint.color = _decoration.color;
if (_decoration.gradient != null) {
paint.shader = _decoration.gradient.createShader(rect);
paint.shader = _decoration.gradient.createShader(rect, textDirection: textDirection);
_rectForCachedBackgroundPaint = rect;
}
_cachedBackgroundPaint = paint;
......@@ -376,7 +376,7 @@ class _BoxDecorationPainter extends BoxPainter {
void _paintBackgroundColor(Canvas canvas, Rect rect, TextDirection textDirection) {
if (_decoration.color != null || _decoration.gradient != null)
_paintBox(canvas, rect, _getBackgroundPaint(rect), textDirection);
_paintBox(canvas, rect, _getBackgroundPaint(rect, textDirection), textDirection);
}
DecorationImagePainter _imagePainter;
......
......@@ -42,4 +42,30 @@ void main() {
expect(decoration.hitTest(size, const Offset(10.0, 10.0), textDirection: TextDirection.ltr), isFalse);
expect(decoration.hitTest(size, const Offset(990.0, 10.0), textDirection: TextDirection.ltr), isTrue);
});
test('BoxDecoration with LinearGradient using AlignmentDirectional', () {
const BoxDecoration decoration = const BoxDecoration(
color: const Color(0xFF000000),
gradient: const LinearGradient(
begin: AlignmentDirectional.centerStart,
end: AlignmentDirectional.bottomEnd,
colors: const<Color>[
const Color(0xFF000000),
const Color(0xFFFFFFFF),
],
),
);
final BoxPainter painter = decoration.createBoxPainter();
const Size size = const Size(1000.0, 1000.0);
expect(
(Canvas canvas) {
painter.paint(
canvas,
const Offset(0.0, 0.0),
const ImageConfiguration(size: size, textDirection: TextDirection.rtl),
);
},
paints..rect(rect: Offset.zero & size),
);
});
}
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