Skip to content

Commit b3a78d8

Browse files
gnpricechrisbobbe
authored andcommitted
scroll [nfc]: Explain magic numbers in scroll-to-end calculations
1 parent 97f5821 commit b3a78d8

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

lib/widgets/scrolling.dart

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,10 +178,28 @@ 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+
/// The top speed to move at, in logical pixels per second.
182+
///
183+
/// This will be the speed whenever the distance to be traveled
184+
/// is long enough to take at least [minDuration] at this speed.
185+
///
186+
/// This is chosen to equal the top speed that can be produced
187+
/// by a fling gesture in a Flutter [ScrollView],
188+
/// which in turn was chosen to equal the top speed of
189+
/// an (initial) fling gesture in a native Android scroll view.
190+
const double topSpeed = 8000;
191+
192+
/// The desired duration of the animation when traveling short distances.
193+
///
194+
/// The speed will be chosen so that traveling the distance
195+
/// will take this long, whenever that distance is short enough
196+
/// that that means a speed of at most [topSpeed].
197+
const minDuration = Duration(milliseconds: 300);
198+
181199
final target = maxScrollExtent;
182200
final distance = target - pixels;
183-
final durationMsAtSpeedLimit = (1000 * distance / 8000).ceil();
184-
final durationMs = math.max(300, durationMsAtSpeedLimit);
201+
final durationMsAtSpeedLimit = (1000 * distance / topSpeed).ceil();
202+
final durationMs = math.max(minDuration.inMilliseconds, durationMsAtSpeedLimit);
185203
animateTo(
186204
target,
187205
duration: Duration(milliseconds: durationMs),

0 commit comments

Comments
 (0)