| 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; |
| 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 events.listen('pointerdown', _handlePointerDown); | 28 |
| 29 events.listen('pointerup', _handlePointerUpOrCancel); | 29 Node buildContent(); |
| 30 events.listen('pointercancel', _handlePointerUpOrCancel); | 30 |
| 31 events.listen('gestureflingstart', _handleFlingStart); | 31 Node build() { |
| 32 events.listen('gestureflingcancel', _handleFlingCancel); | 32 return new EventTarget( |
| 33 events.listen('gesturescrollupdate', _handleScrollUpdate); | 33 buildContent(), |
| 34 events.listen('wheel', _handleWheel); | 34 onPointerDown: _handlePointerDown, |
| 35 onPointerUp: _handlePointerUpOrCancel, |
| 36 onPointerCancel: _handlePointerUpOrCancel, |
| 37 onGestureFlingStart: _handleFlingStart, |
| 38 onGestureFlingCancel: _handleFlingCancel, |
| 39 onGestureScrollUpdate: _handleScrollUpdate, |
| 40 onWheel: _handleWheel |
| 41 ); |
| 35 } | 42 } |
| 36 | 43 |
| 37 void didUnmount() { | 44 void didUnmount() { |
| 38 super.didUnmount(); | 45 super.didUnmount(); |
| 39 _stopSimulation(); | 46 _stopSimulation(); |
| 40 } | 47 } |
| 41 | 48 |
| 42 bool scrollBy(double scrollDelta) { | 49 bool scrollBy(double scrollDelta) { |
| 43 var newScrollOffset = scrollBehavior.applyCurve(_scrollOffset, scrollDelta); | 50 var newScrollOffset = scrollBehavior.applyCurve(_scrollOffset, scrollDelta); |
| 44 if (newScrollOffset == _scrollOffset) | 51 if (newScrollOffset == _scrollOffset) |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 } | 97 } |
| 91 | 98 |
| 92 void _handleFlingCancel(sky.GestureEvent event) { | 99 void _handleFlingCancel(sky.GestureEvent event) { |
| 93 _startSimulation(_createParticle()); | 100 _startSimulation(_createParticle()); |
| 94 } | 101 } |
| 95 | 102 |
| 96 void _handleWheel(sky.WheelEvent event) { | 103 void _handleWheel(sky.WheelEvent event) { |
| 97 scrollBy(-event.offsetY); | 104 scrollBy(-event.offsetY); |
| 98 } | 105 } |
| 99 } | 106 } |
| OLD | NEW |