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 {
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<Function> _listeners = new List<Function>();
......
......@@ -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;
......
......@@ -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;
}
......
......@@ -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;
......
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