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

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

Issue 1226373003: demo_launcher/lib/main.dart does not have bottom-overscroll (Closed) Base URL: git@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/animation/scroll_behavior.dart ('k') | sky/sdk/lib/widgets/scrollable.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 import 'dart:math' as math; 5 import 'dart:math' as math;
6 6
7 import 'package:vector_math/vector_math.dart'; 7 import 'package:vector_math/vector_math.dart';
8 8
9 import '../animation/scroll_behavior.dart'; 9 import '../animation/scroll_behavior.dart';
10 import 'basic.dart'; 10 import 'basic.dart';
11 import 'scrollable.dart'; 11 import 'scrollable.dart';
12 12
13 abstract class FixedHeightScrollable extends Scrollable { 13 abstract class FixedHeightScrollable extends Scrollable {
14 14
15 FixedHeightScrollable({ String key, this.itemHeight, Color backgroundColor, th is.padding }) 15 FixedHeightScrollable({ String key, this.itemHeight, Color backgroundColor, th is.padding })
16 : super(key: key, backgroundColor: backgroundColor) { 16 : super(key: key, backgroundColor: backgroundColor) {
17 assert(itemHeight != null); 17 assert(itemHeight != null);
18 } 18 }
19 19
20 EdgeDims padding; 20 EdgeDims padding;
21 double itemHeight; 21 double itemHeight;
22 22
23 /// Subclasses must implement `get itemCount` to tell FixedHeightScrollable 23 /// Subclasses must implement `get itemCount` to tell FixedHeightScrollable
24 /// how many items there are in the list. 24 /// how many items there are in the list.
25 int get itemCount; 25 int get itemCount;
26 int _previousItemCount;
26 27
27 void syncFields(FixedHeightScrollable source) { 28 void syncFields(FixedHeightScrollable source) {
28 padding = source.padding; 29 padding = source.padding;
29 itemHeight = source.itemHeight; 30 itemHeight = source.itemHeight;
30 super.syncFields(source); 31 super.syncFields(source);
31 } 32 }
32 33
33 ScrollBehavior createScrollBehavior() => new OverscrollBehavior(); 34 ScrollBehavior createScrollBehavior() => new OverscrollBehavior();
34 OverscrollBehavior get scrollBehavior => super.scrollBehavior; 35 OverscrollBehavior get scrollBehavior => super.scrollBehavior;
35 36
36 double _height; 37 double _height;
37 void _handleSizeChanged(Size newSize) { 38 void _handleSizeChanged(Size newSize) {
38 setState(() { 39 setState(() {
39 _height = newSize.height; 40 _height = newSize.height;
40 scrollBehavior.containerHeight = _height; 41 scrollBehavior.containerHeight = _height;
41 }); 42 });
42 } 43 _updateScrollOffset();
eseidel 2015/07/09 20:40:07 Unneeded.
43
44 bool scrollTo(double newScrollOffset) {
45 if (_height != null && _height > 0.0) {
46 double maxScrollOffset = math.max(0.0, itemCount * itemHeight - _height);
47 newScrollOffset = math.min(newScrollOffset, maxScrollOffset);
48 }
49 return super.scrollTo(newScrollOffset);
50 } 44 }
51 45
52 void _updateContentsHeight() { 46 void _updateContentsHeight() {
53 double contentsHeight = itemHeight * itemCount; 47 double contentsHeight = itemHeight * itemCount;
54 if (padding != null) 48 if (padding != null)
55 contentsHeight += padding.top + padding.bottom; 49 contentsHeight += padding.top + padding.bottom;
56 scrollBehavior.contentsHeight = contentsHeight; 50 scrollBehavior.contentsHeight = contentsHeight;
57 } 51 }
58 52
53 void _updateScrollOffset() {
54 if (scrollOffset > scrollBehavior.maxScrollOffset)
55 settleScrollOffset();
56 }
57
59 Widget buildContent() { 58 Widget buildContent() {
60 _updateContentsHeight(); 59 if (itemCount != _previousItemCount) {
60 _previousItemCount = itemCount;
61 _updateContentsHeight();
62 _updateScrollOffset();
63 }
61 64
62 var itemShowIndex = 0; 65 var itemShowIndex = 0;
63 var itemShowCount = 0; 66 var itemShowCount = 0;
64 Matrix4 transform = new Matrix4.identity(); 67 Matrix4 transform = new Matrix4.identity();
65 68
66 if (_height != null && _height > 0.0) { 69 if (_height != null && _height > 0.0) {
67 if (scrollOffset < 0.0) { 70 if (scrollOffset < 0.0) {
68 double visibleHeight = _height + scrollOffset; 71 double visibleHeight = _height + scrollOffset;
69 itemShowCount = (visibleHeight / itemHeight).round() + 1; 72 itemShowCount = (visibleHeight / itemHeight).round() + 1;
70 transform.translate(0.0, -scrollOffset); 73 transform.translate(0.0, -scrollOffset);
(...skipping 23 matching lines...) Expand all
94 child: new Block(items) 97 child: new Block(items)
95 ) 98 )
96 ) 99 )
97 ) 100 )
98 ); 101 );
99 } 102 }
100 103
101 List<Widget> buildItems(int start, int count); 104 List<Widget> buildItems(int start, int count);
102 105
103 } 106 }
OLDNEW
« no previous file with comments | « sky/sdk/lib/animation/scroll_behavior.dart ('k') | sky/sdk/lib/widgets/scrollable.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698