Unverified Commit 5f394877 authored by LongCatIsLooong's avatar LongCatIsLooong Committed by GitHub

Don't show scrollbar if there isn't enough content (#34175)

parent 3ae6abd9
......@@ -103,6 +103,11 @@ class _CupertinoScrollbarState extends State<CupertinoScrollbar> with TickerProv
}
bool _handleScrollNotification(ScrollNotification notification) {
final ScrollMetrics metrics = notification.metrics;
if (metrics.maxScrollExtent <= metrics.minScrollExtent) {
return false;
}
if (notification is ScrollUpdateNotification ||
notification is OverscrollNotification) {
// Any movements always makes the scrollbar start showing up.
......
......@@ -109,6 +109,11 @@ class _ScrollbarState extends State<Scrollbar> with TickerProviderStateMixin {
}
bool _handleScrollNotification(ScrollNotification notification) {
final ScrollMetrics metrics = notification.metrics;
if (metrics.maxScrollExtent <= metrics.minScrollExtent) {
return false;
}
// iOS sub-delegates to the CupertinoScrollbar instead and doesn't handle
// scroll notifications here.
if (_currentPlatform != TargetPlatform.iOS
......
......@@ -77,7 +77,7 @@ void main() {
final TestGesture gesture = await tester.startGesture(tester.getCenter(find.byType(ListView)));
await gesture.moveBy(_kGestureOffset);
// Move back to original position.
await gesture.moveBy(Offset.zero.translate(-_kGestureOffset.dx, -_kGestureOffset.dy));
await gesture.moveBy(Offset(-_kGestureOffset.dx, -_kGestureOffset.dy));
await tester.pump();
await tester.pump(const Duration(milliseconds: 500));
......@@ -96,4 +96,44 @@ void main() {
),
));
});
testWidgets("should not paint when there isn't enough space", (WidgetTester tester) async {
await tester.pumpWidget(
CupertinoApp(
home: MediaQuery(
data: const MediaQueryData(
padding: EdgeInsets.fromLTRB(0, 20, 0, 34),
),
child: CupertinoPageScaffold(
navigationBar: const CupertinoNavigationBar(
middle: Text('Title'),
backgroundColor: Color(0x11111111),
),
child: CupertinoScrollbar(
child: ListView(
physics: const AlwaysScrollableScrollPhysics(parent: BouncingScrollPhysics()),
children: const <Widget> [SizedBox(width: 10, height: 10)],
),
),
),
),
),
);
final TestGesture gesture = await tester.startGesture(tester.getCenter(find.byType(ListView)));
await gesture.moveBy(_kGestureOffset);
// Move back to original position.
await gesture.moveBy(Offset(-_kGestureOffset.dx, -_kGestureOffset.dy));
await tester.pump();
await tester.pump(const Duration(milliseconds: 500));
expect(find.byType(CupertinoScrollbar), isNot(paints..rrect()));
// The scrollbar should not appear even when overscrolled.
final TestGesture overscrollGesture = await tester.startGesture(tester.getCenter(find.byType(ListView)));
await overscrollGesture.moveBy(_kGestureOffset);
await tester.pump();
await tester.pump(const Duration(milliseconds: 500));
expect(find.byType(CupertinoScrollbar), isNot(paints..rrect()));
});
}
......@@ -77,4 +77,32 @@ void main() {
),
));
});
testWidgets("should not paint when there isn't enough space", (WidgetTester tester) async {
await tester.pumpWidget(MaterialApp(
home: MediaQuery(
data: const MediaQueryData(
padding: EdgeInsets.fromLTRB(0, 20, 0, 34)
),
child: Scaffold(
appBar: AppBar(title: const Text('Title')),
body: Scrollbar(
child: ListView(
children: const <Widget>[SizedBox(width: 40, height: 40)]
),
),
),
),
));
final TestGesture gesture = await tester.startGesture(tester.getCenter(find.byType(ListView)));
// On Android it should not overscroll.
await gesture.moveBy(const Offset(0, 100));
// Trigger fade in animation.
await tester.pump();
await tester.pump(const Duration(milliseconds: 500));
expect(find.byType(Scrollbar), isNot(paints..rect()));
});
}
......@@ -115,8 +115,9 @@ void main() {
final List<Invocation> invocations = <Invocation>[];
final TestCanvas canvas = TestCanvas(invocations);
scrollPainter.paint(canvas, const Size(10.0, 100.0));
final Rect thumbRect = invocations.single.positionalArguments[0];
expect(thumbRect.isFinite, isTrue);
// Scrollbar is not supposed to draw anything if there isn't enough content.
expect(invocations.isEmpty, isTrue);
});
testWidgets('Adaptive scrollbar', (WidgetTester tester) async {
......
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