Place the transform and its children within the RenderFlow's opacity layer (#15543)
Fixes https://github.com/flutter/flutter/issues/15037
This commit is contained in:
parent
340c68038a
commit
95fbd819fa
@ -342,7 +342,7 @@ class RenderFlow extends RenderBox
|
||||
_paintingContext.pushTransform(needsCompositing, _paintingOffset, transform, painter);
|
||||
} else {
|
||||
_paintingContext.pushOpacity(_paintingOffset, _getAlphaFromOpacity(opacity), (PaintingContext context, Offset offset) {
|
||||
_paintingContext.pushTransform(needsCompositing, offset, transform, painter);
|
||||
context.pushTransform(needsCompositing, offset, transform, painter);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -4,6 +4,7 @@
|
||||
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:flutter/rendering.dart';
|
||||
|
||||
class TestFlowDelegate extends FlowDelegate {
|
||||
TestFlowDelegate({this.startOffset}) : super(repaint: startOffset);
|
||||
@ -28,6 +29,22 @@ class TestFlowDelegate extends FlowDelegate {
|
||||
bool shouldRepaint(TestFlowDelegate oldDelegate) => startOffset == oldDelegate.startOffset;
|
||||
}
|
||||
|
||||
class OpacityFlowDelegate extends FlowDelegate {
|
||||
OpacityFlowDelegate(this.opacity);
|
||||
|
||||
double opacity;
|
||||
|
||||
@override
|
||||
void paintChildren(FlowPaintingContext context) {
|
||||
for (int i = 0; i < context.childCount; ++i) {
|
||||
context.paintChild(i, opacity: opacity);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
bool shouldRepaint(OpacityFlowDelegate oldDelegate) => opacity != oldDelegate.opacity;
|
||||
}
|
||||
|
||||
void main() {
|
||||
testWidgets('Flow control test', (WidgetTester tester) async {
|
||||
final AnimationController startOffset = new AnimationController.unbounded(
|
||||
@ -82,4 +99,23 @@ void main() {
|
||||
await tester.tapAt(const Offset(20.0, 90.0));
|
||||
expect(log, equals(<int>[0]));
|
||||
});
|
||||
|
||||
testWidgets('Flow opacity layer', (WidgetTester tester) async {
|
||||
const double opacity = 0.2;
|
||||
await tester.pumpWidget(
|
||||
new Flow(
|
||||
delegate: new OpacityFlowDelegate(opacity),
|
||||
children: <Widget>[
|
||||
new Container(width: 100.0, height: 100.0),
|
||||
]
|
||||
)
|
||||
);
|
||||
ContainerLayer layer = RendererBinding.instance.renderView.debugLayer;
|
||||
while (layer != null && !(layer is OpacityLayer))
|
||||
layer = layer.firstChild;
|
||||
expect(layer, const isInstanceOf<OpacityLayer>());
|
||||
final OpacityLayer opacityLayer = layer;
|
||||
expect(opacityLayer.alpha, equals(opacity * 255));
|
||||
expect(layer.firstChild, const isInstanceOf<TransformLayer>());
|
||||
});
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user