Remove BlockDirection in favor of ScrollDirection
We'll probably renaming ScrollDirection to Axis in a future patch. Fixes #151
This commit is contained in:
parent
06b566bdea
commit
76dd6228b4
@ -13,14 +13,6 @@ import 'viewport.dart';
|
|||||||
/// Parent data for use with [RenderBlockBase].
|
/// Parent data for use with [RenderBlockBase].
|
||||||
class BlockParentData extends ContainerBoxParentDataMixin<RenderBox> { }
|
class BlockParentData extends ContainerBoxParentDataMixin<RenderBox> { }
|
||||||
|
|
||||||
/// The direction in which the block should lay out.
|
|
||||||
enum BlockDirection {
|
|
||||||
/// Children are arranged horizontally, from left to right.
|
|
||||||
horizontal,
|
|
||||||
/// Children are arranged vertically, from top to bottom.
|
|
||||||
vertical
|
|
||||||
}
|
|
||||||
|
|
||||||
typedef double _ChildSizingFunction(RenderBox child, BoxConstraints constraints);
|
typedef double _ChildSizingFunction(RenderBox child, BoxConstraints constraints);
|
||||||
typedef double _Constrainer(double value);
|
typedef double _Constrainer(double value);
|
||||||
|
|
||||||
@ -40,7 +32,7 @@ abstract class RenderBlockBase extends RenderBox
|
|||||||
|
|
||||||
RenderBlockBase({
|
RenderBlockBase({
|
||||||
List<RenderBox> children,
|
List<RenderBox> children,
|
||||||
BlockDirection direction: BlockDirection.vertical,
|
ScrollDirection direction: ScrollDirection.vertical,
|
||||||
double itemExtent,
|
double itemExtent,
|
||||||
double minExtent: 0.0
|
double minExtent: 0.0
|
||||||
}) : _direction = direction, _itemExtent = itemExtent, _minExtent = minExtent {
|
}) : _direction = direction, _itemExtent = itemExtent, _minExtent = minExtent {
|
||||||
@ -53,9 +45,9 @@ abstract class RenderBlockBase extends RenderBox
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// The direction to use as the main axis.
|
/// The direction to use as the main axis.
|
||||||
BlockDirection get direction => _direction;
|
ScrollDirection get direction => _direction;
|
||||||
BlockDirection _direction;
|
ScrollDirection _direction;
|
||||||
void set direction (BlockDirection value) {
|
void set direction (ScrollDirection value) {
|
||||||
if (_direction != value) {
|
if (_direction != value) {
|
||||||
_direction = value;
|
_direction = value;
|
||||||
markNeedsLayout();
|
markNeedsLayout();
|
||||||
@ -83,10 +75,9 @@ abstract class RenderBlockBase extends RenderBox
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Whether the main axis is vertical.
|
/// Whether the main axis is vertical.
|
||||||
bool get isVertical => _direction == BlockDirection.vertical;
|
bool get isVertical => _direction == ScrollDirection.vertical;
|
||||||
|
|
||||||
// TODO(abarth): Remove BlockDirection in favor of ScrollDirection.
|
ScrollDirection get scrollDirection => _direction;
|
||||||
ScrollDirection get scrollDirection => isVertical ? ScrollDirection.vertical : ScrollDirection.horizontal;
|
|
||||||
|
|
||||||
BoxConstraints _getInnerConstraints(BoxConstraints constraints) {
|
BoxConstraints _getInnerConstraints(BoxConstraints constraints) {
|
||||||
if (isVertical)
|
if (isVertical)
|
||||||
@ -135,7 +126,7 @@ class RenderBlock extends RenderBlockBase {
|
|||||||
|
|
||||||
RenderBlock({
|
RenderBlock({
|
||||||
List<RenderBox> children,
|
List<RenderBox> children,
|
||||||
BlockDirection direction: BlockDirection.vertical,
|
ScrollDirection direction: ScrollDirection.vertical,
|
||||||
double itemExtent,
|
double itemExtent,
|
||||||
double minExtent: 0.0
|
double minExtent: 0.0
|
||||||
}) : super(children: children, direction: direction, itemExtent: itemExtent, minExtent: minExtent);
|
}) : super(children: children, direction: direction, itemExtent: itemExtent, minExtent: minExtent);
|
||||||
@ -251,7 +242,7 @@ class RenderBlockViewport extends RenderBlockBase {
|
|||||||
ExtentCallback maxCrossAxisDimensionCallback,
|
ExtentCallback maxCrossAxisDimensionCallback,
|
||||||
ExtentCallback minCrossAxisDimensionCallback,
|
ExtentCallback minCrossAxisDimensionCallback,
|
||||||
Painter overlayPainter,
|
Painter overlayPainter,
|
||||||
BlockDirection direction: BlockDirection.vertical,
|
ScrollDirection direction: ScrollDirection.vertical,
|
||||||
double itemExtent,
|
double itemExtent,
|
||||||
double minExtent: 0.0,
|
double minExtent: 0.0,
|
||||||
double startOffset: 0.0,
|
double startOffset: 0.0,
|
||||||
|
@ -11,7 +11,6 @@ import 'framework.dart';
|
|||||||
|
|
||||||
export 'package:flutter/rendering.dart' show
|
export 'package:flutter/rendering.dart' show
|
||||||
BackgroundImage,
|
BackgroundImage,
|
||||||
BlockDirection,
|
|
||||||
Border,
|
Border,
|
||||||
BorderSide,
|
BorderSide,
|
||||||
BoxConstraints,
|
BoxConstraints,
|
||||||
@ -948,13 +947,13 @@ class Container extends StatelessComponent {
|
|||||||
class BlockBody extends MultiChildRenderObjectWidget {
|
class BlockBody extends MultiChildRenderObjectWidget {
|
||||||
BlockBody(List<Widget> children, {
|
BlockBody(List<Widget> children, {
|
||||||
Key key,
|
Key key,
|
||||||
this.direction: BlockDirection.vertical
|
this.direction: ScrollDirection.vertical
|
||||||
}) : super(key: key, children: children) {
|
}) : super(key: key, children: children) {
|
||||||
assert(direction != null);
|
assert(direction != null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The direction to use as the main axis.
|
/// The direction to use as the main axis.
|
||||||
final BlockDirection direction;
|
final ScrollDirection direction;
|
||||||
|
|
||||||
RenderBlock createRenderObject() => new RenderBlock(direction: direction);
|
RenderBlock createRenderObject() => new RenderBlock(direction: direction);
|
||||||
|
|
||||||
|
@ -207,7 +207,7 @@ class _HomogeneousViewportElement extends _ViewportBaseElement<HomogeneousViewpo
|
|||||||
_layoutItemCount = math.max(0, _layoutItemCount);
|
_layoutItemCount = math.max(0, _layoutItemCount);
|
||||||
_updateChildren();
|
_updateChildren();
|
||||||
// Update the renderObject configuration
|
// Update the renderObject configuration
|
||||||
renderObject.direction = widget.direction == ScrollDirection.vertical ? BlockDirection.vertical : BlockDirection.horizontal;
|
renderObject.direction = widget.direction;
|
||||||
renderObject.itemExtent = widget.itemExtent;
|
renderObject.itemExtent = widget.itemExtent;
|
||||||
renderObject.minExtent = getTotalExtent(null);
|
renderObject.minExtent = getTotalExtent(null);
|
||||||
renderObject.startOffset = offset;
|
renderObject.startOffset = offset;
|
||||||
|
@ -509,14 +509,7 @@ class _MixedViewportElement extends RenderObjectElement<MixedViewport> {
|
|||||||
int index = startIndex;
|
int index = startIndex;
|
||||||
if (haveChildren) {
|
if (haveChildren) {
|
||||||
// Update the renderObject configuration
|
// Update the renderObject configuration
|
||||||
switch (widget.direction) {
|
renderObject.direction = renderObject.direction;
|
||||||
case ScrollDirection.vertical:
|
|
||||||
renderObject.direction = BlockDirection.vertical;
|
|
||||||
break;
|
|
||||||
case ScrollDirection.horizontal:
|
|
||||||
renderObject.direction = BlockDirection.horizontal;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
renderObject.startOffset = _childOffsets[index] - widget.startOffset;
|
renderObject.startOffset = _childOffsets[index] - widget.startOffset;
|
||||||
// Build all the widgets we still need.
|
// Build all the widgets we still need.
|
||||||
while (_childOffsets[index] < endOffset) {
|
while (_childOffsets[index] < endOffset) {
|
||||||
|
@ -424,14 +424,8 @@ class Block extends StatelessComponent {
|
|||||||
final ScrollDirection scrollDirection;
|
final ScrollDirection scrollDirection;
|
||||||
final ScrollListener onScroll;
|
final ScrollListener onScroll;
|
||||||
|
|
||||||
BlockDirection get _direction {
|
|
||||||
if (scrollDirection == ScrollDirection.vertical)
|
|
||||||
return BlockDirection.vertical;
|
|
||||||
return BlockDirection.horizontal;
|
|
||||||
}
|
|
||||||
|
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
Widget contents = new BlockBody(children, direction: _direction);
|
Widget contents = new BlockBody(children, direction: scrollDirection);
|
||||||
if (padding != null)
|
if (padding != null)
|
||||||
contents = new Padding(padding: padding, child: contents);
|
contents = new Padding(padding: padding, child: contents);
|
||||||
return new ScrollableViewport(
|
return new ScrollableViewport(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user