mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
This CL cleans up the sky/framework/animation as follows: 1) I've moved code that's used only by the custom elements framework into sky/framework/elements/animation. This code is based on AnimationDelegates rather than Streams. 2) Rename ScrollCurve to ScrollBehavior because it encapsulates more behavior than just a curve. 3) Make the Generator interface explicit and mark subclasses as actual subclasses. 4) Move Simulation into generators.dart because it implements the Generator interface. 5) Move Animation out of generators.dart because it does not implement the Generator interface. R=eseidel@chromium.org Review URL: https://codereview.chromium.org/1001373002
49 lines
1.2 KiB
Dart
49 lines
1.2 KiB
Dart
// Copyright 2015 The Chromium Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file.
|
|
|
|
import "../../animation/curves.dart";
|
|
import "timer.dart";
|
|
|
|
class AnimationController extends AnimationDelegate {
|
|
final AnimationDelegate _delegate;
|
|
AnimationTimer _timer;
|
|
double _begin = 0.0;
|
|
double _end = 0.0;
|
|
Curve _curve;
|
|
bool _isAnimating = false;
|
|
|
|
AnimationController(this._delegate) {
|
|
_timer = new AnimationTimer(this);
|
|
}
|
|
|
|
bool get isAnimating => _isAnimating;
|
|
|
|
void start({double begin: 0.0, double end: 0.0, Curve curve: linear,
|
|
double duration: 0.0}) {
|
|
_begin = begin;
|
|
_end = end;
|
|
_curve = curve;
|
|
_isAnimating = true;
|
|
_timer.start(duration);
|
|
}
|
|
|
|
void stop() {
|
|
_isAnimating = false;
|
|
_timer.stop();
|
|
}
|
|
|
|
double _positionForTime(double t) {
|
|
// Explicitly finish animations at |_end| in case the curve isn't an
|
|
// exact numerical transform.
|
|
if (t == 1)
|
|
return _end;
|
|
double curvedTime = _curve.transform(t);
|
|
return _begin + (_end - _begin) * curvedTime;
|
|
}
|
|
|
|
void updateAnimation(double t) {
|
|
_delegate.updateAnimation(_positionForTime(t));
|
|
}
|
|
}
|