Commit d9e0c32d authored by Hans Muller's avatar Hans Muller

Remove ScrollableListPainter (#3226)

* Remove ScrollableListPainter
parent df0a9fc1
......@@ -1075,7 +1075,6 @@ class _TabBarViewState<T> extends PageableListState<TabBarView<T>> implements Ta
itemsWrap: config.itemsWrap,
mainAxis: config.scrollDirection,
startOffset: scrollOffset,
overlayPainter: config.scrollableListPainter,
children: _items
);
}
......
......@@ -6,7 +6,6 @@ import 'dart:math' as math;
import 'box.dart';
import 'object.dart';
import 'viewport.dart';
/// Parent data for use with [RenderBlockBase].
class BlockParentData extends ContainerBoxParentDataMixin<RenderBox> { }
......@@ -25,8 +24,7 @@ typedef double _Constrainer(double value);
/// viewport with a scrolling direction that matches the block's main axis.
class RenderBlock extends RenderBox
with ContainerRenderObjectMixin<RenderBox, BlockParentData>,
RenderBoxContainerDefaultsMixin<RenderBox, BlockParentData>
implements HasMainAxis {
RenderBoxContainerDefaultsMixin<RenderBox, BlockParentData> {
RenderBlock({
List<RenderBox> children,
......@@ -42,7 +40,6 @@ class RenderBlock extends RenderBox
}
/// The direction to use as the main axis.
@override
Axis get mainAxis => _mainAxis;
Axis _mainAxis;
void set mainAxis (Axis value) {
......
......@@ -73,18 +73,12 @@ class ViewportDimensions {
String toString() => 'ViewportDimensions(container: $containerSize, content: $contentSize)';
}
/// An interface that indicates that an object has a scroll direction.
abstract class HasMainAxis {
/// Whether this object scrolls horizontally or vertically.
Axis get mainAxis;
}
/// A base class for render objects that are bigger on the inside.
///
/// This class holds the common fields for viewport render objects but does not
/// have a child model. See [RenderViewport] for a viewport with a single child
/// and [RenderVirtualViewport] for a viewport with multiple children.
class RenderViewportBase extends RenderBox implements HasMainAxis {
class RenderViewportBase extends RenderBox {
RenderViewportBase(
Offset paintOffset,
Axis mainAxis,
......@@ -128,7 +122,6 @@ class RenderViewportBase extends RenderBox implements HasMainAxis {
/// The child is given layout constraints that are fully unconstrainted along
/// the main axis (e.g., the child can be as tall as it wants if the main axis
/// is vertical).
@override
Axis get mainAxis => _mainAxis;
Axis _mainAxis;
void set mainAxis(Axis value) {
......
......@@ -35,7 +35,6 @@ class PageableList extends Scrollable {
this.itemsWrap: false,
this.itemsSnapAlignment: PageableListFlingBehavior.stopAtNextPage,
this.onPageChanged,
this.scrollableListPainter,
this.duration: const Duration(milliseconds: 200),
this.curve: Curves.ease,
this.children
......@@ -61,9 +60,6 @@ class PageableList extends Scrollable {
/// Called when the currently visible page changes.
final ValueChanged<int> onPageChanged;
/// Used to paint the scrollbar for this list.
final ScrollableListPainter scrollableListPainter;
/// The duration used when animating to a given page.
final Duration duration;
......@@ -146,7 +142,6 @@ class PageableListState<T extends PageableList> extends ScrollableState<T> {
}
void _updateScrollBehavior() {
config.scrollableListPainter?.contentExtent = _itemCount.toDouble();
didUpdateScrollBehavior(scrollBehavior.updateExtents(
contentExtent: _itemCount.toDouble(),
containerExtent: 1.0,
......@@ -154,24 +149,6 @@ class PageableListState<T extends PageableList> extends ScrollableState<T> {
));
}
@override
void dispatchOnScrollStart() {
super.dispatchOnScrollStart();
config.scrollableListPainter?.scrollStarted();
}
@override
void dispatchOnScroll() {
super.dispatchOnScroll();
config.scrollableListPainter?.scrollOffset = scrollOffset;
}
@override
void dispatchOnScrollEnd() {
super.dispatchOnScrollEnd();
config.scrollableListPainter?.scrollEnded();
}
@override
Widget buildContent(BuildContext context) {
return new PageViewport(
......@@ -179,7 +156,6 @@ class PageableListState<T extends PageableList> extends ScrollableState<T> {
mainAxis: config.scrollDirection,
anchor: config.scrollAnchor,
startOffset: scrollOffset,
overlayPainter: config.scrollableListPainter,
children: config.children
);
}
......
......@@ -8,7 +8,6 @@ import 'dart:ui' as ui show window;
import 'package:newton/newton.dart';
import 'package:flutter/gestures.dart';
import 'package:flutter/rendering.dart' show HasMainAxis;
import 'basic.dart';
import 'framework.dart';
......@@ -764,100 +763,3 @@ class Block extends StatelessWidget {
);
}
}
abstract class ScrollableListPainter extends RenderObjectPainter {
@override
void attach(RenderObject renderObject) {
assert(renderObject is RenderBox);
assert(renderObject is HasMainAxis);
super.attach(renderObject);
}
@override
RenderBox get renderObject => super.renderObject;
Axis get scrollDirection {
HasMainAxis scrollable = renderObject as dynamic;
return scrollable?.mainAxis;
}
Size get viewportSize => renderObject.size;
double get contentExtent => _contentExtent;
double _contentExtent = 0.0;
void set contentExtent (double value) {
assert(value != null);
assert(value >= 0.0);
if (_contentExtent == value)
return;
_contentExtent = value;
renderObject?.markNeedsPaint();
}
double get scrollOffset => _scrollOffset;
double _scrollOffset = 0.0;
void set scrollOffset (double value) {
assert(value != null);
if (_scrollOffset == value)
return;
_scrollOffset = value;
renderObject?.markNeedsPaint();
}
/// Called when a scroll starts. Subclasses may override this method to
/// initialize some state or to play an animation.
void scrollStarted() { }
/// Similar to scrollStarted(). Called when a scroll ends. For fling scrolls
/// "ended" means that the scroll animation either stopped of its own accord
/// or was canceled by the user.
void scrollEnded() { }
}
class CompoundScrollableListPainter extends ScrollableListPainter {
CompoundScrollableListPainter(this.painters);
final List<ScrollableListPainter> painters;
@override
void attach(RenderObject renderObject) {
for(ScrollableListPainter painter in painters)
painter.attach(renderObject);
}
@override
void detach() {
for(ScrollableListPainter painter in painters)
painter.detach();
}
@override
void set contentExtent (double value) {
for(ScrollableListPainter painter in painters)
painter.contentExtent = value;
}
@override
void paint(PaintingContext context, Offset offset) {
for(ScrollableListPainter painter in painters)
painter.paint(context, offset);
}
@override
void set scrollOffset (double value) {
for(ScrollableListPainter painter in painters)
painter.scrollOffset = value;
}
@override
void scrollStarted() {
for(ScrollableListPainter painter in painters)
painter.scrollStarted();
}
@override
void scrollEnded() {
for(ScrollableListPainter painter in painters)
painter.scrollEnded();
}
}
......@@ -23,7 +23,6 @@ class ScrollableList extends Scrollable {
this.itemsWrap: false,
this.clampOverscrolls: false,
this.padding,
this.scrollableListPainter,
this.children
}) : super(
key: key,
......@@ -40,7 +39,6 @@ class ScrollableList extends Scrollable {
final bool itemsWrap;
final bool clampOverscrolls;
final EdgeInsets padding;
final ScrollableListPainter scrollableListPainter;
final Iterable<Widget> children;
@override
......@@ -55,7 +53,6 @@ class _ScrollableListState extends ScrollableState<ScrollableList> {
ExtentScrollBehavior get scrollBehavior => super.scrollBehavior;
void _handleExtentsChanged(double contentExtent, double containerExtent) {
config.scrollableListPainter?.contentExtent = contentExtent;
setState(() {
didUpdateScrollBehavior(scrollBehavior.updateExtents(
contentExtent: config.itemsWrap ? double.INFINITY : contentExtent,
......@@ -65,18 +62,6 @@ class _ScrollableListState extends ScrollableState<ScrollableList> {
});
}
@override
void dispatchOnScrollStart() {
super.dispatchOnScrollStart();
config.scrollableListPainter?.scrollStarted();
}
@override
void dispatchOnScroll() {
super.dispatchOnScroll();
config.scrollableListPainter?.scrollOffset = scrollOffset;
}
@override
Widget buildContent(BuildContext context) {
final double listScrollOffset = config.clampOverscrolls
......@@ -90,7 +75,6 @@ class _ScrollableListState extends ScrollableState<ScrollableList> {
itemExtent: config.itemExtent,
itemsWrap: config.itemsWrap,
padding: config.padding,
overlayPainter: config.scrollableListPainter,
children: config.children
);
}
......@@ -302,8 +286,7 @@ class ScrollableLazyList extends Scrollable {
this.itemExtent,
this.itemCount,
this.itemBuilder,
this.padding,
this.scrollableListPainter
this.padding
}) : super(
key: key,
initialScrollOffset: initialScrollOffset,
......@@ -321,7 +304,6 @@ class ScrollableLazyList extends Scrollable {
final int itemCount;
final ItemListBuilder itemBuilder;
final EdgeInsets padding;
final ScrollableListPainter scrollableListPainter;
@override
ScrollableState createState() => new _ScrollableLazyListState();
......@@ -335,7 +317,6 @@ class _ScrollableLazyListState extends ScrollableState<ScrollableLazyList> {
ExtentScrollBehavior get scrollBehavior => super.scrollBehavior;
void _handleExtentsChanged(double contentExtent, double containerExtent) {
config.scrollableListPainter?.contentExtent = contentExtent;
setState(() {
didUpdateScrollBehavior(scrollBehavior.updateExtents(
contentExtent: contentExtent,
......@@ -345,24 +326,6 @@ class _ScrollableLazyListState extends ScrollableState<ScrollableLazyList> {
});
}
@override
void dispatchOnScrollStart() {
super.dispatchOnScrollStart();
config.scrollableListPainter?.scrollStarted();
}
@override
void dispatchOnScroll() {
super.dispatchOnScroll();
config.scrollableListPainter?.scrollOffset = scrollOffset;
}
@override
void dispatchOnScrollEnd() {
super.dispatchOnScrollEnd();
config.scrollableListPainter?.scrollEnded();
}
@override
Widget buildContent(BuildContext context) {
return new LazyListViewport(
......@@ -373,8 +336,7 @@ class _ScrollableLazyListState extends ScrollableState<ScrollableLazyList> {
itemExtent: config.itemExtent,
itemCount: config.itemCount,
itemBuilder: config.itemBuilder,
padding: config.padding,
overlayPainter: config.scrollableListPainter
padding: config.padding
);
}
}
......
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