Unverified Commit 1bdbfe7b authored by xster's avatar xster Committed by GitHub

Fix SliverPadding dropping the chain on scrollOffsetCorrection propagation (#14789)

* Fix SliverPadding dropping the chain on scrollOffsetCorrection propagation

* review doc
parent 62addedc
...@@ -520,6 +520,10 @@ class SliverGeometry extends Diagnosticable { ...@@ -520,6 +520,10 @@ class SliverGeometry extends Diagnosticable {
/// If this is non-zero after [RenderSliver.performLayout] returns, the scroll /// If this is non-zero after [RenderSliver.performLayout] returns, the scroll
/// offset will be adjusted by the parent and then the entire layout of the /// offset will be adjusted by the parent and then the entire layout of the
/// parent will be rerun. /// parent will be rerun.
///
/// If the parent is also a [RenderSliver], it must propagate this value
/// in its own [RenderSliver.geometry] property until a viewport which adjusts
/// its offset based on this value.
final double scrollOffsetCorrection; final double scrollOffsetCorrection;
/// Asserts that this geometry is internally consistent. /// Asserts that this geometry is internally consistent.
......
...@@ -189,6 +189,12 @@ class RenderSliverPadding extends RenderSliver with RenderObjectWithChildMixin<R ...@@ -189,6 +189,12 @@ class RenderSliverPadding extends RenderSliver with RenderObjectWithChildMixin<R
parentUsesSize: true, parentUsesSize: true,
); );
final SliverGeometry childLayoutGeometry = child.geometry; final SliverGeometry childLayoutGeometry = child.geometry;
if (childLayoutGeometry.scrollOffsetCorrection != null) {
geometry = new SliverGeometry(
scrollOffsetCorrection: childLayoutGeometry.scrollOffsetCorrection,
);
return;
}
final double beforePaddingPaintExtent = calculatePaintOffset( final double beforePaddingPaintExtent = calculatePaintOffset(
constraints, constraints,
from: 0.0, from: 0.0,
......
...@@ -357,4 +357,69 @@ void main() { ...@@ -357,4 +357,69 @@ void main() {
); );
expect(tester.renderObject<RenderSliverPadding>(find.byType(SliverPadding)).afterPadding, 1.0); expect(tester.renderObject<RenderSliverPadding>(find.byType(SliverPadding)).afterPadding, 1.0);
}); });
testWidgets('SliverPadding propagates geometry offset corrections', (WidgetTester tester) async {
Widget listBuilder(IndexedWidgetBuilder sliverChildBuilder) {
return new Directionality(
textDirection: TextDirection.ltr,
child: new CustomScrollView(
slivers: <Widget>[
new SliverPadding(
padding: EdgeInsets.zero,
sliver: new SliverList(
delegate: new SliverChildBuilderDelegate(
sliverChildBuilder,
childCount: 10,
),
),
),
],
),
);
}
await tester.pumpWidget(
listBuilder(
(BuildContext context, int index) {
return new Container(
height: 200.0,
child: new Center(
child: new Text(index.toString()),
),
);
},
),
);
await tester.drag(find.text('2'), const Offset(0.0, -300.0));
await tester.pump();
expect(
tester.getRect(find.widgetWithText(Container, '2')),
new Rect.fromLTRB(0.0, 100.0, 800.0, 300.0),
);
// Now item 0 is 400.0px and going back will underflow.
await tester.pumpWidget(
listBuilder(
(BuildContext context, int index) {
return new Container(
height: index == 0 ? 400.0 : 200.0,
child: new Center(
child: new Text(index.toString()),
),
);
},
),
);
await tester.drag(find.text('2'), const Offset(0.0, 300.0));
// On this one frame, the scroll correction must properly propagate.
await tester.pump();
expect(
tester.getRect(find.widgetWithText(Container, '0')),
new Rect.fromLTRB(0.0, -200.0, 800.0, 200.0),
);
});
} }
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