| Index: sky/sdk/lib/widgets/scrollable.dart
|
| diff --git a/sky/sdk/lib/widgets/scrollable.dart b/sky/sdk/lib/widgets/scrollable.dart
|
| index a6c4023a356507f47251fd4354077a9ef3b1ee9c..34e1e07e1eafe0017bba18bea7301954a47a3f1a 100644
|
| --- a/sky/sdk/lib/widgets/scrollable.dart
|
| +++ b/sky/sdk/lib/widgets/scrollable.dart
|
| @@ -2,7 +2,6 @@
|
| // Use of this source code is governed by a BSD-style license that can be
|
| // found in the LICENSE file.
|
|
|
| -import 'dart:math' as math;
|
| import 'dart:sky' as sky;
|
|
|
| import '../animation/generators.dart';
|
| @@ -14,24 +13,31 @@ import 'material.dart';
|
|
|
| const double _kMillisecondsPerSecond = 1000.0;
|
|
|
| -double _velocityForFlingGesture(sky.GestureEvent event) {
|
| - return math.max(-config.kMaxFlingVelocity, math.min(config.kMaxFlingVelocity,
|
| - -event.velocityY)) / _kMillisecondsPerSecond;
|
| +double _velocityForFlingGesture(double eventVelocity) {
|
| + return eventVelocity.clamp(-config.kMaxFlingVelocity, config.kMaxFlingVelocity) /
|
| + _kMillisecondsPerSecond;
|
| }
|
|
|
| abstract class ScrollClient {
|
| bool ancestorScrolled(Scrollable ancestor);
|
| }
|
|
|
| +enum ScrollDirection { vertical, horizontal }
|
| +
|
| abstract class Scrollable extends Component {
|
|
|
| - Scrollable({ String key, Color this.backgroundColor })
|
| - : super(key: key, stateful: true);
|
| + Scrollable({
|
| + String key,
|
| + this.backgroundColor,
|
| + this.direction: ScrollDirection.vertical
|
| + }) : super(key: key, stateful: true);
|
|
|
| Color backgroundColor;
|
| + ScrollDirection direction;
|
|
|
| void syncFields(Scrollable source) {
|
| backgroundColor = source.backgroundColor;
|
| + direction == source.direction;
|
| }
|
|
|
| double _scrollOffset = 0.0;
|
| @@ -145,11 +151,14 @@ abstract class Scrollable extends Component {
|
| }
|
|
|
| void _handleScrollUpdate(sky.GestureEvent event) {
|
| - scrollBy(-event.dy);
|
| + scrollBy(direction == ScrollDirection.horizontal ? event.dx : -event.dy);
|
| }
|
|
|
| void _handleFlingStart(sky.GestureEvent event) {
|
| - _startSimulation(_createParticle(_velocityForFlingGesture(event)));
|
| + double eventVelocity = direction == ScrollDirection.horizontal
|
| + ? -event.velocityX
|
| + : -event.velocityY;
|
| + _startSimulation(_createParticle(_velocityForFlingGesture(eventVelocity)));
|
| }
|
|
|
| void _handleFlingCancel(sky.GestureEvent event) {
|
|
|