| 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:sky/animation/scroll_behavior.dart'; | 7 import 'package:sky/animation/scroll_behavior.dart'; |
| 8 import 'package:sky/widgets/basic.dart'; | 8 import 'package:sky/widgets/basic.dart'; |
| 9 import 'package:sky/widgets/scrollable.dart'; | 9 import 'package:sky/widgets/scrollable.dart'; |
| 10 | 10 |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 | 54 |
| 55 Widget buildContent() { | 55 Widget buildContent() { |
| 56 if (itemCount != _previousItemCount) { | 56 if (itemCount != _previousItemCount) { |
| 57 _previousItemCount = itemCount; | 57 _previousItemCount = itemCount; |
| 58 _updateContentsHeight(); | 58 _updateContentsHeight(); |
| 59 _updateScrollOffset(); | 59 _updateScrollOffset(); |
| 60 } | 60 } |
| 61 | 61 |
| 62 int itemShowIndex = 0; | 62 int itemShowIndex = 0; |
| 63 int itemShowCount = 0; | 63 int itemShowCount = 0; |
| 64 | |
| 65 double offsetY = 0.0; | 64 double offsetY = 0.0; |
| 66 | |
| 67 if (_height != null && _height > 0.0) { | 65 if (_height != null && _height > 0.0) { |
| 68 if (scrollOffset < 0.0) { | 66 if (scrollOffset < 0.0) { |
| 69 double visibleHeight = _height + scrollOffset; | 67 double visibleHeight = _height + scrollOffset; |
| 70 itemShowCount = (visibleHeight / itemHeight).round() + 1; | 68 itemShowCount = (visibleHeight / itemHeight).round() + 1; |
| 71 offsetY = scrollOffset; | 69 offsetY = scrollOffset; |
| 72 } else { | 70 } else { |
| 73 itemShowCount = (_height / itemHeight).ceil() + 1; | 71 itemShowCount = (_height / itemHeight).ceil(); |
| 74 double alignmentDelta = -scrollOffset % itemHeight; | 72 double alignmentDelta = -scrollOffset % itemHeight; |
| 75 if (alignmentDelta != 0.0) | 73 double drawStart; |
| 74 if (alignmentDelta != 0.0) { |
| 76 alignmentDelta -= itemHeight; | 75 alignmentDelta -= itemHeight; |
| 77 | 76 itemShowCount += 1; |
| 78 double drawStart = scrollOffset + alignmentDelta; | 77 drawStart = scrollOffset + alignmentDelta; |
| 78 offsetY = -alignmentDelta; |
| 79 } else { |
| 80 drawStart = scrollOffset; |
| 81 } |
| 79 itemShowIndex = math.max(0, (drawStart / itemHeight).floor()); | 82 itemShowIndex = math.max(0, (drawStart / itemHeight).floor()); |
| 80 | |
| 81 offsetY = -alignmentDelta; | |
| 82 } | 83 } |
| 83 } | 84 } |
| 84 | 85 |
| 85 List<Widget> items = buildItems(itemShowIndex, itemShowCount); | 86 List<Widget> items = buildItems(itemShowIndex, itemShowCount); |
| 86 assert(items.every((item) => item.key != null)); | 87 assert(items.every((item) => item.key != null)); |
| 87 | 88 |
| 88 // TODO(ianh): Refactor this so that it does the building in the | 89 // TODO(ianh): Refactor this so that it does the building in the |
| 89 // same frame as the size observing, similar to BlockViewport, but | 90 // same frame as the size observing, similar to BlockViewport, but |
| 90 // keeping the fixed-height optimisations. | 91 // keeping the fixed-height optimisations. |
| 91 return new SizeObserver( | 92 return new SizeObserver( |
| 92 callback: _handleSizeChanged, | 93 callback: _handleSizeChanged, |
| 93 child: new Viewport( | 94 child: new Viewport( |
| 94 offset: offsetY, | 95 offset: offsetY, |
| 95 child: new Container( | 96 child: new Container( |
| 96 padding: padding, | 97 padding: padding, |
| 97 child: new Block(items) | 98 child: new Block(items) |
| 98 ) | 99 ) |
| 99 ) | 100 ) |
| 100 ); | 101 ); |
| 101 } | 102 } |
| 102 | 103 |
| 103 List<Widget> buildItems(int start, int count); | 104 List<Widget> buildItems(int start, int count); |
| 104 | 105 |
| 105 } | 106 } |
| OLD | NEW |