Set SliverResizingHeader's maxScrollObstructionExtent to minExtent (#162955)
The maxScrollObstructionExtent of a Sliver denotes the "maximum extent by which this sliver can reduce the area in which content can scroll if the sliver were pinned at the edge.". See also the rest of the documentation of this field. In the case of SliverResizingHeader, like with SliverPersistentHeader, we expect this value to be minExtent. A use case is provided in the referenced issue. Fixes #162661. ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [x] I signed the [CLA]. - [x] I listed at least one issue that this PR fixes in the description above. - [ ] I updated/added relevant documentation (doc comments with `///`). - [x] I added new tests to check the change I am making, or this PR is [test-exempt]. - [ ] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [ ] All existing and new tests are passing. If you need help, consider asking for advice on the #hackers-new channel on [Discord]. <!-- Links --> [Contributor Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview [Tree Hygiene]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md [test-exempt]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests [Flutter Style Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md [Features we expect every widget to implement]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [breaking change policy]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md [Data Driven Fixes]: https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md --------- Co-authored-by: Victor Sanni <victorsanniay@gmail.com>
This commit is contained in:
parent
17e73f219f
commit
97b7700dae
@ -223,7 +223,7 @@ class _RenderSliverResizingHeader extends RenderSliver
|
||||
paintExtent: math.min(childExtent, remainingPaintExtent),
|
||||
layoutExtent: clampDouble(layoutExtent, 0, remainingPaintExtent),
|
||||
maxPaintExtent: childExtent,
|
||||
maxScrollObstructionExtent: childExtent,
|
||||
maxScrollObstructionExtent: minExtent,
|
||||
cacheExtent: calculateCacheOffset(constraints, from: 0.0, to: childExtent),
|
||||
hasVisualOverflow: true, // Conservatively say we do have overflow to avoid complexity.
|
||||
);
|
||||
|
@ -357,4 +357,57 @@ void main() {
|
||||
await tester.pumpAndSettle();
|
||||
expect(getHeaderHeight(), 200);
|
||||
});
|
||||
|
||||
testWidgets('SliverResizingHeader maxScrollObstructionExtent', (WidgetTester tester) async {
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: Scaffold(
|
||||
body: NestedScrollView(
|
||||
headerSliverBuilder:
|
||||
(BuildContext context, _) => <Widget>[
|
||||
SliverOverlapAbsorber(
|
||||
handle: NestedScrollView.sliverOverlapAbsorberHandleFor(context),
|
||||
sliver: const SliverResizingHeader(
|
||||
minExtentPrototype: SizedBox(height: 100),
|
||||
maxExtentPrototype: SizedBox(height: 300),
|
||||
child: SizedBox.expand(child: Text('header')),
|
||||
),
|
||||
),
|
||||
],
|
||||
body: Builder(
|
||||
builder:
|
||||
(BuildContext context) => CustomScrollView(
|
||||
slivers: <Widget>[
|
||||
SliverOverlapInjector(
|
||||
handle: NestedScrollView.sliverOverlapAbsorberHandleFor(context),
|
||||
),
|
||||
SliverList(
|
||||
delegate: SliverChildBuilderDelegate(
|
||||
(BuildContext context, int index) =>
|
||||
SizedBox(height: 50, child: Text('$index')),
|
||||
childCount: 100,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
double getHeaderHeight() => tester.getSize(find.text('header')).height;
|
||||
|
||||
expect(getHeaderHeight(), 300);
|
||||
|
||||
// After scrolling down 150px, the header height becomes 150px
|
||||
await tester.drag(find.byType(NestedScrollView), const Offset(0, -150));
|
||||
await tester.pumpAndSettle();
|
||||
expect(getHeaderHeight(), 150);
|
||||
|
||||
// After scrolling down an additional 150px, the header height becomes 100px
|
||||
await tester.drag(find.byType(NestedScrollView), const Offset(0, -150));
|
||||
await tester.pumpAndSettle();
|
||||
expect(getHeaderHeight(), 100);
|
||||
});
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user