Skip to content

Commit a435fe9

Browse files
gnpricechrisbobbe
authored andcommitted
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 e583ffa commit a435fe9

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
@@ -178,6 +178,15 @@ class MessageListScrollPosition extends ScrollPositionWithSingleContext {
178178
/// at the start of the animation, even if that ends up being more or less far
179179
/// than the actual extent of the content.
180180
void scrollToEnd() {
181+
final target = maxScrollExtent;
182+
183+
final tolerance = physics.toleranceFor(this);
184+
if (nearEqual(pixels, target, tolerance.distance)) {
185+
// Skip the animation; jump right to the target, which is already close.
186+
jumpTo(target);
187+
return;
188+
}
189+
181190
/// The top speed to move at, in logical pixels per second.
182191
///
183192
/// This will be the speed whenever the distance to be traveled
@@ -196,12 +205,12 @@ class MessageListScrollPosition extends ScrollPositionWithSingleContext {
196205
/// that that means a speed of at most [topSpeed].
197206
const minDuration = Duration(milliseconds: 300);
198207

199-
final target = maxScrollExtent;
200208
final durationSecAtSpeedLimit = (target - pixels) / topSpeed;
201209
final durationSec = math.max(durationSecAtSpeedLimit,
202210
minDuration.inMilliseconds / 1000.0);
203211
final duration = Duration(milliseconds: (durationSec * 1000.0).ceil());
204-
animateTo(target, duration: duration, curve: Curves.linear);
212+
beginActivity(DrivenScrollActivity(this, vsync: context.vsync,
213+
from: pixels, to: target, duration: duration, curve: Curves.linear));
205214
}
206215
}
207216

0 commit comments

Comments
 (0)