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

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

Issue 1092423003: [Effen] Reduce splashes when scrolling. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: fix comments from eseidel 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
« no previous file with comments | « sky/framework/components/ink_well.dart ('k') | sky/framework/fn.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 ScrollClient {
21 bool ancestorScrolled(Scrollable ancestor);
22 }
23
20 abstract class Scrollable extends Component { 24 abstract class Scrollable extends Component {
21 ScrollBehavior scrollBehavior; 25 ScrollBehavior scrollBehavior;
22 double get scrollOffset => _scrollOffset; 26 double get scrollOffset => _scrollOffset;
23 27
24 double _scrollOffset = 0.0; 28 double _scrollOffset = 0.0;
25 Simulation _simulation; 29 Simulation _simulation;
26 30
27 Scrollable({Object key, this.scrollBehavior}) : super(key: key) { 31 Scrollable({Object key, this.scrollBehavior}) : super(key: key) {
28 onDidUnmount(_stopSimulation); 32 onDidUnmount(_stopSimulation);
29 } 33 }
30 34
31 UINode buildContent(); 35 UINode buildContent();
32 36
33 UINode build() { 37 UINode build() {
34 return new EventListenerNode( 38 return new EventListenerNode(
35 buildContent(), 39 buildContent(),
36 onPointerDown: _handlePointerDown, 40 onPointerDown: _handlePointerDown,
37 onPointerUp: _handlePointerUpOrCancel, 41 onPointerUp: _handlePointerUpOrCancel,
38 onPointerCancel: _handlePointerUpOrCancel, 42 onPointerCancel: _handlePointerUpOrCancel,
39 onGestureFlingStart: _handleFlingStart, 43 onGestureFlingStart: _handleFlingStart,
40 onGestureFlingCancel: _handleFlingCancel, 44 onGestureFlingCancel: _handleFlingCancel,
41 onGestureScrollUpdate: _handleScrollUpdate, 45 onGestureScrollUpdate: _handleScrollUpdate,
42 onWheel: _handleWheel 46 onWheel: _handleWheel
43 ); 47 );
44 } 48 }
45 49
50 List<ScrollClient> _registeredScrollClients;
51
52 void registerScrollClient(ScrollClient notifiee) {
53 if (_registeredScrollClients == null)
54 _registeredScrollClients = new List<ScrollClient>();
55 setState(() {
56 _registeredScrollClients.add(notifiee);
57 });
58 }
59
60 void unregisterScrollClient(ScrollClient notifiee) {
61 if (_registeredScrollClients == null)
62 return;
63 setState(() {
64 _registeredScrollClients.remove(notifiee);
65 });
66 }
67
46 bool scrollTo(double newScrollOffset) { 68 bool scrollTo(double newScrollOffset) {
47 if (newScrollOffset == _scrollOffset) 69 if (newScrollOffset == _scrollOffset)
48 return false; 70 return false;
49 setState(() { 71 setState(() {
50 _scrollOffset = newScrollOffset; 72 _scrollOffset = newScrollOffset;
51 }); 73 });
74 if (_registeredScrollClients != null) {
75 var newList = null;
76 _registeredScrollClients.forEach((target) {
77 if (target.ancestorScrolled(this)) {
78 if (newList == null)
79 newList = new List<ScrollClient>();
80 newList.add(target);
81 }
82 });
83 setState(() {
84 _registeredScrollClients = newList;
85 });
86 }
52 return true; 87 return true;
53 } 88 }
54 89
55 bool scrollBy(double scrollDelta) { 90 bool scrollBy(double scrollDelta) {
56 var newScrollOffset = scrollBehavior.applyCurve(_scrollOffset, scrollDelta); 91 var newScrollOffset = scrollBehavior.applyCurve(_scrollOffset, scrollDelta);
57 return scrollTo(newScrollOffset); 92 return scrollTo(newScrollOffset);
58 } 93 }
59 94
60 void _stopSimulation() { 95 void _stopSimulation() {
61 if (_simulation == null) 96 if (_simulation == null)
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 } 129 }
95 130
96 void _handleFlingCancel(sky.GestureEvent event) { 131 void _handleFlingCancel(sky.GestureEvent event) {
97 _startSimulation(_createParticle()); 132 _startSimulation(_createParticle());
98 } 133 }
99 134
100 void _handleWheel(sky.WheelEvent event) { 135 void _handleWheel(sky.WheelEvent event) {
101 scrollBy(-event.offsetY); 136 scrollBy(-event.offsetY);
102 } 137 }
103 } 138 }
OLDNEW
« no previous file with comments | « sky/framework/components/ink_well.dart ('k') | sky/framework/fn.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698