Skip to content

Commit 6264ed9

Browse files
committed
scroll [nfc]: Introduce ScrollToEndActivity
We'll use this to customize the behavior. It also makes a handy marker in tests, when using the testing-only [ScrollPosition.activity] getter for inspecting what's going on in the scroll behavior.
1 parent 7055b9c commit 6264ed9

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

lib/widgets/scrolling.dart

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,21 @@ class _SingleChildScrollViewWithScrollbarState
4343
}
4444
}
4545

46+
/// An activity that animates a scroll view smoothly to its end.
47+
///
48+
/// In particular this drives the "scroll to bottom" button
49+
/// in the Zulip message list.
50+
class ScrollToEndActivity extends DrivenScrollActivity {
51+
ScrollToEndActivity(
52+
super.delegate, {
53+
required super.from,
54+
required super.to,
55+
required super.duration,
56+
required super.curve,
57+
required super.vsync,
58+
});
59+
}
60+
4661
/// A version of [ScrollPosition] adapted for the Zulip message list,
4762
/// used by [MessageListScrollController].
4863
class MessageListScrollPosition extends ScrollPositionWithSingleContext {
@@ -217,7 +232,7 @@ class MessageListScrollPosition extends ScrollPositionWithSingleContext {
217232
final durationSec = math.max(durationSecAtSpeedLimit,
218233
minDuration.inMilliseconds / 1000.0);
219234
final duration = Duration(milliseconds: (durationSec * 1000.0).ceil());
220-
beginActivity(DrivenScrollActivity(this, vsync: context.vsync,
235+
beginActivity(ScrollToEndActivity(this, vsync: context.vsync,
221236
from: pixels, to: target, duration: duration, curve: Curves.linear));
222237
}
223238
}

test/widgets/scrolling_test.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ void main() {
204204
position.scrollToEnd();
205205
await tester.pump();
206206
check(position.extentAfter).equals(300);
207-
check(position.activity).isA<DrivenScrollActivity>();
207+
check(position.activity).isA<ScrollToEndActivity>();
208208

209209
// The scrolling moves at a stately pace; …
210210
await tester.pump(Duration(milliseconds: 100));
@@ -236,7 +236,7 @@ void main() {
236236
// Start scrolling to end.
237237
position.scrollToEnd();
238238
await tester.pump();
239-
check(position.activity).isA<DrivenScrollActivity>();
239+
check(position.activity).isA<ScrollToEndActivity>();
240240

241241
// Let it scroll, plotting the trajectory.
242242
final log = <double>[];

0 commit comments

Comments
 (0)