| OLD | NEW |
| 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 Loading... |
| 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 Loading... |
| 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 } |
| OLD | NEW |