Skip to content

Commit e738a08

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 3856aef commit e738a08

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
@@ -249,6 +249,21 @@ class RenderCustomPaintOrderViewport extends RenderViewport {
249249
}
250250
}
251251

252+
/// An activity that animates a scroll view smoothly to its end.
253+
///
254+
/// In particular this drives the "scroll to bottom" button
255+
/// in the Zulip message list.
256+
class ScrollToEndActivity extends DrivenScrollActivity {
257+
ScrollToEndActivity(
258+
super.delegate, {
259+
required super.from,
260+
required super.to,
261+
required super.duration,
262+
required super.curve,
263+
required super.vsync,
264+
});
265+
}
266+
252267
/// A version of [ScrollPosition] adapted for the Zulip message list,
253268
/// used by [MessageListScrollController].
254269
class MessageListScrollPosition extends ScrollPositionWithSingleContext {
@@ -423,7 +438,7 @@ class MessageListScrollPosition extends ScrollPositionWithSingleContext {
423438
final durationSec = math.max(durationSecAtSpeedLimit,
424439
minDuration.inMilliseconds / 1000.0);
425440
final duration = Duration(milliseconds: (durationSec * 1000.0).ceil());
426-
beginActivity(DrivenScrollActivity(this, vsync: context.vsync,
441+
beginActivity(ScrollToEndActivity(this, vsync: context.vsync,
427442
from: pixels, to: target, duration: duration, curve: Curves.linear));
428443
}
429444
}

test/widgets/scrolling_test.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ void main() {
325325
position.scrollToEnd();
326326
await tester.pump();
327327
check(position.extentAfter).equals(300);
328-
check(position.activity).isA<DrivenScrollActivity>();
328+
check(position.activity).isA<ScrollToEndActivity>();
329329

330330
// The scrolling moves at a stately pace; …
331331
await tester.pump(Duration(milliseconds: 100));
@@ -357,7 +357,7 @@ void main() {
357357
// Start scrolling to end.
358358
position.scrollToEnd();
359359
await tester.pump();
360-
check(position.activity).isA<DrivenScrollActivity>();
360+
check(position.activity).isA<ScrollToEndActivity>();
361361

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

0 commit comments

Comments
 (0)