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

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

Issue 1074033002: Added Scrollable.scrollTo() (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: 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 | « no previous file | no next file » | 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;
(...skipping 25 matching lines...) Expand all
36 onPointerDown: _handlePointerDown, 36 onPointerDown: _handlePointerDown,
37 onPointerUp: _handlePointerUpOrCancel, 37 onPointerUp: _handlePointerUpOrCancel,
38 onPointerCancel: _handlePointerUpOrCancel, 38 onPointerCancel: _handlePointerUpOrCancel,
39 onGestureFlingStart: _handleFlingStart, 39 onGestureFlingStart: _handleFlingStart,
40 onGestureFlingCancel: _handleFlingCancel, 40 onGestureFlingCancel: _handleFlingCancel,
41 onGestureScrollUpdate: _handleScrollUpdate, 41 onGestureScrollUpdate: _handleScrollUpdate,
42 onWheel: _handleWheel 42 onWheel: _handleWheel
43 ); 43 );
44 } 44 }
45 45
46 bool scrollBy(double scrollDelta) { 46 bool scrollTo(double newScrollOffset) {
47 var newScrollOffset = scrollBehavior.applyCurve(_scrollOffset, scrollDelta);
48 if (newScrollOffset == _scrollOffset) 47 if (newScrollOffset == _scrollOffset)
49 return false; 48 return false;
50 setState(() { 49 setState(() {
51 _scrollOffset = newScrollOffset; 50 _scrollOffset = newScrollOffset;
52 }); 51 });
53 return true; 52 return true;
54 } 53 }
55 54
55 bool scrollBy(double scrollDelta) {
56 var newScrollOffset = scrollBehavior.applyCurve(_scrollOffset, scrollDelta);
57 return scrollTo(newScrollOffset);
58 }
59
56 void _stopSimulation() { 60 void _stopSimulation() {
57 if (_simulation == null) 61 if (_simulation == null)
58 return; 62 return;
59 _simulation.cancel(); 63 _simulation.cancel();
60 _simulation = null; 64 _simulation = null;
61 } 65 }
62 66
63 void _startSimulation(Particle particle) { 67 void _startSimulation(Particle particle) {
64 _stopSimulation(); 68 _stopSimulation();
65 _simulation = scrollBehavior.release(particle); 69 _simulation = scrollBehavior.release(particle);
(...skipping 28 matching lines...) Expand all
94 } 98 }
95 99
96 void _handleFlingCancel(sky.GestureEvent event) { 100 void _handleFlingCancel(sky.GestureEvent event) {
97 _startSimulation(_createParticle()); 101 _startSimulation(_createParticle());
98 } 102 }
99 103
100 void _handleWheel(sky.WheelEvent event) { 104 void _handleWheel(sky.WheelEvent event) {
101 scrollBy(-event.offsetY); 105 scrollBy(-event.offsetY);
102 } 106 }
103 } 107 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698