Skip to content

Commit 6ecde6a

Browse files
authored
Expand on docs around scroll simulation (#20)
1 parent 8284ad7 commit 6ecde6a

File tree

1 file changed

+27
-10
lines changed

1 file changed

+27
-10
lines changed

lib/src/page_list_viewport_gestures.dart

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -260,8 +260,6 @@ class _PageListViewportGesturesState extends State<PageListViewportGestures> wit
260260
}
261261
}
262262

263-
Duration? lastDuration;
264-
265263
void _onFrictionTick(Duration elapsedTime) {
266264
if (elapsedTime == Duration.zero) {
267265
return;
@@ -314,8 +312,16 @@ class _PageListViewportGesturesState extends State<PageListViewportGestures> wit
314312
}
315313

316314
class DeprecatedPanAndScaleVelocityTracker {
317-
static double kViewportMinFlingVelocity = 600;
318-
static double kViewportMinFlingDistance = 60;
315+
/// The maximum velocity a gesture can have and still be considered a viewport
316+
/// re-adjustment. Used in tandem with the [kViewportReAdjustmentMinTranslationDistance]
317+
/// to determine if the user is re-adjusting the viewport. Viewport re-adjustments
318+
/// result in the momentum simulation to be aborted.
319+
static double kViewportReAdjustmentMaxVelocity = 600;
320+
321+
/// The minimum distance the viewport must be translated such that the
322+
/// gesture is considered a viewport re-adjustment which results in the
323+
/// momentum simulation to be aborted.
324+
static double kViewportReAdjustmentMinTranslationDistance = 60;
319325

320326
DeprecatedPanAndScaleVelocityTracker({
321327
required Clock clock,
@@ -333,7 +339,11 @@ class DeprecatedPanAndScaleVelocityTracker {
333339

334340
Offset get velocity => _launchVelocity;
335341
Offset _launchVelocity = Offset.zero;
336-
Offset _startPosition = Offset.zero;
342+
343+
/// The focal point when the gesture started.
344+
Offset _startFocalPosition = Offset.zero;
345+
346+
/// The last focal point before the gesture ended
337347
Offset _lastFocalPosition = Offset.zero;
338348

339349
void onScaleStart(ScaleStartDetails details) {
@@ -378,7 +388,7 @@ class DeprecatedPanAndScaleVelocityTracker {
378388
}
379389

380390
_previousPointerCount = details.pointerCount;
381-
_startPosition = details.localFocalPoint;
391+
_startFocalPosition = details.localFocalPoint;
382392
}
383393

384394
void onScaleUpdate(Offset localFocalPoint, int pointerCount) {
@@ -443,8 +453,9 @@ class DeprecatedPanAndScaleVelocityTracker {
443453
return;
444454
}
445455

446-
final translationDistance = (_lastFocalPosition - _startPosition).distance;
447-
if (translationDistance > kViewportMinFlingDistance && velocity.distance < kViewportMinFlingVelocity) {
456+
final translationDistance = (_lastFocalPosition - _startFocalPosition).distance;
457+
if (translationDistance > kViewportReAdjustmentMinTranslationDistance &&
458+
velocity.distance < kViewportReAdjustmentMaxVelocity) {
448459
// The user was readjusting the viewport by dragging it to the
449460
// new position.
450461
return;
@@ -471,6 +482,11 @@ class DeprecatedPanAndScaleVelocityTracker {
471482
}
472483

473484
class PanningFrictionSimulation {
485+
// Dampening factors applied to each component of a [FrictionSimulation].
486+
// Larger values result in the [FrictionSimulation] to accelerate faster and approach
487+
// zero slower, giving the impression of the simulation being "more slippery".
488+
// It was found through testing that other scroll systems seem to be use different dampening
489+
// factors for the vertical and horizontal components.
474490
static const kVerticalDrag = 0.095;
475491
static const kHorizontalDrag = 0.0425;
476492

@@ -479,7 +495,8 @@ class PanningFrictionSimulation {
479495
required Offset velocity,
480496
}) : _position = position,
481497
_velocity = velocity {
482-
// Clamping bounds determines how long the simulation will run. Larger numbers slide for longer,
498+
// Clamping bounds enforces a maximum instantaneous velocity of the viewport
499+
// and in turn, how long the simulation will run. Larger numbers slide for longer,
483500
// smaller numbers end more quickly.
484501
_xSimulation = ClampedSimulation(
485502
FrictionSimulation(
@@ -506,7 +523,7 @@ class PanningFrictionSimulation {
506523
// near the end (when it smoothly slides to zero).
507524
constantDeceleration: 2.35,
508525
),
509-
dxMin: -2000, // Scroll up more slowly than scrolling down. A config found in some other scrolling systems.
526+
dxMin: -2000, // Scroll down more slowly than scrolling up. A config found in some other scrolling systems.
510527
dxMax: 3000,
511528
);
512529
}

0 commit comments

Comments
 (0)