Clean up flipping of ScrollDirection (#8343)
Makes RenderViewport.layoutOneSide more readable.
This commit is contained in:
parent
34a6e48ac8
commit
5e93756f19
@ -131,6 +131,27 @@ AxisDirection applyGrowthDirectionToAxisDirection(AxisDirection axisDirection, G
|
||||
return null;
|
||||
}
|
||||
|
||||
/// Flips the [ScrollDirection] if the [GrowthDirection] is [GrowthDirection.reverse].
|
||||
///
|
||||
/// Specifically, returns `scrollDirection` if `scrollDirection` is
|
||||
/// [GrowthDirection.forward], otherwise returns [flipScrollDirection] applied to
|
||||
/// `scrollDirection`.
|
||||
///
|
||||
/// This function is useful in [RenderSliver] subclasses that are given both an
|
||||
/// [ScrollDirection] and a [GrowthDirection] and wish to compute the
|
||||
/// [ScrollDirection] in which growth will occur.
|
||||
ScrollDirection applyGrowthDirecitonToScrollDirection(ScrollDirection scrollDirection, GrowthDirection growthDirection) {
|
||||
assert(scrollDirection != null);
|
||||
assert(growthDirection != null);
|
||||
switch (growthDirection) {
|
||||
case GrowthDirection.forward:
|
||||
return scrollDirection;
|
||||
case GrowthDirection.reverse:
|
||||
return flipScrollDirection(scrollDirection);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/// Immutable layout constraints for [RenderSliver] layout.
|
||||
///
|
||||
/// The [SliverConstraints] describe the current scroll state of the viewport
|
||||
@ -524,7 +545,7 @@ class SliverGeometry {
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
final StringBuffer buffer = new StringBuffer();
|
||||
buffer.write('SliverGeometry(');
|
||||
buffer.write('scrollExtent: ${scrollExtent.toStringAsFixed(1)}, ');
|
||||
if (paintExtent > 0.0) {
|
||||
|
@ -129,28 +129,11 @@ abstract class RenderViewportBase<ParentDataClass extends ContainerParentDataMix
|
||||
) {
|
||||
assert(scrollOffset.isFinite);
|
||||
assert(scrollOffset >= 0.0);
|
||||
ScrollDirection adjustedUserScrollDirection;
|
||||
switch (growthDirection) {
|
||||
case GrowthDirection.forward:
|
||||
adjustedUserScrollDirection = offset.userScrollDirection;
|
||||
break;
|
||||
case GrowthDirection.reverse:
|
||||
switch (offset.userScrollDirection) {
|
||||
case ScrollDirection.forward:
|
||||
adjustedUserScrollDirection = ScrollDirection.reverse;
|
||||
break;
|
||||
case ScrollDirection.reverse:
|
||||
adjustedUserScrollDirection = ScrollDirection.forward;
|
||||
break;
|
||||
case ScrollDirection.idle:
|
||||
adjustedUserScrollDirection = ScrollDirection.idle;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
final ScrollDirection adjustedUserScrollDirection =
|
||||
applyGrowthDirecitonToScrollDirection(offset.userScrollDirection, growthDirection);
|
||||
assert(adjustedUserScrollDirection != null);
|
||||
double maxPaintOffset = layoutOffset;
|
||||
double initialLayoutOffset = layoutOffset;
|
||||
final double initialLayoutOffset = layoutOffset;
|
||||
while (child != null) {
|
||||
assert(scrollOffset >= 0.0);
|
||||
child.layout(new SliverConstraints(
|
||||
|
@ -33,6 +33,23 @@ enum ScrollDirection {
|
||||
reverse,
|
||||
}
|
||||
|
||||
/// Returns the opposite of the given [ScrollDirection].
|
||||
///
|
||||
/// Specifically, returns [AxisDirection.reverse] for [AxisDirection.forward]
|
||||
/// (and vice versa) and returns [ScrollDirection.idle] for
|
||||
/// [ScrollDirection.idle].
|
||||
ScrollDirection flipScrollDirection(ScrollDirection direction) {
|
||||
switch (direction) {
|
||||
case ScrollDirection.idle:
|
||||
return ScrollDirection.idle;
|
||||
case ScrollDirection.forward:
|
||||
return ScrollDirection.reverse;
|
||||
case ScrollDirection.reverse:
|
||||
return ScrollDirection.forward;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
abstract class ViewportOffset extends ChangeNotifier {
|
||||
ViewportOffset();
|
||||
factory ViewportOffset.fixed(double value) = _FixedViewportOffset;
|
||||
|
Loading…
x
Reference in New Issue
Block a user