OLD | NEW |
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'; | |
8 | |
9 import '../animation/scroll_behavior.dart'; | 7 import '../animation/scroll_behavior.dart'; |
10 import 'basic.dart'; | 8 import 'basic.dart'; |
11 import 'scrollable.dart'; | 9 import 'scrollable.dart'; |
12 | 10 |
13 abstract class FixedHeightScrollable extends Scrollable { | 11 abstract class FixedHeightScrollable extends Scrollable { |
14 | 12 |
15 FixedHeightScrollable({ String key, this.itemHeight, Color backgroundColor, th
is.padding }) | 13 FixedHeightScrollable({ String key, this.itemHeight, Color backgroundColor, th
is.padding }) |
16 : super(key: key, backgroundColor: backgroundColor) { | 14 : super(key: key, backgroundColor: backgroundColor) { |
17 assert(itemHeight != null); | 15 assert(itemHeight != null); |
18 } | 16 } |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 settleScrollOffset(); | 52 settleScrollOffset(); |
55 } | 53 } |
56 | 54 |
57 Widget buildContent() { | 55 Widget buildContent() { |
58 if (itemCount != _previousItemCount) { | 56 if (itemCount != _previousItemCount) { |
59 _previousItemCount = itemCount; | 57 _previousItemCount = itemCount; |
60 _updateContentsHeight(); | 58 _updateContentsHeight(); |
61 _updateScrollOffset(); | 59 _updateScrollOffset(); |
62 } | 60 } |
63 | 61 |
64 var itemShowIndex = 0; | 62 int itemShowIndex = 0; |
65 var itemShowCount = 0; | 63 int itemShowCount = 0; |
66 Matrix4 transform = new Matrix4.identity(); | 64 |
| 65 double offsetY = 0.0; |
67 | 66 |
68 if (_height != null && _height > 0.0) { | 67 if (_height != null && _height > 0.0) { |
69 if (scrollOffset < 0.0) { | 68 if (scrollOffset < 0.0) { |
70 double visibleHeight = _height + scrollOffset; | 69 double visibleHeight = _height + scrollOffset; |
71 itemShowCount = (visibleHeight / itemHeight).round() + 1; | 70 itemShowCount = (visibleHeight / itemHeight).round() + 1; |
72 transform.translate(0.0, -scrollOffset); | 71 offsetY = scrollOffset; |
73 } else { | 72 } else { |
74 itemShowCount = (_height / itemHeight).ceil() + 1; | 73 itemShowCount = (_height / itemHeight).ceil() + 1; |
75 double alignmentDelta = -scrollOffset % itemHeight; | 74 double alignmentDelta = -scrollOffset % itemHeight; |
76 if (alignmentDelta != 0.0) | 75 if (alignmentDelta != 0.0) |
77 alignmentDelta -= itemHeight; | 76 alignmentDelta -= itemHeight; |
78 | 77 |
79 double drawStart = scrollOffset + alignmentDelta; | 78 double drawStart = scrollOffset + alignmentDelta; |
80 itemShowIndex = math.max(0, (drawStart / itemHeight).floor()); | 79 itemShowIndex = math.max(0, (drawStart / itemHeight).floor()); |
81 | 80 |
82 transform.translate(0.0, alignmentDelta); | 81 offsetY = -alignmentDelta; |
83 } | 82 } |
84 } | 83 } |
85 | 84 |
86 List<Widget> items = buildItems(itemShowIndex, itemShowCount); | 85 List<Widget> items = buildItems(itemShowIndex, itemShowCount); |
87 assert(items.every((item) => item.key != null)); | 86 assert(items.every((item) => item.key != null)); |
88 | 87 |
89 return new SizeObserver( | 88 return new SizeObserver( |
90 callback: _handleSizeChanged, | 89 callback: _handleSizeChanged, |
91 child: new ClipRect( | 90 child: new Viewport( |
92 child: new Transform( | 91 offset: offsetY, |
93 transform: transform, | 92 child: new Container( |
94 child: new Container( | 93 padding: padding, |
95 padding: padding, | 94 child: new Block(items) |
96 child: new Block(items) | |
97 ) | |
98 ) | 95 ) |
99 ) | 96 ) |
100 ); | 97 ); |
101 } | 98 } |
102 | 99 |
103 List<Widget> buildItems(int start, int count); | 100 List<Widget> buildItems(int start, int count); |
104 | 101 |
105 } | 102 } |
OLD | NEW |