Skip to content

Commit 2541a10

Browse files
committed
scroll [nfc]: Introduce applyContentDimensionsRaw on scroll position
1 parent 4efbb12 commit 2541a10

File tree

1 file changed

+25
-4
lines changed

1 file changed

+25
-4
lines changed

lib/widgets/scrolling.dart

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,25 @@ class MessageListScrollPosition extends ScrollPositionWithSingleContext {
259259
super.oldPosition,
260260
super.debugLabel,
261261
});
262+
263+
/// Like [applyContentDimensions], but called without adjusting
264+
/// the arguments to subtract the viewport dimension.
265+
///
266+
/// For instance, if there is 100.0 pixels of scrollable content
267+
/// of which 40.0 pixels is in the reverse-growing slivers and
268+
/// 60.0 pixels in the forward-growing slivers, then the arguments
269+
/// will be -40.0 and 60.0, regardless of the viewport dimension.
270+
///
271+
/// By contrast in a call to [applyContentDimensions], in this example and
272+
/// if the viewport dimension is 80.0, then the arguments might be
273+
/// 0.0 and 60.0, or -10.0 and 10.0, or -40.0 and 0.0, or other values,
274+
/// depending on the value of [Viewport.anchor].
275+
bool applyContentDimensionsRaw(double wholeMinScrollExtent, double wholeMaxScrollExtent) {
276+
// This makes the simplifying assumption that `anchor` is 1.0.
277+
final effectiveMin = math.min(0.0, wholeMinScrollExtent + viewportDimension);
278+
final effectiveMax = wholeMaxScrollExtent;
279+
return applyContentDimensions(effectiveMin, effectiveMax);
280+
}
262281
}
263282

264283
/// A version of [ScrollController] adapted for the Zulip message list.
@@ -449,10 +468,12 @@ class RenderMessageListViewport extends RenderCustomPaintOrderViewport {
449468
if (correction != 0.0) {
450469
offset.correctBy(correction);
451470
} else {
452-
if (offset.applyContentDimensions(
453-
math.min(0.0, _minScrollExtent + mainAxisExtent * anchor),
454-
math.max(0.0, _maxScrollExtent - mainAxisExtent * (1.0 - anchor)),
455-
)) {
471+
// TODO(upstream): Move applyContentDimensionsRaw to ViewportOffset
472+
// (possibly with an API change to tell it [anchor]?);
473+
// give it a default implementation calling applyContentDimensions;
474+
// have RenderViewport.performLayout call it.
475+
if ((offset as MessageListScrollPosition)
476+
.applyContentDimensionsRaw(_minScrollExtent, _maxScrollExtent)) {
456477
break;
457478
}
458479
}

0 commit comments

Comments
 (0)