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

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

Issue 1027633003: [Effen] Add AnimatedComponent base class (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: cr changes 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/components/popup_menu_item.dart ('k') | sky/framework/editing/editable_text.dart » ('j') | 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/generators.dart'; 5 import '../animation/generators.dart';
6 import '../animation/mechanics.dart'; 6 import '../animation/mechanics.dart';
7 import '../animation/scroll_behavior.dart'; 7 import '../animation/scroll_behavior.dart';
8 import '../fn.dart'; 8 import '../fn.dart';
9 import '../theme/view-configuration.dart' as config; 9 import '../theme/view-configuration.dart' as config;
10 import 'dart:math' as math; 10 import 'dart:math' as math;
11 import 'dart:sky' as sky; 11 import 'dart:sky' as sky;
12 12
13 const double _kMillisecondsPerSecond = 1000.0; 13 const double _kMillisecondsPerSecond = 1000.0;
14 14
15 double _velocityForFlingGesture(sky.GestureEvent event) { 15 double _velocityForFlingGesture(sky.GestureEvent event) {
16 return math.max(-config.kMaxFlingVelocity, math.min(config.kMaxFlingVelocity, 16 return math.max(-config.kMaxFlingVelocity, math.min(config.kMaxFlingVelocity,
17 -event.velocityY)) / _kMillisecondsPerSecond; 17 -event.velocityY)) / _kMillisecondsPerSecond;
18 } 18 }
19 19
20 abstract class Scrollable extends Component { 20 abstract class Scrollable extends Component {
21 ScrollBehavior scrollBehavior; 21 ScrollBehavior scrollBehavior;
22 double get scrollOffset => _scrollOffset; 22 double get scrollOffset => _scrollOffset;
23 23
24 double _scrollOffset = 0.0; 24 double _scrollOffset = 0.0;
25 Simulation _simulation; 25 Simulation _simulation;
26 26
27 Scrollable({Object key, this.scrollBehavior}) : super(key: key); 27 Scrollable({Object key, this.scrollBehavior}) : super(key: key) {
28 onDidUnmount(_stopSimulation);
29 }
28 30
29 Node buildContent(); 31 Node buildContent();
30 32
31 Node build() { 33 Node build() {
32 return new EventTarget( 34 return new EventTarget(
33 buildContent(), 35 buildContent(),
34 onPointerDown: _handlePointerDown, 36 onPointerDown: _handlePointerDown,
35 onPointerUp: _handlePointerUpOrCancel, 37 onPointerUp: _handlePointerUpOrCancel,
36 onPointerCancel: _handlePointerUpOrCancel, 38 onPointerCancel: _handlePointerUpOrCancel,
37 onGestureFlingStart: _handleFlingStart, 39 onGestureFlingStart: _handleFlingStart,
38 onGestureFlingCancel: _handleFlingCancel, 40 onGestureFlingCancel: _handleFlingCancel,
39 onGestureScrollUpdate: _handleScrollUpdate, 41 onGestureScrollUpdate: _handleScrollUpdate,
40 onWheel: _handleWheel 42 onWheel: _handleWheel
41 ); 43 );
42 } 44 }
43 45
44 void didUnmount() {
45 super.didUnmount();
46 _stopSimulation();
47 }
48
49 bool scrollBy(double scrollDelta) { 46 bool scrollBy(double scrollDelta) {
50 var newScrollOffset = scrollBehavior.applyCurve(_scrollOffset, scrollDelta); 47 var newScrollOffset = scrollBehavior.applyCurve(_scrollOffset, scrollDelta);
51 if (newScrollOffset == _scrollOffset) 48 if (newScrollOffset == _scrollOffset)
52 return false; 49 return false;
53 setState(() { 50 setState(() {
54 _scrollOffset = newScrollOffset; 51 _scrollOffset = newScrollOffset;
55 }); 52 });
56 return true; 53 return true;
57 } 54 }
58 55
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 } 94 }
98 95
99 void _handleFlingCancel(sky.GestureEvent event) { 96 void _handleFlingCancel(sky.GestureEvent event) {
100 _startSimulation(_createParticle()); 97 _startSimulation(_createParticle());
101 } 98 }
102 99
103 void _handleWheel(sky.WheelEvent event) { 100 void _handleWheel(sky.WheelEvent event) {
104 scrollBy(-event.offsetY); 101 scrollBy(-event.offsetY);
105 } 102 }
106 } 103 }
OLDNEW
« no previous file with comments | « sky/framework/components/popup_menu_item.dart ('k') | sky/framework/editing/editable_text.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698