Commit 6fd68597 authored by Adam Barth's avatar Adam Barth

LazyBlock docs and physics

This patch adds dartdoc to LazyBlock. Also, this patch fixes the scrolling
physics of LazyBlock. Previously, we updated a running simulation only when the
change in scroll behavior changed the current scroll offset. Now we update
running simulations every time the behavior changes because the simulation
might depend on quantities other than the current scroll offset.
parent 0bf68cc5
...@@ -418,7 +418,7 @@ class CardCollectionState extends State<CardCollection> { ...@@ -418,7 +418,7 @@ class CardCollectionState extends State<CardCollection> {
); );
} else { } else {
cardCollection = new LazyBlock( cardCollection = new LazyBlock(
delegate: new LazyBlockBuilder(_buildCard), delegate: new LazyBlockBuilder(builder: _buildCard),
snapOffsetCallback: _snapToCenter ? _toSnapOffset : null snapOffsetCallback: _snapToCenter ? _toSnapOffset : null
); );
} }
......
...@@ -130,7 +130,7 @@ class CardBuilder extends LazyBlockDelegate { ...@@ -130,7 +130,7 @@ class CardBuilder extends LazyBlockDelegate {
class OverlayGeometryAppState extends State<OverlayGeometryApp> { class OverlayGeometryAppState extends State<OverlayGeometryApp> {
List<CardModel> cardModels; List<CardModel> cardModels;
Map<MarkerType, Point> markers = new Map<MarkerType, Point>(); Map<MarkerType, Point> markers = new Map<MarkerType, Point>();
double markersScrollOffset; double markersScrollOffset = 0.0;
ScrollListener scrollListener; ScrollListener scrollListener;
@override @override
......
...@@ -125,9 +125,9 @@ class RenderViewportBase extends RenderBox implements HasMainAxis { ...@@ -125,9 +125,9 @@ class RenderViewportBase extends RenderBox implements HasMainAxis {
/// The direction in which the child is permitted to be larger than the viewport /// The direction in which the child is permitted to be larger than the viewport
/// ///
/// If the viewport is scrollable in a particular direction (e.g., vertically), /// The child is given layout constraints that are fully unconstrainted along
/// the child is given layout constraints that are fully unconstrainted in /// the main axis (e.g., the child can be as tall as it wants if the main axis
/// that direction (e.g., the child can be as tall as it wants). /// is vertical).
@override @override
Axis get mainAxis => _mainAxis; Axis get mainAxis => _mainAxis;
Axis _mainAxis; Axis _mainAxis;
......
...@@ -1013,9 +1013,9 @@ class Viewport extends SingleChildRenderObjectWidget { ...@@ -1013,9 +1013,9 @@ class Viewport extends SingleChildRenderObjectWidget {
/// The direction in which the child is permitted to be larger than the viewport /// The direction in which the child is permitted to be larger than the viewport
/// ///
/// If the viewport is scrollable in a particular direction (e.g., vertically), /// The child is given layout constraints that are fully unconstrainted along
/// the child is given layout constraints that are fully unconstrainted in /// the main axis (e.g., the child can be as tall as it wants if the main axis
/// that direction (e.g., the child can be as tall as it wants). /// is vertical).
final Axis mainAxis; final Axis mainAxis;
final ViewportAnchor anchor; final ViewportAnchor anchor;
...@@ -1025,6 +1025,7 @@ class Viewport extends SingleChildRenderObjectWidget { ...@@ -1025,6 +1025,7 @@ class Viewport extends SingleChildRenderObjectWidget {
/// Often used to paint scroll bars. /// Often used to paint scroll bars.
final RenderObjectPainter overlayPainter; final RenderObjectPainter overlayPainter;
/// Called when the interior or exterior dimensions of the viewport change.
final ViewportDimensionsChangeCallback onPaintOffsetUpdateNeeded; final ViewportDimensionsChangeCallback onPaintOffsetUpdateNeeded;
@override @override
......
...@@ -162,7 +162,7 @@ abstract class AnimatedWidgetBaseState<T extends ImplicitlyAnimatedWidget> exten ...@@ -162,7 +162,7 @@ abstract class AnimatedWidgetBaseState<T extends ImplicitlyAnimatedWidget> exten
} }
/// Subclasses must implement this function by running through the following /// Subclasses must implement this function by running through the following
/// steps for for each animatable facet in the class: /// steps for each animatable facet in the class:
/// ///
/// 1. Call the visitor callback with three arguments, the first argument /// 1. Call the visitor callback with three arguments, the first argument
/// being the current value of the Tween<T> object that represents the /// being the current value of the Tween<T> object that represents the
......
...@@ -379,9 +379,16 @@ abstract class ScrollableState<T extends Scrollable> extends State<T> { ...@@ -379,9 +379,16 @@ abstract class ScrollableState<T extends Scrollable> extends State<T> {
return _controller.animateTo(newScrollOffset, duration: duration, curve: curve).then(_endScroll); return _controller.animateTo(newScrollOffset, duration: duration, curve: curve).then(_endScroll);
} }
/// Update any in-progress scrolling physics to account for new scroll behavior.
///
/// The scrolling physics depends on the scroll behavior. When changing the
/// scrolling behavior, call this function to update any in-progress scrolling
/// physics to account for the new scroll behavior. This function preserves
/// the current velocity when updating the physics.
///
/// If there are no in-progress scrolling physics, this function scrolls to
/// the given offset instead.
void didUpdateScrollBehavior(double newScrollOffset) { void didUpdateScrollBehavior(double newScrollOffset) {
if (newScrollOffset == _scrollOffset)
return;
if (_numberOfInProgressScrolls > 0) { if (_numberOfInProgressScrolls > 0) {
if (_simulation != null) { if (_simulation != null) {
double dx = _simulation.dx(_controller.lastElapsedDuration.inMicroseconds / Duration.MICROSECONDS_PER_SECOND); double dx = _simulation.dx(_controller.lastElapsedDuration.inMicroseconds / Duration.MICROSECONDS_PER_SECOND);
......
...@@ -126,8 +126,8 @@ class _GridViewportElement extends VirtualViewportElement { ...@@ -126,8 +126,8 @@ class _GridViewportElement extends VirtualViewportElement {
super.updateRenderObject(oldWidget); super.updateRenderObject(oldWidget);
} }
double _contentExtent; double _lastReportedContentExtent;
double _containerExtent; double _lastReportedContainerExtent;
GridSpecification _specification; GridSpecification _specification;
@override @override
...@@ -146,10 +146,10 @@ class _GridViewportElement extends VirtualViewportElement { ...@@ -146,10 +146,10 @@ class _GridViewportElement extends VirtualViewportElement {
super.layout(constraints); super.layout(constraints);
if (contentExtent != _contentExtent || containerExtent != _containerExtent) { if (contentExtent != _lastReportedContentExtent || containerExtent != _lastReportedContainerExtent) {
_contentExtent = contentExtent; _lastReportedContentExtent = contentExtent;
_containerExtent = containerExtent; _lastReportedContainerExtent = containerExtent;
widget.onExtentsChanged(_contentExtent, _containerExtent); widget.onExtentsChanged(_lastReportedContentExtent, _lastReportedContainerExtent);
} }
} }
} }
...@@ -192,8 +192,8 @@ class _VirtualListViewportElement extends VirtualViewportElement { ...@@ -192,8 +192,8 @@ class _VirtualListViewportElement extends VirtualViewportElement {
super.updateRenderObject(oldWidget); super.updateRenderObject(oldWidget);
} }
double _contentExtent; double _lastReportedContentExtent;
double _containerExtent; double _lastReportedContainerExtent;
@override @override
void layout(BoxConstraints constraints) { void layout(BoxConstraints constraints) {
...@@ -253,10 +253,10 @@ class _VirtualListViewportElement extends VirtualViewportElement { ...@@ -253,10 +253,10 @@ class _VirtualListViewportElement extends VirtualViewportElement {
super.layout(constraints); super.layout(constraints);
if (contentExtent != _contentExtent || containerExtent != _containerExtent) { if (contentExtent != _lastReportedContentExtent || containerExtent != _lastReportedContainerExtent) {
_contentExtent = contentExtent; _lastReportedContentExtent = contentExtent;
_containerExtent = containerExtent; _lastReportedContainerExtent = containerExtent;
widget.onExtentsChanged(_contentExtent, _containerExtent); widget.onExtentsChanged(_lastReportedContentExtent, _lastReportedContainerExtent);
} }
} }
} }
......
...@@ -23,7 +23,7 @@ Widget buildCard(BuildContext context, int index) { ...@@ -23,7 +23,7 @@ Widget buildCard(BuildContext context, int index) {
Widget buildFrame() { Widget buildFrame() {
return new LazyBlock( return new LazyBlock(
delegate: new LazyBlockBuilder(buildCard) delegate: new LazyBlockBuilder(builder: buildCard)
); );
} }
......
...@@ -100,7 +100,7 @@ class TexturedLinePainter { ...@@ -100,7 +100,7 @@ class TexturedLinePainter {
List<Vector2> miters = _computeMiterList(vectors, false); List<Vector2> miters = _computeMiterList(vectors, false);
List<Point> vertices = <Point>[]; List<Point> vertices = <Point>[];
List<int> indicies = <int>[]; List<int> indices = <int>[];
List<Color> verticeColors = <Color>[]; List<Color> verticeColors = <Color>[];
List<Point> textureCoordinates; List<Point> textureCoordinates;
double textureTop; double textureTop;
...@@ -151,8 +151,8 @@ class TexturedLinePainter { ...@@ -151,8 +151,8 @@ class TexturedLinePainter {
int lastIndex1 = (i - 1) * 2 + 1; int lastIndex1 = (i - 1) * 2 + 1;
int currentIndex0 = i * 2; int currentIndex0 = i * 2;
int currentIndex1 = i * 2 + 1; int currentIndex1 = i * 2 + 1;
indicies.addAll(<int>[lastIndex0, lastIndex1, currentIndex0]); indices.addAll(<int>[lastIndex0, lastIndex1, currentIndex0]);
indicies.addAll(<int>[lastIndex1, currentIndex1, currentIndex0]); indices.addAll(<int>[lastIndex1, currentIndex1, currentIndex0]);
// Add colors // Add colors
verticeColors.add(colors[i]); verticeColors.add(colors[i]);
...@@ -170,7 +170,7 @@ class TexturedLinePainter { ...@@ -170,7 +170,7 @@ class TexturedLinePainter {
lastMiter = currentMiter; lastMiter = currentMiter;
} }
canvas.drawVertices(VertexMode.triangles, vertices, textureCoordinates, verticeColors, TransferMode.modulate, indicies, _cachedPaint); canvas.drawVertices(VertexMode.triangles, vertices, textureCoordinates, verticeColors, TransferMode.modulate, indices, _cachedPaint);
} }
double _xPosForStop(double stop) { double _xPosForStop(double stop) {
......
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