Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(301)

Side by Side Diff: sky/sdk/lib/widgets/variable_height_scrollable.dart

Issue 1227823012: Move VariableHeightScrollable to sdk/lib/widgets (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « sky/sdk/lib/widgets/block_viewport.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 import 'dart:collection';
6
7 import '../animation/scroll_behavior.dart';
8 import 'basic.dart';
9 import 'block_viewport.dart';
10 import 'scrollable.dart';
11 import 'widget.dart';
12
13 class VariableHeightScrollable extends Scrollable {
14 VariableHeightScrollable({
15 String key,
16 this.builder,
17 this.token,
18 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.
19 }) : super(key: key);
20
21 IndexedBuilder builder;
22 Object token;
23 int itemCount;
24
25 void syncFields(VariableHeightScrollable source) {
26 builder = source.builder;
27 token = source.token;
28 itemCount = source.itemCount;
29 super.syncFields(source);
30 }
31
32 ScrollBehavior createScrollBehavior() => new OverscrollBehavior();
33 OverscrollBehavior get scrollBehavior => super.scrollBehavior;
34
35 void _handleSizeChanged(Size newSize) {
36 setState(() {
37 scrollBehavior.containerHeight = newSize.height;
38 });
39 }
40
41 void _handleLayoutChanged(int startIndex, int childCount, UnmodifiableListView <double> offsets) {
42 assert(offsets.length > 0);
43
44 double contentsHeight = offsets.last;
45 int contentsCount = offsets.length - 1;
46 scrollBehavior.contentsHeight = contentsHeight;
47
48 // 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
49 // contentsHeight a little, to accomodate scrolling further.
50 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
51 scrollBehavior.contentsHeight += scrollBehavior.containerHeight;
52
53 if (scrollOffset > scrollBehavior.maxScrollOffset)
54 settleScrollOffset();
55 }
56
57 Widget buildContent() {
58 return new SizeObserver(
59 callback: _handleSizeChanged,
60 child: new BlockViewport(
61 builder: builder,
62 onLayoutChanged: _handleLayoutChanged,
63 startOffset: scrollOffset,
64 token: token
65 )
66 );
67 }
68 }
OLDNEW
« no previous file with comments | « sky/sdk/lib/widgets/block_viewport.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698