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

Side by Side Diff: sky/framework/components/fixed_height_scrollable.dart

Issue 1002953003: Implement an OverscrollCurve for Scrollable (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 9 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/framework/animation/scroll_curve.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
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 '../animation/scroll_curve.dart'; 5 import '../animation/scroll_curve.dart';
6 import '../fn.dart'; 6 import '../fn.dart';
7 import 'dart:math' as math;
7 import 'dart:sky' as sky; 8 import 'dart:sky' as sky;
8 import 'scrollable.dart'; 9 import 'scrollable.dart';
9 10
10 abstract class FixedHeightScrollable extends Scrollable { 11 abstract class FixedHeightScrollable extends Scrollable {
11 // TODO(rafaelw): This component really shouldn't have an opinion 12 // TODO(rafaelw): This component really shouldn't have an opinion
12 // about how it is sized. The owning component should decide whether 13 // about how it is sized. The owning component should decide whether
13 // it's explicitly sized or flexible or whatever... 14 // it's explicitly sized or flexible or whatever...
14 static final Style _style = new Style(''' 15 static final Style _style = new Style('''
15 overflow: hidden; 16 overflow: hidden;
16 position: relative; 17 position: relative;
(...skipping 28 matching lines...) Expand all
45 _itemHeight = itemRect.height; 46 _itemHeight = itemRect.height;
46 }); 47 });
47 } 48 }
48 49
49 Node build() { 50 Node build() {
50 var itemNumber = 0; 51 var itemNumber = 0;
51 var drawCount = 1; 52 var drawCount = 1;
52 var transformStyle = ''; 53 var transformStyle = '';
53 54
54 if (_height > 0.0) { 55 if (_height > 0.0) {
55 drawCount = (_height / _itemHeight).round() + 1; 56 if (scrollOffset < 0.0) {
56 double alignmentDelta = -scrollOffset % _itemHeight; 57 double visibleHeight = _height + scrollOffset;
57 if (alignmentDelta != 0.0) { 58 drawCount = (visibleHeight / _itemHeight).round() + 1;
58 alignmentDelta -= _itemHeight; 59 transformStyle =
60 'transform: translateY(${(-scrollOffset).toStringAsFixed(2)}px)';
61 } else {
62 drawCount = (_height / _itemHeight).round() + 1;
63 double alignmentOffset = math.max(0.0, scrollOffset);
64 double alignmentDelta = -scrollOffset % _itemHeight;
65 if (alignmentDelta != 0.0)
66 alignmentDelta -= _itemHeight;
67
68 double drawStart = scrollOffset + alignmentDelta;
69 itemNumber = (drawStart / _itemHeight).floor();
70
71 transformStyle =
72 'transform: translateY(${(alignmentDelta).toStringAsFixed(2)}px)';
59 } 73 }
60
61 double drawStart = scrollOffset + alignmentDelta;
62 itemNumber = (drawStart / _itemHeight).floor();
63
64 transformStyle =
65 'transform: translateY(${(alignmentDelta).toStringAsFixed(2)}px)';
66 } 74 }
67 75
68 return new Container( 76 return new Container(
69 styles: [_style], 77 styles: [_style],
70 children: [ 78 children: [
71 new Container( 79 new Container(
72 styles: [_scrollAreaStyle], 80 styles: [_scrollAreaStyle],
73 inlineStyle: transformStyle, 81 inlineStyle: transformStyle,
74 children: buildItems(itemNumber, drawCount) 82 children: buildItems(itemNumber, drawCount)
75 ) 83 )
76 ] 84 ]
77 ); 85 );
78 } 86 }
79 } 87 }
OLDNEW
« no previous file with comments | « sky/framework/animation/scroll_curve.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698