Skip to content

Commit a0de83f

Browse files
committed
scroll [nfc]: Inline animateTo implementation into scrollToEnd
This gets us hands-on control of the ScrollActivity being used, which we'll want to customize in order to get the behavior we want.
1 parent c3dcb77 commit a0de83f

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

lib/widgets/scrolling.dart

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,15 @@ class MessageListScrollPosition extends ScrollPositionWithSingleContext {
384384
/// at the start of the animation, even if that ends up being more or less far
385385
/// than the actual extent of the content.
386386
void scrollToEnd() {
387+
final target = maxScrollExtent;
388+
389+
final tolerance = physics.toleranceFor(this);
390+
if (nearEqual(pixels, target, tolerance.distance)) {
391+
// Skip the animation; jump right to the target, which is already close.
392+
jumpTo(target);
393+
return;
394+
}
395+
387396
/// The top speed to move at, in logical pixels per second.
388397
///
389398
/// This will be the speed whenever the distance to be traveled
@@ -402,12 +411,12 @@ class MessageListScrollPosition extends ScrollPositionWithSingleContext {
402411
/// that that means a speed of at most [topSpeed].
403412
const minDuration = Duration(milliseconds: 300);
404413

405-
final target = maxScrollExtent;
406414
final durationSecAtSpeedLimit = (target - pixels) / topSpeed;
407415
final durationSec = math.max(durationSecAtSpeedLimit,
408416
minDuration.inMilliseconds / 1000.0);
409417
final duration = Duration(milliseconds: (durationSec * 1000.0).ceil());
410-
animateTo(target, duration: duration, curve: Curves.linear);
418+
beginActivity(DrivenScrollActivity(this, vsync: context.vsync,
419+
from: pixels, to: target, duration: duration, curve: Curves.linear));
411420
}
412421
}
413422

0 commit comments

Comments
 (0)