Commit 72807ef8 authored by Adam Barth's avatar Adam Barth

Fix padding on infinite scrolling list

Rather than using a Padding widget to provide padding along the scrolling axis,
we now just figure the padding into where we draw the items. This patch fixes
an issue where we would remove the first topmost item in a scrollable list too
early because we thought it was already off screen.

Fixes #697
parent 87adaf3f
...@@ -384,14 +384,30 @@ abstract class FixedHeightScrollable extends Scrollable { ...@@ -384,14 +384,30 @@ abstract class FixedHeightScrollable extends Scrollable {
}); });
} }
double get _leadingPadding {
if (scrollDirection == ScrollDirection.vertical)
return padding.top;
return padding.left;
}
double get _trailingPadding {
if (scrollDirection == ScrollDirection.vertical)
return padding.bottom;
return padding.right;
}
EdgeDims get _crossAxisPadding {
if (padding == null)
return null;
if (scrollDirection == ScrollDirection.vertical)
return new EdgeDims.only(left: padding.left, right: padding.right);
return new EdgeDims.only(top: padding.top, bottom: padding.bottom);
}
void _updateContentsExtent() { void _updateContentsExtent() {
double contentsExtent = itemExtent * itemCount; double contentsExtent = itemExtent * itemCount;
if (padding != null) { if (padding != null)
if (scrollDirection == ScrollDirection.vertical) contentsExtent += _leadingPadding + _trailingPadding;
contentsExtent += padding.top + padding.bottom;
else
contentsExtent += padding.left + padding.right;
}
scrollBehavior.contentsSize = contentsExtent; scrollBehavior.contentsSize = contentsExtent;
} }
...@@ -413,25 +429,29 @@ abstract class FixedHeightScrollable extends Scrollable { ...@@ -413,25 +429,29 @@ abstract class FixedHeightScrollable extends Scrollable {
_updateScrollOffset(); _updateScrollOffset();
} }
double paddedScrollOffset = scrollOffset;
if (padding != null)
paddedScrollOffset -= _leadingPadding;
int itemShowIndex = 0; int itemShowIndex = 0;
int itemShowCount = 0; int itemShowCount = 0;
Offset viewportOffset = Offset.zero; Offset viewportOffset = Offset.zero;
if (_containerExtent != null && _containerExtent > 0.0) { if (_containerExtent != null && _containerExtent > 0.0) {
if (scrollOffset < 0.0) { if (paddedScrollOffset < 0.0) {
double visibleHeight = _containerExtent + scrollOffset; double visibleHeight = _containerExtent + paddedScrollOffset;
itemShowCount = (visibleHeight / itemExtent).round() + 1; itemShowCount = (visibleHeight / itemExtent).round() + 1;
viewportOffset = _toOffset(scrollOffset); viewportOffset = _toOffset(paddedScrollOffset);
} else { } else {
itemShowCount = (_containerExtent / itemExtent).ceil(); itemShowCount = (_containerExtent / itemExtent).ceil();
double alignmentDelta = -scrollOffset % itemExtent; double alignmentDelta = -paddedScrollOffset % itemExtent;
double drawStart; double drawStart;
if (alignmentDelta != 0.0) { if (alignmentDelta != 0.0) {
alignmentDelta -= itemExtent; alignmentDelta -= itemExtent;
itemShowCount += 1; itemShowCount += 1;
drawStart = scrollOffset + alignmentDelta; drawStart = paddedScrollOffset + alignmentDelta;
viewportOffset = _toOffset(-alignmentDelta); viewportOffset = _toOffset(-alignmentDelta);
} else { } else {
drawStart = scrollOffset; drawStart = paddedScrollOffset;
} }
itemShowIndex = math.max(0, (drawStart / itemExtent).floor()); itemShowIndex = math.max(0, (drawStart / itemExtent).floor());
} }
...@@ -453,7 +473,7 @@ abstract class FixedHeightScrollable extends Scrollable { ...@@ -453,7 +473,7 @@ abstract class FixedHeightScrollable extends Scrollable {
scrollDirection: scrollDirection, scrollDirection: scrollDirection,
scrollOffset: viewportOffset, scrollOffset: viewportOffset,
child: new Container( child: new Container(
padding: padding, padding: _crossAxisPadding,
child: new Block(items, direction: blockDirection) child: new Block(items, direction: blockDirection)
) )
) )
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment