Unverified Commit c9312c78 authored by Kate Lovett's avatar Kate Lovett Committed by GitHub

Fix stretch edge case (#99365)

parent 9c521b90
......@@ -359,7 +359,7 @@ abstract class RenderSliverScrollingPersistentHeader extends RenderSliverPersist
@protected
double updateGeometry() {
double stretchOffset = 0.0;
if (stretchConfiguration != null && _childPosition == 0.0) {
if (stretchConfiguration != null) {
stretchOffset += constraints.overlap.abs();
}
final double maxExtent = this.maxExtent;
......@@ -596,7 +596,7 @@ abstract class RenderSliverFloatingPersistentHeader extends RenderSliverPersiste
@protected
double updateGeometry() {
double stretchOffset = 0.0;
if (stretchConfiguration != null && _childPosition == 0.0) {
if (stretchConfiguration != null) {
stretchOffset += constraints.overlap.abs();
}
final double maxExtent = this.maxExtent;
......
......@@ -43,6 +43,105 @@ void main() {
expect(header.child!.size.height, equals(200.0));
});
testWidgets('fills overscroll after reverse direction input - scrolling header', (WidgetTester tester) async {
const Key anchor = Key('drag');
await tester.pumpWidget(
MaterialApp(
home: CustomScrollView(
physics: const BouncingScrollPhysics(),
slivers: <Widget>[
const SliverAppBar(
title: Text('Test'),
stretch: true,
expandedHeight: 100.0,
),
SliverToBoxAdapter(
child: Container(
key: anchor,
height: 800,
),
),
SliverToBoxAdapter(
child: Container(
height: 800,
),
),
],
),
),
);
final RenderSliverScrollingPersistentHeader header = tester.renderObject(
find.byType(SliverAppBar),
);
expect(header.child!.size.height, equals(100.0));
expect(tester.getCenter(find.text('Test')).dy, 28.0);
// First scroll the header away
final TestGesture gesture = await tester.startGesture(tester.getCenter(find.byKey(anchor)));
await gesture.moveBy(const Offset(0.0, -100.0));
await tester.pump(const Duration(milliseconds: 10));
expect(header.child!.size.height, equals(56.0));
expect(tester.getCenter(find.text('Test', skipOffstage: false)).dy, -28.0);
// With the same gesture, scroll back and into overscroll
await gesture.moveBy(const Offset(0.0, 200.0));
await tester.pump(const Duration(milliseconds: 10));
// Header should stretch in overscroll
expect(header.child!.size.height, equals(200.0));
expect(tester.getCenter(find.text('Test')).dy, 28.0);
await gesture.up();
await tester.pumpAndSettle();
});
testWidgets('fills overscroll after reverse direction input - floating header', (WidgetTester tester) async {
const Key anchor = Key('drag');
await tester.pumpWidget(
MaterialApp(
home: CustomScrollView(
physics: const BouncingScrollPhysics(),
slivers: <Widget>[
const SliverAppBar(
title: Text('Test'),
stretch: true,
floating: true,
expandedHeight: 100.0,
),
SliverToBoxAdapter(
child: Container(
key: anchor,
height: 800,
),
),
SliverToBoxAdapter(
child: Container(
height: 800,
),
),
],
),
),
);
final RenderSliverFloatingPersistentHeader header = tester.renderObject(
find.byType(SliverAppBar),
);
expect(header.child!.size.height, equals(100.0));
expect(tester.getCenter(find.text('Test')).dy, 28.0);
// First scroll the header away
final TestGesture gesture = await tester.startGesture(tester.getCenter(find.byKey(anchor)));
await gesture.moveBy(const Offset(0.0, -100.0));
await tester.pump(const Duration(milliseconds: 10));
expect(header.child!.size.height, equals(56.0));
expect(tester.getCenter(find.text('Test', skipOffstage: false)).dy, -28.0);
// With the same gesture, scroll back and into overscroll
await gesture.moveBy(const Offset(0.0, 200.0));
await tester.pump(const Duration(milliseconds: 10));
// Header should stretch in overscroll
expect(header.child!.size.height, equals(200.0));
expect(tester.getCenter(find.text('Test')).dy, 28.0);
await gesture.up();
await tester.pumpAndSettle();
});
testWidgets('does not stretch without overscroll physics', (WidgetTester tester) async {
const Key anchor = Key('drag');
await tester.pumpWidget(
......
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