diff --git a/packages/flutter/lib/animation/animation_performance.dart b/packages/flutter/lib/animation/animation_performance.dart index 88cb67fb32..9e21b1261f 100644 --- a/packages/flutter/lib/animation/animation_performance.dart +++ b/packages/flutter/lib/animation/animation_performance.dart @@ -98,8 +98,10 @@ class AnimationPerformance { Future forward() => play(Direction.forward); Future reverse() => play(Direction.reverse); Future resume() { - if (attachedForce != null) - return fling(_direction, force: attachedForce); + if (attachedForce != null) { + return fling(velocity: _direction == Direction.forward ? 1.0 : -1.0, + force: attachedForce); + } return _animateTo(direction == Direction.forward ? 1.0 : 0.0); } @@ -107,13 +109,14 @@ class AnimationPerformance { timeline.stop(); } - // Flings the timeline in the given direction with an optional force - // (defaults to a critically damped spring) and initial velocity. - Future fling(Direction direction, {double velocity: 0.0, Force force}) { + // Flings the timeline with an optional force (defaults to a critically + // damped spring) and initial velocity. If velocity is positive, the + // animation will complete, otherwise it will dismiss. + Future fling({double velocity: 1.0, Force force}) { if (force == null) force = kDefaultSpringForce; - _direction = direction; - return timeline.fling(force.release(progress, velocity, _direction)); + _direction = velocity < 0.0 ? Direction.reverse : Direction.forward; + return timeline.fling(force.release(progress, velocity)); } final List _listeners = new List(); diff --git a/packages/flutter/lib/animation/forces.dart b/packages/flutter/lib/animation/forces.dart index 7bfeeb1636..cf5f53a2a1 100644 --- a/packages/flutter/lib/animation/forces.dart +++ b/packages/flutter/lib/animation/forces.dart @@ -3,11 +3,10 @@ // found in the LICENSE file. import 'package:newton/newton.dart'; -import 'package:sky/animation/direction.dart'; // Base class for creating Simulations for the animation Timeline. abstract class Force { - Simulation release(double position, double velocity, Direction direction); + Simulation release(double position, double velocity); } class SpringForce extends Force { @@ -24,8 +23,8 @@ class SpringForce extends Force { // respectively. final double left, right; - Simulation release(double position, double velocity, Direction direction) { - double target = direction == Direction.reverse ? + Simulation release(double position, double velocity) { + double target = velocity < 0.0 ? this.left - tolerance.distance : this.right + tolerance.distance; return new SpringSimulation(spring, position, target, velocity) ..tolerance = tolerance; diff --git a/packages/flutter/lib/widgets/dismissable.dart b/packages/flutter/lib/widgets/dismissable.dart index db7ca639f2..3c06b361ae 100644 --- a/packages/flutter/lib/widgets/dismissable.dart +++ b/packages/flutter/lib/widgets/dismissable.dart @@ -153,7 +153,7 @@ class Dismissable extends StatefulComponent { if (_isHorizontalFlingGesture(event)) { _dragUnderway = false; _dragX = event.velocityX.sign; - _fadePerformance.fling(Direction.forward, velocity: event.velocityX.abs() * _kFlingVelocityScale); + _fadePerformance.fling(velocity: event.velocityX.abs() * _kFlingVelocityScale); } return EventDisposition.processed; } diff --git a/packages/flutter/lib/widgets/drawer.dart b/packages/flutter/lib/widgets/drawer.dart index cbf68fa466..b1772a96d1 100644 --- a/packages/flutter/lib/widgets/drawer.dart +++ b/packages/flutter/lib/widgets/drawer.dart @@ -171,9 +171,7 @@ class Drawer extends StatefulComponent { EventDisposition handleFlingStart(event) { if (event.velocityX.abs() >= _kMinFlingVelocity) { - _performance.fling( - event.velocityX < 0.0 ? Direction.reverse : Direction.forward, - velocity: event.velocityX.abs() * _kFlingVelocityScale); + _performance.fling(velocity: event.velocityX * _kFlingVelocityScale); return EventDisposition.processed; } return EventDisposition.ignored;