Commit de7d8efc authored by Matt Perry's avatar Matt Perry

Get rid of the Direction parameter for animation Forces.

Just infer it from the sign of the velocity. That's what odeon does.
parent e4b8d8a8
...@@ -98,8 +98,10 @@ class AnimationPerformance { ...@@ -98,8 +98,10 @@ class AnimationPerformance {
Future forward() => play(Direction.forward); Future forward() => play(Direction.forward);
Future reverse() => play(Direction.reverse); Future reverse() => play(Direction.reverse);
Future resume() { Future resume() {
if (attachedForce != null) if (attachedForce != null) {
return fling(_direction, force: attachedForce); return fling(velocity: _direction == Direction.forward ? 1.0 : -1.0,
force: attachedForce);
}
return _animateTo(direction == Direction.forward ? 1.0 : 0.0); return _animateTo(direction == Direction.forward ? 1.0 : 0.0);
} }
...@@ -107,13 +109,14 @@ class AnimationPerformance { ...@@ -107,13 +109,14 @@ class AnimationPerformance {
timeline.stop(); timeline.stop();
} }
// Flings the timeline in the given direction with an optional force // Flings the timeline with an optional force (defaults to a critically
// (defaults to a critically damped spring) and initial velocity. // damped spring) and initial velocity. If velocity is positive, the
Future fling(Direction direction, {double velocity: 0.0, Force force}) { // animation will complete, otherwise it will dismiss.
Future fling({double velocity: 1.0, Force force}) {
if (force == null) if (force == null)
force = kDefaultSpringForce; force = kDefaultSpringForce;
_direction = direction; _direction = velocity < 0.0 ? Direction.reverse : Direction.forward;
return timeline.fling(force.release(progress, velocity, _direction)); return timeline.fling(force.release(progress, velocity));
} }
final List<Function> _listeners = new List<Function>(); final List<Function> _listeners = new List<Function>();
......
...@@ -3,11 +3,10 @@ ...@@ -3,11 +3,10 @@
// found in the LICENSE file. // found in the LICENSE file.
import 'package:newton/newton.dart'; import 'package:newton/newton.dart';
import 'package:sky/animation/direction.dart';
// Base class for creating Simulations for the animation Timeline. // Base class for creating Simulations for the animation Timeline.
abstract class Force { abstract class Force {
Simulation release(double position, double velocity, Direction direction); Simulation release(double position, double velocity);
} }
class SpringForce extends Force { class SpringForce extends Force {
...@@ -24,8 +23,8 @@ class SpringForce extends Force { ...@@ -24,8 +23,8 @@ class SpringForce extends Force {
// respectively. // respectively.
final double left, right; final double left, right;
Simulation release(double position, double velocity, Direction direction) { Simulation release(double position, double velocity) {
double target = direction == Direction.reverse ? double target = velocity < 0.0 ?
this.left - tolerance.distance : this.right + tolerance.distance; this.left - tolerance.distance : this.right + tolerance.distance;
return new SpringSimulation(spring, position, target, velocity) return new SpringSimulation(spring, position, target, velocity)
..tolerance = tolerance; ..tolerance = tolerance;
......
...@@ -153,7 +153,7 @@ class Dismissable extends StatefulComponent { ...@@ -153,7 +153,7 @@ class Dismissable extends StatefulComponent {
if (_isHorizontalFlingGesture(event)) { if (_isHorizontalFlingGesture(event)) {
_dragUnderway = false; _dragUnderway = false;
_dragX = event.velocityX.sign; _dragX = event.velocityX.sign;
_fadePerformance.fling(Direction.forward, velocity: event.velocityX.abs() * _kFlingVelocityScale); _fadePerformance.fling(velocity: event.velocityX.abs() * _kFlingVelocityScale);
} }
return EventDisposition.processed; return EventDisposition.processed;
} }
......
...@@ -171,9 +171,7 @@ class Drawer extends StatefulComponent { ...@@ -171,9 +171,7 @@ class Drawer extends StatefulComponent {
EventDisposition handleFlingStart(event) { EventDisposition handleFlingStart(event) {
if (event.velocityX.abs() >= _kMinFlingVelocity) { if (event.velocityX.abs() >= _kMinFlingVelocity) {
_performance.fling( _performance.fling(velocity: event.velocityX * _kFlingVelocityScale);
event.velocityX < 0.0 ? Direction.reverse : Direction.forward,
velocity: event.velocityX.abs() * _kFlingVelocityScale);
return EventDisposition.processed; return EventDisposition.processed;
} }
return EventDisposition.ignored; return EventDisposition.ignored;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment