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

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

Issue 993033003: Move example fn widgets into sky/framework/components (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
OLDNEW
1 part of widgets; 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/fling-curve.dart';
6 import '../fn.dart';
7 import 'dart:sky' as sky;
2 8
3 abstract class FixedHeightScrollable extends Component { 9 abstract class FixedHeightScrollable extends Component {
4
5 // TODO(rafaelw): This component really shouldn't have an opinion 10 // TODO(rafaelw): This component really shouldn't have an opinion
6 // about how it is sized. The owning component should decide whether 11 // about how it is sized. The owning component should decide whether
7 // it's explicitly sized or flexible or whatever... 12 // it's explicitly sized or flexible or whatever...
8 static Style _style = new Style(''' 13 static final Style _style = new Style('''
9 overflow: hidden; 14 overflow: hidden;
10 position: relative; 15 position: relative;
11 flex: 1; 16 flex: 1;
12 will-change: transform;''' 17 will-change: transform;'''
13 ); 18 );
14 19
15 static Style _scrollAreaStyle = new Style(''' 20 static final Style _scrollAreaStyle = new Style('''
16 position:relative; 21 position:relative;
17 will-change: transform;''' 22 will-change: transform;'''
18 ); 23 );
19 24
20 double minOffset; 25 double minOffset;
21 double maxOffset; 26 double maxOffset;
22 27
23 double _scrollOffset = 0.0; 28 double _scrollOffset = 0.0;
24 FlingCurve _flingCurve; 29 FlingCurve _flingCurve;
25 int _flingAnimationId; 30 int _flingAnimationId;
26 double _height = 0.0; 31 double _height = 0.0;
27 double _itemHeight; 32 double _itemHeight;
28 33
29 FixedHeightScrollable({ 34 FixedHeightScrollable({
30 Object key, 35 Object key,
31 this.minOffset, 36 this.minOffset,
32 this.maxOffset 37 this.maxOffset
33 }) : super(key: key) {} 38 }) : super(key: key) {
39 events.listen('gestureflingstart', _handleFlingStart);
40 events.listen('gestureflingcancel', _handleFlingCancel);
41 events.listen('gesturescrollupdate', _handleScrollUpdate);
42 events.listen('wheel', _handleWheel);
43 }
34 44
35 List<Node> buildItems(int start, int count); 45 List<Node> buildItems(int start, int count);
36 46
37 void didMount() { 47 void didMount() {
38 var root = getRoot(); 48 var root = getRoot();
39 var item = root.firstChild.firstChild; 49 var item = root.firstChild.firstChild;
40 sky.ClientRect scrollRect = root.getBoundingClientRect(); 50 sky.ClientRect scrollRect = root.getBoundingClientRect();
41 sky.ClientRect itemRect = item.getBoundingClientRect(); 51 sky.ClientRect itemRect = item.getBoundingClientRect();
42 assert(scrollRect.height > 0); 52 assert(scrollRect.height > 0);
43 assert(itemRect.height > 0); 53 assert(itemRect.height > 0);
(...skipping 25 matching lines...) Expand all
69 79
70 return new Container( 80 return new Container(
71 style: _style, 81 style: _style,
72 children: [ 82 children: [
73 new Container( 83 new Container(
74 style: _scrollAreaStyle, 84 style: _scrollAreaStyle,
75 inlineStyle: transformStyle, 85 inlineStyle: transformStyle,
76 children: buildItems(itemNumber, drawCount) 86 children: buildItems(itemNumber, drawCount)
77 ) 87 )
78 ] 88 ]
79 ) 89 );
80 ..events.listen('gestureflingstart', _handleFlingStart)
81 ..events.listen('gestureflingcancel', _handleFlingCancel)
82 ..events.listen('gesturescrollupdate', _handleScrollUpdate)
83 ..events.listen('wheel', _handleWheel);
84 } 90 }
85 91
86 void didUnmount() { 92 void didUnmount() {
87 _stopFling(); 93 _stopFling();
88 } 94 }
89 95
90 bool _scrollBy(double scrollDelta) { 96 bool _scrollBy(double scrollDelta) {
91 var newScrollOffset = _scrollOffset + scrollDelta; 97 var newScrollOffset = _scrollOffset + scrollDelta;
92 if (minOffset != null && newScrollOffset < minOffset) { 98 if (minOffset != null && newScrollOffset < minOffset) {
93 newScrollOffset = minOffset; 99 newScrollOffset = minOffset;
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 } 143 }
138 144
139 void _handleFlingCancel(sky.GestureEvent event) { 145 void _handleFlingCancel(sky.GestureEvent event) {
140 _stopFling(); 146 _stopFling();
141 } 147 }
142 148
143 void _handleWheel(sky.WheelEvent event) { 149 void _handleWheel(sky.WheelEvent event) {
144 _scrollBy(-event.offsetY); 150 _scrollBy(-event.offsetY);
145 } 151 }
146 } 152 }
OLDNEW
« no previous file with comments | « sky/framework/components/drawer_header.dart ('k') | sky/framework/components/floating_action_button.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698