OLD | NEW |
| (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 '../animation/scroll_behavior.dart'; | |
6 import '../fn2.dart'; | |
7 import 'dart:async'; | |
8 import 'dart:math' as math; | |
9 import 'package:vector_math/vector_math.dart'; | |
10 import 'scrollable.dart'; | |
11 | |
12 abstract class FixedHeightScrollable extends Scrollable { | |
13 | |
14 FixedHeightScrollable({ this.itemHeight, Object key }) : super(key: key) { | |
15 assert(itemHeight != null); | |
16 } | |
17 | |
18 double itemHeight; | |
19 | |
20 void syncFields(FixedHeightScrollable source) { | |
21 itemHeight = source.itemHeight; | |
22 super.syncFields(source); | |
23 } | |
24 | |
25 ScrollBehavior createScrollBehavior() => new OverscrollBehavior(); | |
26 OverscrollBehavior get scrollBehavior => super.scrollBehavior as OverscrollBeh
avior; | |
27 | |
28 int _itemCount = 0; | |
29 int get itemCount => _itemCount; | |
30 void set itemCount (int value) { | |
31 if (_itemCount != value) { | |
32 _itemCount = value; | |
33 scrollBehavior.contentsHeight = itemHeight * _itemCount; | |
34 } | |
35 } | |
36 | |
37 double _height; | |
38 void _handleSizeChanged(Size newSize) { | |
39 setState(() { | |
40 _height = newSize.height; | |
41 scrollBehavior.containerHeight = _height; | |
42 }); | |
43 } | |
44 | |
45 UINode buildContent() { | |
46 var itemShowIndex = 0; | |
47 var itemShowCount = 0; | |
48 | |
49 Matrix4 transform = new Matrix4.identity(); | |
50 | |
51 if (_height != null && _height > 0.0) { | |
52 if (scrollOffset < 0.0) { | |
53 double visibleHeight = _height + scrollOffset; | |
54 itemShowCount = (visibleHeight / itemHeight).round() + 1; | |
55 transform.translate(0.0, -scrollOffset); | |
56 } else { | |
57 itemShowCount = (_height / itemHeight).ceil() + 1; | |
58 double alignmentDelta = -scrollOffset % itemHeight; | |
59 if (alignmentDelta != 0.0) | |
60 alignmentDelta -= itemHeight; | |
61 | |
62 double drawStart = scrollOffset + alignmentDelta; | |
63 itemShowIndex = math.max(0, (drawStart / itemHeight).floor()); | |
64 | |
65 transform.translate(0.0, alignmentDelta); | |
66 } | |
67 } | |
68 | |
69 return new SizeObserver( | |
70 callback: _handleSizeChanged, | |
71 child: new ClipRect( | |
72 child: new DecoratedBox( | |
73 decoration: const BoxDecoration( | |
74 backgroundColor: const Color(0xFFFFFFFF) | |
75 ), | |
76 child: new Transform( | |
77 transform: transform, | |
78 child: new Block(buildItems(itemShowIndex, itemShowCount)) | |
79 ) | |
80 ) | |
81 ) | |
82 ); | |
83 } | |
84 | |
85 List<UINode> buildItems(int start, int count); | |
86 | |
87 } | |
OLD | NEW |