Skip to content

Commit

Permalink
Bounce effect workaround
Browse files Browse the repository at this point in the history
  • Loading branch information
DamirDautov committed Jun 8, 2021
1 parent 8f62b08 commit 2312e9c
Showing 1 changed file with 27 additions and 3 deletions.
30 changes: 27 additions & 3 deletions packages/scrollable_positioned_list/lib/src/viewport.dart
Original file line number Diff line number Diff line change
Expand Up @@ -231,10 +231,36 @@ class UnboundedRenderViewport extends RenderViewport {
_maxScrollExtent = 0.0;
_hasVisualOverflow = false;

final RenderSliver? leadingNegativeChild = childBefore(center!);
final RenderSliver? trailingPositiveChild = childAfter(center!);
final double leadingOffset = (leadingNegativeChild != null
? leadingNegativeChild.geometry?.scrollExtent ?? 0
: 0);
final double trailingOffset = (trailingPositiveChild != null
? trailingPositiveChild.geometry?.scrollExtent ?? 0
: 0);
final double centerBodyOffset =
(center != null ? center!.geometry?.scrollExtent ?? 0 : 0);

// centerOffset is the offset from the leading edge of the RenderViewport
// to the zero scroll offset (the line between the forward slivers and the
// reverse slivers).
final double centerOffset = mainAxisExtent * anchor - correctedOffset;
double centerOffset = mainAxisExtent * anchor - correctedOffset;
if (leadingOffset + centerBodyOffset + trailingOffset > 0) {
if (leadingOffset + centerBodyOffset + trailingOffset < mainAxisExtent) {
centerOffset = math.max(
leadingOffset,
mainAxisExtent * anchor - centerBodyOffset - trailingOffset,
);
} else {
centerOffset = centerOffset.clamp(
mainAxisExtent - centerBodyOffset - trailingOffset,
leadingOffset +
(leadingOffset > mainAxisExtent ? mainAxisExtent * anchor : 0),
);
}
}

final double reverseDirectionRemainingPaintExtent =
centerOffset.clamp(0.0, mainAxisExtent);
final double forwardDirectionRemainingPaintExtent =
Expand All @@ -256,8 +282,6 @@ class UnboundedRenderViewport extends RenderViewport {
final double forwardDirectionRemainingCacheExtent =
(fullCacheExtent - centerCacheOffset).clamp(0.0, fullCacheExtent);

final RenderSliver? leadingNegativeChild = childBefore(center!);

if (leadingNegativeChild != null) {
// negative scroll offsets
final double result = layoutChildSequence(
Expand Down

0 comments on commit 2312e9c

Please sign in to comment.