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

Side by Side Diff: sky/sdk/lib/framework/components2/scrollable.dart

Issue 1175753003: Kill onDidMount()/onDidUnmount() in favour of just overriding the relevant methods. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 years, 6 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/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 '../fn2.dart'; 8 import '../fn2.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 ScrollClient { 20 abstract class ScrollClient {
21 bool ancestorScrolled(Scrollable ancestor); 21 bool ancestorScrolled(Scrollable ancestor);
22 } 22 }
23 23
24 abstract class Scrollable extends Component { 24 abstract class Scrollable extends Component {
25 25
26 Scrollable({Object key}) : super(key: key, stateful: true) { 26 Scrollable({Object key}) : super(key: key, stateful: true);
27 onDidUnmount(_stopSimulation);
28 }
29 27
30 void syncFields(Scrollable source) { } 28 void syncFields(Scrollable source) { }
31 29
32 double _scrollOffset = 0.0; 30 double _scrollOffset = 0.0;
33 double get scrollOffset => _scrollOffset; 31 double get scrollOffset => _scrollOffset;
34 32
35 ScrollBehavior _scrollBehavior; 33 ScrollBehavior _scrollBehavior;
36 ScrollBehavior createScrollBehavior(); 34 ScrollBehavior createScrollBehavior();
37 ScrollBehavior get scrollBehavior { 35 ScrollBehavior get scrollBehavior {
38 if (_scrollBehavior == null) 36 if (_scrollBehavior == null)
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 }); 93 });
96 } 94 }
97 return true; 95 return true;
98 } 96 }
99 97
100 bool scrollBy(double scrollDelta) { 98 bool scrollBy(double scrollDelta) {
101 var newScrollOffset = scrollBehavior.applyCurve(_scrollOffset, scrollDelta); 99 var newScrollOffset = scrollBehavior.applyCurve(_scrollOffset, scrollDelta);
102 return scrollTo(newScrollOffset); 100 return scrollTo(newScrollOffset);
103 } 101 }
104 102
103 void didUnmount() {
104 _stopSimulation();
105 super.didUnmount();
106 }
107
105 void _stopSimulation() { 108 void _stopSimulation() {
106 if (_simulation == null) 109 if (_simulation == null)
107 return; 110 return;
108 _simulation.cancel(); 111 _simulation.cancel();
109 _simulation = null; 112 _simulation = null;
110 } 113 }
111 114
112 void _startSimulation(Particle particle) { 115 void _startSimulation(Particle particle) {
113 _stopSimulation(); 116 _stopSimulation();
114 _simulation = scrollBehavior.release(particle); 117 _simulation = scrollBehavior.release(particle);
(...skipping 25 matching lines...) Expand all
140 143
141 void _handleFlingCancel(sky.GestureEvent event) { 144 void _handleFlingCancel(sky.GestureEvent event) {
142 _startSimulation(_createParticle()); 145 _startSimulation(_createParticle());
143 } 146 }
144 147
145 void _handleWheel(sky.WheelEvent event) { 148 void _handleWheel(sky.WheelEvent event) {
146 scrollBy(-event.offsetY); 149 scrollBy(-event.offsetY);
147 } 150 }
148 151
149 } 152 }
OLDNEW
« no previous file with comments | « sky/sdk/lib/framework/components2/popup_menu.dart ('k') | sky/sdk/lib/framework/editing2/editable_text.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698