Chromium Code Reviews| Index: sky/sdk/lib/widgets/variable_height_scrollable.dart |
| diff --git a/sky/sdk/lib/widgets/variable_height_scrollable.dart b/sky/sdk/lib/widgets/variable_height_scrollable.dart |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..60fed1fc3bce56da18e6eeafdf2b13a2ce1e3a77 |
| --- /dev/null |
| +++ b/sky/sdk/lib/widgets/variable_height_scrollable.dart |
| @@ -0,0 +1,68 @@ |
| +// Copyright 2015 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +import 'dart:collection'; |
| + |
| +import '../animation/scroll_behavior.dart'; |
| +import 'basic.dart'; |
| +import 'block_viewport.dart'; |
| +import 'scrollable.dart'; |
| +import 'widget.dart'; |
| + |
| +class VariableHeightScrollable extends Scrollable { |
| + VariableHeightScrollable({ |
| + String key, |
| + this.builder, |
| + this.token, |
| + this.itemCount |
|
Hixie
2015/07/10 20:55:11
Requiring that we pass this in implies this is a f
hansmuller
2015/07/10 22:42:50
Done.
|
| + }) : super(key: key); |
| + |
| + IndexedBuilder builder; |
| + Object token; |
| + int itemCount; |
| + |
| + void syncFields(VariableHeightScrollable source) { |
| + builder = source.builder; |
| + token = source.token; |
| + itemCount = source.itemCount; |
| + super.syncFields(source); |
| + } |
| + |
| + ScrollBehavior createScrollBehavior() => new OverscrollBehavior(); |
| + OverscrollBehavior get scrollBehavior => super.scrollBehavior; |
| + |
| + void _handleSizeChanged(Size newSize) { |
| + setState(() { |
| + scrollBehavior.containerHeight = newSize.height; |
| + }); |
| + } |
| + |
| + void _handleLayoutChanged(int startIndex, int childCount, UnmodifiableListView<double> offsets) { |
| + assert(offsets.length > 0); |
| + |
| + double contentsHeight = offsets.last; |
| + int contentsCount = offsets.length - 1; |
| + scrollBehavior.contentsHeight = contentsHeight; |
| + |
| + // We don't know the height of all items yet. Grow the ScrollBehavior's |
|
Hixie
2015/07/10 20:55:11
This isn't the right way to do this IMHO. We shoul
hansmuller
2015/07/10 22:42:50
I agree. I've updated OverScrollBehavior to handle
|
| + // contentsHeight a little, to accomodate scrolling further. |
| + if (contentsCount < itemCount) |
|
Hixie
2015/07/10 20:55:12
Rather than using itemCount and figuring out if we
hansmuller
2015/07/10 22:42:50
Good point. I've added a parameter to the onLayout
|
| + scrollBehavior.contentsHeight += scrollBehavior.containerHeight; |
| + |
| + if (scrollOffset > scrollBehavior.maxScrollOffset) |
| + settleScrollOffset(); |
| + } |
| + |
| + Widget buildContent() { |
| + return new SizeObserver( |
| + callback: _handleSizeChanged, |
| + child: new BlockViewport( |
| + builder: builder, |
| + onLayoutChanged: _handleLayoutChanged, |
| + startOffset: scrollOffset, |
| + token: token |
| + ) |
| + ); |
| + } |
| +} |