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 ...@@ -1075,7 +1075,6 @@ class _TabBarViewState<T> extends PageableListState<TabBarView<T>> implements Ta
itemsWrap: config.itemsWrap, itemsWrap: config.itemsWrap,
mainAxis: config.scrollDirection, mainAxis: config.scrollDirection,
startOffset: scrollOffset, startOffset: scrollOffset,
overlayPainter: config.scrollableListPainter,
children: _items children: _items
); );
} }
......
...@@ -6,7 +6,6 @@ import 'dart:math' as math; ...@@ -6,7 +6,6 @@ import 'dart:math' as math;
import 'box.dart'; import 'box.dart';
import 'object.dart'; import 'object.dart';
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> { }
...@@ -25,8 +24,7 @@ typedef double _Constrainer(double value); ...@@ -25,8 +24,7 @@ typedef double _Constrainer(double value);
/// viewport with a scrolling direction that matches the block's main axis. /// viewport with a scrolling direction that matches the block's main axis.
class RenderBlock extends RenderBox class RenderBlock extends RenderBox
with ContainerRenderObjectMixin<RenderBox, BlockParentData>, with ContainerRenderObjectMixin<RenderBox, BlockParentData>,
RenderBoxContainerDefaultsMixin<RenderBox, BlockParentData> RenderBoxContainerDefaultsMixin<RenderBox, BlockParentData> {
implements HasMainAxis {
RenderBlock({ RenderBlock({
List<RenderBox> children, List<RenderBox> children,
...@@ -42,7 +40,6 @@ class RenderBlock extends RenderBox ...@@ -42,7 +40,6 @@ class RenderBlock extends RenderBox
} }
/// The direction to use as the main axis. /// The direction to use as the main axis.
@override
Axis get mainAxis => _mainAxis; Axis get mainAxis => _mainAxis;
Axis _mainAxis; Axis _mainAxis;
void set mainAxis (Axis value) { void set mainAxis (Axis value) {
......
...@@ -73,18 +73,12 @@ class ViewportDimensions { ...@@ -73,18 +73,12 @@ class ViewportDimensions {
String toString() => 'ViewportDimensions(container: $containerSize, content: $contentSize)'; 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. /// 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 /// 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 /// have a child model. See [RenderViewport] for a viewport with a single child
/// and [RenderVirtualViewport] for a viewport with multiple children. /// and [RenderVirtualViewport] for a viewport with multiple children.
class RenderViewportBase extends RenderBox implements HasMainAxis { class RenderViewportBase extends RenderBox {
RenderViewportBase( RenderViewportBase(
Offset paintOffset, Offset paintOffset,
Axis mainAxis, Axis mainAxis,
...@@ -128,7 +122,6 @@ class RenderViewportBase extends RenderBox implements HasMainAxis { ...@@ -128,7 +122,6 @@ class RenderViewportBase extends RenderBox implements HasMainAxis {
/// The child is given layout constraints that are fully unconstrainted along /// 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 /// the main axis (e.g., the child can be as tall as it wants if the main axis
/// is vertical). /// is vertical).
@override
Axis get mainAxis => _mainAxis; Axis get mainAxis => _mainAxis;
Axis _mainAxis; Axis _mainAxis;
void set mainAxis(Axis value) { void set mainAxis(Axis value) {
......
...@@ -35,7 +35,6 @@ class PageableList extends Scrollable { ...@@ -35,7 +35,6 @@ class PageableList extends Scrollable {
this.itemsWrap: false, this.itemsWrap: false,
this.itemsSnapAlignment: PageableListFlingBehavior.stopAtNextPage, this.itemsSnapAlignment: PageableListFlingBehavior.stopAtNextPage,
this.onPageChanged, this.onPageChanged,
this.scrollableListPainter,
this.duration: const Duration(milliseconds: 200), this.duration: const Duration(milliseconds: 200),
this.curve: Curves.ease, this.curve: Curves.ease,
this.children this.children
...@@ -61,9 +60,6 @@ class PageableList extends Scrollable { ...@@ -61,9 +60,6 @@ class PageableList extends Scrollable {
/// Called when the currently visible page changes. /// Called when the currently visible page changes.
final ValueChanged<int> onPageChanged; final ValueChanged<int> onPageChanged;
/// Used to paint the scrollbar for this list.
final ScrollableListPainter scrollableListPainter;
/// The duration used when animating to a given page. /// The duration used when animating to a given page.
final Duration duration; final Duration duration;
...@@ -146,7 +142,6 @@ class PageableListState<T extends PageableList> extends ScrollableState<T> { ...@@ -146,7 +142,6 @@ class PageableListState<T extends PageableList> extends ScrollableState<T> {
} }
void _updateScrollBehavior() { void _updateScrollBehavior() {
config.scrollableListPainter?.contentExtent = _itemCount.toDouble();
didUpdateScrollBehavior(scrollBehavior.updateExtents( didUpdateScrollBehavior(scrollBehavior.updateExtents(
contentExtent: _itemCount.toDouble(), contentExtent: _itemCount.toDouble(),
containerExtent: 1.0, containerExtent: 1.0,
...@@ -154,24 +149,6 @@ class PageableListState<T extends PageableList> extends ScrollableState<T> { ...@@ -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 @override
Widget buildContent(BuildContext context) { Widget buildContent(BuildContext context) {
return new PageViewport( return new PageViewport(
...@@ -179,7 +156,6 @@ class PageableListState<T extends PageableList> extends ScrollableState<T> { ...@@ -179,7 +156,6 @@ class PageableListState<T extends PageableList> extends ScrollableState<T> {
mainAxis: config.scrollDirection, mainAxis: config.scrollDirection,
anchor: config.scrollAnchor, anchor: config.scrollAnchor,
startOffset: scrollOffset, startOffset: scrollOffset,
overlayPainter: config.scrollableListPainter,
children: config.children children: config.children
); );
} }
......
...@@ -8,7 +8,6 @@ import 'dart:ui' as ui show window; ...@@ -8,7 +8,6 @@ import 'dart:ui' as ui show window;
import 'package:newton/newton.dart'; import 'package:newton/newton.dart';
import 'package:flutter/gestures.dart'; import 'package:flutter/gestures.dart';
import 'package:flutter/rendering.dart' show HasMainAxis;
import 'basic.dart'; import 'basic.dart';
import 'framework.dart'; import 'framework.dart';
...@@ -764,100 +763,3 @@ class Block extends StatelessWidget { ...@@ -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 { ...@@ -23,7 +23,6 @@ class ScrollableList extends Scrollable {
this.itemsWrap: false, this.itemsWrap: false,
this.clampOverscrolls: false, this.clampOverscrolls: false,
this.padding, this.padding,
this.scrollableListPainter,
this.children this.children
}) : super( }) : super(
key: key, key: key,
...@@ -40,7 +39,6 @@ class ScrollableList extends Scrollable { ...@@ -40,7 +39,6 @@ class ScrollableList extends Scrollable {
final bool itemsWrap; final bool itemsWrap;
final bool clampOverscrolls; final bool clampOverscrolls;
final EdgeInsets padding; final EdgeInsets padding;
final ScrollableListPainter scrollableListPainter;
final Iterable<Widget> children; final Iterable<Widget> children;
@override @override
...@@ -55,7 +53,6 @@ class _ScrollableListState extends ScrollableState<ScrollableList> { ...@@ -55,7 +53,6 @@ class _ScrollableListState extends ScrollableState<ScrollableList> {
ExtentScrollBehavior get scrollBehavior => super.scrollBehavior; ExtentScrollBehavior get scrollBehavior => super.scrollBehavior;
void _handleExtentsChanged(double contentExtent, double containerExtent) { void _handleExtentsChanged(double contentExtent, double containerExtent) {
config.scrollableListPainter?.contentExtent = contentExtent;
setState(() { setState(() {
didUpdateScrollBehavior(scrollBehavior.updateExtents( didUpdateScrollBehavior(scrollBehavior.updateExtents(
contentExtent: config.itemsWrap ? double.INFINITY : contentExtent, contentExtent: config.itemsWrap ? double.INFINITY : contentExtent,
...@@ -65,18 +62,6 @@ class _ScrollableListState extends ScrollableState<ScrollableList> { ...@@ -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 @override
Widget buildContent(BuildContext context) { Widget buildContent(BuildContext context) {
final double listScrollOffset = config.clampOverscrolls final double listScrollOffset = config.clampOverscrolls
...@@ -90,7 +75,6 @@ class _ScrollableListState extends ScrollableState<ScrollableList> { ...@@ -90,7 +75,6 @@ class _ScrollableListState extends ScrollableState<ScrollableList> {
itemExtent: config.itemExtent, itemExtent: config.itemExtent,
itemsWrap: config.itemsWrap, itemsWrap: config.itemsWrap,
padding: config.padding, padding: config.padding,
overlayPainter: config.scrollableListPainter,
children: config.children children: config.children
); );
} }
...@@ -302,8 +286,7 @@ class ScrollableLazyList extends Scrollable { ...@@ -302,8 +286,7 @@ class ScrollableLazyList extends Scrollable {
this.itemExtent, this.itemExtent,
this.itemCount, this.itemCount,
this.itemBuilder, this.itemBuilder,
this.padding, this.padding
this.scrollableListPainter
}) : super( }) : super(
key: key, key: key,
initialScrollOffset: initialScrollOffset, initialScrollOffset: initialScrollOffset,
...@@ -321,7 +304,6 @@ class ScrollableLazyList extends Scrollable { ...@@ -321,7 +304,6 @@ class ScrollableLazyList extends Scrollable {
final int itemCount; final int itemCount;
final ItemListBuilder itemBuilder; final ItemListBuilder itemBuilder;
final EdgeInsets padding; final EdgeInsets padding;
final ScrollableListPainter scrollableListPainter;
@override @override
ScrollableState createState() => new _ScrollableLazyListState(); ScrollableState createState() => new _ScrollableLazyListState();
...@@ -335,7 +317,6 @@ class _ScrollableLazyListState extends ScrollableState<ScrollableLazyList> { ...@@ -335,7 +317,6 @@ class _ScrollableLazyListState extends ScrollableState<ScrollableLazyList> {
ExtentScrollBehavior get scrollBehavior => super.scrollBehavior; ExtentScrollBehavior get scrollBehavior => super.scrollBehavior;
void _handleExtentsChanged(double contentExtent, double containerExtent) { void _handleExtentsChanged(double contentExtent, double containerExtent) {
config.scrollableListPainter?.contentExtent = contentExtent;
setState(() { setState(() {
didUpdateScrollBehavior(scrollBehavior.updateExtents( didUpdateScrollBehavior(scrollBehavior.updateExtents(
contentExtent: contentExtent, contentExtent: contentExtent,
...@@ -345,24 +326,6 @@ class _ScrollableLazyListState extends ScrollableState<ScrollableLazyList> { ...@@ -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 @override
Widget buildContent(BuildContext context) { Widget buildContent(BuildContext context) {
return new LazyListViewport( return new LazyListViewport(
...@@ -373,8 +336,7 @@ class _ScrollableLazyListState extends ScrollableState<ScrollableLazyList> { ...@@ -373,8 +336,7 @@ class _ScrollableLazyListState extends ScrollableState<ScrollableLazyList> {
itemExtent: config.itemExtent, itemExtent: config.itemExtent,
itemCount: config.itemCount, itemCount: config.itemCount,
itemBuilder: config.itemBuilder, itemBuilder: config.itemBuilder,
padding: config.padding, padding: config.padding
overlayPainter: config.scrollableListPainter
); );
} }
} }
......
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