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

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

Issue 1097373002: [Effen] Prevent scrolling past the bottom of a scrollable list. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Move the creation of the OverscrollBehavior class to FixedHeightScrollable, since we already assumeā€¦ Created 5 years, 8 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
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_behavior.dart'; 5 import '../animation/scroll_behavior.dart';
6 import '../debug/tracing.dart'; 6 import '../debug/tracing.dart';
7 import '../fn.dart'; 7 import '../fn.dart';
8 import 'dart:math' as math; 8 import 'dart:math' as math;
9 import 'dart:sky' as sky; 9 import 'dart:sky' as sky;
10 import 'dart:async'; 10 import 'dart:async';
11 import 'scrollable.dart'; 11 import 'scrollable.dart';
12 import '../layouts/block.dart'; 12 import '../layouts/block.dart';
13 13
14 abstract class FixedHeightScrollable extends Scrollable { 14 abstract class FixedHeightScrollable extends Scrollable {
15 static final Style _style = new Style(''' 15 static final Style _style = new Style('''
16 overflow: hidden; 16 overflow: hidden;
17 position: relative; 17 position: relative;
18 will-change: transform;''' 18 will-change: transform;'''
19 ); 19 );
20 20
21 static final Style _scrollAreaStyle = new Style(''' 21 static final Style _scrollAreaStyle = new Style('''
22 position:relative; 22 position:relative;
23 will-change: transform;''' 23 will-change: transform;'''
24 ); 24 );
25 25
26 FixedHeightScrollable({
27 Object key
28 }) : super(key: key);
29
30 ScrollBehavior createScrollBehavior() => new OverscrollBehavior();
31
26 double _height = 0.0; 32 double _height = 0.0;
27 double _itemHeight; 33 double _itemHeight;
28 34
29 FixedHeightScrollable({ 35 int _itemCount = 0;
30 Object key, 36 int get itemCount => _itemCount;
31 ScrollBehavior scrollBehavior 37 void set itemCount (int value) {
32 }) : super(key: key, scrollBehavior: scrollBehavior); 38 if (_itemCount != value) {
39 _itemCount = value;
40 if (_itemHeight != null)
41 scrollBehavior.contentsHeight = _itemHeight * _itemCount;
42 }
43 }
33 44
34 void _measureHeights() { 45 void _measureHeights() {
35 trace('FixedHeightScrollable::_measureHeights', () { 46 trace('FixedHeightScrollable::_measureHeights', () {
36 if (_itemHeight != null) 47 if (_itemHeight != null)
37 return; 48 return;
38 var root = getRoot(); 49 var root = getRoot();
39 if (root == null) 50 if (root == null)
40 return; 51 return;
41 var item = root.firstChild.firstChild; 52 var item = root.firstChild.firstChild;
42 if (item == null) 53 if (item == null)
43 return; 54 return;
44 sky.ClientRect scrollRect = root.getBoundingClientRect(); 55 sky.ClientRect scrollRect = root.getBoundingClientRect();
45 sky.ClientRect itemRect = item.getBoundingClientRect(); 56 sky.ClientRect itemRect = item.getBoundingClientRect();
46 assert(scrollRect.height > 0); 57 assert(scrollRect.height > 0);
47 assert(itemRect.height > 0); 58 assert(itemRect.height > 0);
48 59
49 setState(() { 60 setState(() {
50 _height = scrollRect.height; 61 _height = scrollRect.height;
51 _itemHeight = itemRect.height; 62 _itemHeight = itemRect.height;
63 scrollBehavior.containerHeight = _height;
64 scrollBehavior.contentsHeight = _itemHeight * _itemCount;
52 }); 65 });
53 }); 66 });
54 } 67 }
55 68
56 UINode buildContent() { 69 UINode buildContent() {
57 var itemNumber = 0; 70 var itemNumber = 0;
58 var drawCount = 1; 71 var drawCount = 1;
59 var transformStyle = ''; 72 var transformStyle = '';
60 73
61 if (_itemHeight == null) 74 if (_itemHeight == null)
(...skipping 25 matching lines...) Expand all
87 children: [ 100 children: [
88 new BlockLayout( 101 new BlockLayout(
89 style: _scrollAreaStyle, 102 style: _scrollAreaStyle,
90 inlineStyle: transformStyle, 103 inlineStyle: transformStyle,
91 children: buildItems(itemNumber, drawCount) 104 children: buildItems(itemNumber, drawCount)
92 ) 105 )
93 ] 106 ]
94 ); 107 );
95 } 108 }
96 } 109 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698