Merge pull request #2238 from abarth/rm_animation_direction
Remove AnimationDirection
This commit is contained in:
commit
fc564f0c44
@ -14,39 +14,44 @@ class _ProgressIndicatorDemoState extends State<ProgressIndicatorDemo> {
|
||||
super.initState();
|
||||
controller = new AnimationController(
|
||||
duration: const Duration(milliseconds: 1500)
|
||||
)..play(AnimationDirection.forward);
|
||||
)..forward();
|
||||
|
||||
animation = new CurvedAnimation(
|
||||
parent: controller,
|
||||
curve: new Interval(0.0, 0.9, curve: Curves.ease),
|
||||
reverseCurve: Curves.ease
|
||||
)..addStatusListener((AnimationStatus status) {
|
||||
if (status == AnimationStatus.dismissed || status == AnimationStatus.completed)
|
||||
reverseValueAnimationDirection();
|
||||
if (status == AnimationStatus.dismissed)
|
||||
controller.forward();
|
||||
else if (status == AnimationStatus.completed)
|
||||
controller.reverse();
|
||||
});
|
||||
}
|
||||
|
||||
Animation<double> animation;
|
||||
AnimationController controller;
|
||||
|
||||
void handleTap() {
|
||||
void _handleTap() {
|
||||
setState(() {
|
||||
// valueAnimation.isAnimating is part of our build state
|
||||
if (controller.isAnimating)
|
||||
if (controller.isAnimating) {
|
||||
controller.stop();
|
||||
else
|
||||
controller.resume();
|
||||
} else {
|
||||
switch (controller.status) {
|
||||
case AnimationStatus.dismissed:
|
||||
case AnimationStatus.forward:
|
||||
controller.forward();
|
||||
break;
|
||||
case AnimationStatus.reverse:
|
||||
case AnimationStatus.completed:
|
||||
controller.reverse();
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void reverseValueAnimationDirection() {
|
||||
AnimationDirection direction = (controller.direction == AnimationDirection.forward)
|
||||
? AnimationDirection.reverse
|
||||
: AnimationDirection.forward;
|
||||
controller.play(direction);
|
||||
}
|
||||
|
||||
Widget buildIndicators(BuildContext context, Widget child) {
|
||||
Widget _buildIndicators(BuildContext context, Widget child) {
|
||||
List<Widget> indicators = <Widget>[
|
||||
new SizedBox(
|
||||
width: 200.0,
|
||||
@ -82,13 +87,13 @@ class _ProgressIndicatorDemoState extends State<ProgressIndicatorDemo> {
|
||||
body: new DefaultTextStyle(
|
||||
style: Theme.of(context).text.title,
|
||||
child: new GestureDetector(
|
||||
onTap: handleTap,
|
||||
onTap: _handleTap,
|
||||
behavior: HitTestBehavior.opaque,
|
||||
child: new Container(
|
||||
padding: const EdgeDims.symmetric(vertical: 12.0, horizontal: 8.0),
|
||||
child: new AnimatedBuilder(
|
||||
animation: animation,
|
||||
builder: buildIndicators
|
||||
builder: _buildIndicators
|
||||
)
|
||||
)
|
||||
)
|
||||
|
@ -4,15 +4,6 @@
|
||||
|
||||
import 'dart:ui' show Color, Size, Rect, VoidCallback;
|
||||
|
||||
/// The direction in which an animation is running.
|
||||
enum AnimationDirection {
|
||||
/// The animation is running from beginning to end.
|
||||
forward,
|
||||
|
||||
/// The animation is running backwards, from end to beginning.
|
||||
reverse
|
||||
}
|
||||
|
||||
/// The status of an animation
|
||||
enum AnimationStatus {
|
||||
/// The animation is stopped at the beginning
|
||||
@ -62,9 +53,6 @@ abstract class Animation<T> {
|
||||
/// The current status of this animation.
|
||||
AnimationStatus get status;
|
||||
|
||||
/// The current direction of the animation.
|
||||
AnimationDirection get direction;
|
||||
|
||||
/// The current value of the animation.
|
||||
T get value;
|
||||
|
||||
@ -79,7 +67,6 @@ abstract class Animation<T> {
|
||||
}
|
||||
String toStringDetails() {
|
||||
assert(status != null);
|
||||
assert(direction != null);
|
||||
String icon;
|
||||
switch (status) {
|
||||
case AnimationStatus.forward:
|
||||
@ -89,26 +76,12 @@ abstract class Animation<T> {
|
||||
icon = '\u25C0'; // <
|
||||
break;
|
||||
case AnimationStatus.completed:
|
||||
switch (direction) {
|
||||
case AnimationDirection.forward:
|
||||
icon = '\u23ED'; // >>|
|
||||
break;
|
||||
case AnimationDirection.reverse:
|
||||
icon = '\u29CF'; // <|
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case AnimationStatus.dismissed:
|
||||
switch (direction) {
|
||||
case AnimationDirection.forward:
|
||||
icon = '\u29D0'; // |>
|
||||
break;
|
||||
case AnimationDirection.reverse:
|
||||
icon = '\u23EE'; // |<<
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
assert(icon != null);
|
||||
return '$icon';
|
||||
}
|
||||
|
@ -13,6 +13,15 @@ import 'curves.dart';
|
||||
import 'forces.dart';
|
||||
import 'listener_helpers.dart';
|
||||
|
||||
/// The direction in which an animation is running.
|
||||
enum _AnimationDirection {
|
||||
/// The animation is running from beginning to end.
|
||||
forward,
|
||||
|
||||
/// The animation is running backwards, from end to beginning.
|
||||
reverse
|
||||
}
|
||||
|
||||
/// A controller for an animation.
|
||||
///
|
||||
/// An animation controller can drive an animation forward or backward and can
|
||||
@ -79,9 +88,6 @@ class AnimationController extends Animation<double>
|
||||
/// The length of time this animation should last.
|
||||
Duration duration;
|
||||
|
||||
AnimationDirection get direction => _direction;
|
||||
AnimationDirection _direction = AnimationDirection.forward;
|
||||
|
||||
Ticker _ticker;
|
||||
Simulation _simulation;
|
||||
|
||||
@ -106,31 +112,28 @@ class AnimationController extends Animation<double>
|
||||
/// Whether this animation is currently animating in either the forward or reverse direction.
|
||||
bool get isAnimating => _ticker.isTicking;
|
||||
|
||||
_AnimationDirection _direction;
|
||||
|
||||
AnimationStatus get status {
|
||||
if (!isAnimating && value == upperBound)
|
||||
return AnimationStatus.completed;
|
||||
if (!isAnimating && value == lowerBound)
|
||||
return AnimationStatus.dismissed;
|
||||
return _direction == AnimationDirection.forward ?
|
||||
return _direction == _AnimationDirection.forward ?
|
||||
AnimationStatus.forward :
|
||||
AnimationStatus.reverse;
|
||||
}
|
||||
|
||||
/// Starts running this animation forwards (towards the end).
|
||||
Future forward() => play(AnimationDirection.forward);
|
||||
|
||||
/// Starts running this animation in reverse (towards the beginning).
|
||||
Future reverse() => play(AnimationDirection.reverse);
|
||||
|
||||
/// Starts running this animation in the given direction.
|
||||
Future play(AnimationDirection direction) {
|
||||
_direction = direction;
|
||||
return resume();
|
||||
Future forward() {
|
||||
_direction = _AnimationDirection.forward;
|
||||
return animateTo(upperBound);
|
||||
}
|
||||
|
||||
/// Resumes this animation in the most recent direction.
|
||||
Future resume() {
|
||||
return animateTo(_direction == AnimationDirection.forward ? upperBound : lowerBound);
|
||||
/// Starts running this animation in reverse (towards the beginning).
|
||||
Future reverse() {
|
||||
_direction = _AnimationDirection.reverse;
|
||||
return animateTo(lowerBound);
|
||||
}
|
||||
|
||||
/// Drives the animation from its current value to target.
|
||||
@ -166,7 +169,7 @@ class AnimationController extends Animation<double>
|
||||
/// animation will complete, otherwise it will dismiss.
|
||||
Future fling({ double velocity: 1.0, Force force }) {
|
||||
force ??= kDefaultSpringForce;
|
||||
_direction = velocity < 0.0 ? AnimationDirection.reverse : AnimationDirection.forward;
|
||||
_direction = velocity < 0.0 ? _AnimationDirection.reverse : _AnimationDirection.forward;
|
||||
return animateWith(force.release(value, velocity));
|
||||
}
|
||||
|
||||
|
@ -16,7 +16,6 @@ class _AlwaysCompleteAnimation extends Animation<double> {
|
||||
void addStatusListener(AnimationStatusListener listener) { }
|
||||
void removeStatusListener(AnimationStatusListener listener) { }
|
||||
AnimationStatus get status => AnimationStatus.completed;
|
||||
AnimationDirection get direction => AnimationDirection.forward;
|
||||
double get value => 1.0;
|
||||
}
|
||||
|
||||
@ -35,7 +34,6 @@ class _AlwaysDismissedAnimation extends Animation<double> {
|
||||
void addStatusListener(AnimationStatusListener listener) { }
|
||||
void removeStatusListener(AnimationStatusListener listener) { }
|
||||
AnimationStatus get status => AnimationStatus.dismissed;
|
||||
AnimationDirection get direction => AnimationDirection.forward;
|
||||
double get value => 0.0;
|
||||
}
|
||||
|
||||
@ -57,7 +55,6 @@ class AlwaysStoppedAnimation<T> extends Animation<T> {
|
||||
void addStatusListener(AnimationStatusListener listener) { }
|
||||
void removeStatusListener(AnimationStatusListener listener) { }
|
||||
AnimationStatus get status => AnimationStatus.forward;
|
||||
AnimationDirection get direction => AnimationDirection.forward;
|
||||
}
|
||||
|
||||
/// Implements most of the [Animation] interface, by deferring its behavior to a
|
||||
@ -77,7 +74,6 @@ abstract class AnimationWithParentMixin<T> {
|
||||
void removeStatusListener(AnimationStatusListener listener) => parent.removeStatusListener(listener);
|
||||
|
||||
AnimationStatus get status => parent.status;
|
||||
AnimationDirection get direction => parent.direction;
|
||||
}
|
||||
|
||||
/// An animation that is a proxy for another animation.
|
||||
@ -92,13 +88,11 @@ class ProxyAnimation extends Animation<double>
|
||||
_parent = animation;
|
||||
if (_parent == null) {
|
||||
_status = AnimationStatus.dismissed;
|
||||
_direction = AnimationDirection.forward;
|
||||
_value = 0.0;
|
||||
}
|
||||
}
|
||||
|
||||
AnimationStatus _status;
|
||||
AnimationDirection _direction;
|
||||
double _value;
|
||||
|
||||
/// The animation whose value this animation will proxy.
|
||||
@ -112,7 +106,6 @@ class ProxyAnimation extends Animation<double>
|
||||
return;
|
||||
if (_parent != null) {
|
||||
_status = _parent.status;
|
||||
_direction = _parent.direction;
|
||||
_value = _parent.value;
|
||||
if (isListening)
|
||||
didStopListening();
|
||||
@ -126,7 +119,6 @@ class ProxyAnimation extends Animation<double>
|
||||
if (_status != _parent.status)
|
||||
notifyStatusListeners(_parent.status);
|
||||
_status = null;
|
||||
_direction = null;
|
||||
_value = null;
|
||||
}
|
||||
}
|
||||
@ -146,7 +138,6 @@ class ProxyAnimation extends Animation<double>
|
||||
}
|
||||
|
||||
AnimationStatus get status => _parent != null ? _parent.status : _status;
|
||||
AnimationDirection get direction => _parent != null ? _parent.direction : _direction;
|
||||
double get value => _parent != null ? _parent.value : _value;
|
||||
}
|
||||
|
||||
@ -186,7 +177,6 @@ class ReverseAnimation extends Animation<double>
|
||||
}
|
||||
|
||||
AnimationStatus get status => _reverseStatus(parent.status);
|
||||
AnimationDirection get direction => _reverseDirection(parent.direction);
|
||||
double get value => 1.0 - parent.value;
|
||||
|
||||
AnimationStatus _reverseStatus(AnimationStatus status) {
|
||||
@ -197,13 +187,6 @@ class ReverseAnimation extends Animation<double>
|
||||
case AnimationStatus.dismissed: return AnimationStatus.completed;
|
||||
}
|
||||
}
|
||||
|
||||
AnimationDirection _reverseDirection(AnimationDirection direction) {
|
||||
switch (direction) {
|
||||
case AnimationDirection.forward: return AnimationDirection.reverse;
|
||||
case AnimationDirection.reverse: return AnimationDirection.forward;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// An animation that applies a curve to another animation.
|
||||
@ -238,7 +221,7 @@ class CurvedAnimation extends Animation<double> with AnimationWithParentMixin<do
|
||||
/// The curve direction is only reset when we hit the beginning or the end of
|
||||
/// the timeline to avoid discontinuities in the value of any variables this
|
||||
/// a animation is used to animate.
|
||||
AnimationDirection _curveDirection;
|
||||
AnimationStatus _curveDirection;
|
||||
|
||||
void _handleStatusChanged(AnimationStatus status) {
|
||||
switch (status) {
|
||||
@ -247,16 +230,16 @@ class CurvedAnimation extends Animation<double> with AnimationWithParentMixin<do
|
||||
_curveDirection = null;
|
||||
break;
|
||||
case AnimationStatus.forward:
|
||||
_curveDirection ??= AnimationDirection.forward;
|
||||
_curveDirection ??= AnimationStatus.forward;
|
||||
break;
|
||||
case AnimationStatus.reverse:
|
||||
_curveDirection ??= AnimationDirection.reverse;
|
||||
_curveDirection ??= AnimationStatus.reverse;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
double get value {
|
||||
final bool useForwardCurve = reverseCurve == null || (_curveDirection ?? parent.direction) == AnimationDirection.forward;
|
||||
final bool useForwardCurve = reverseCurve == null || (_curveDirection ?? parent.status) != AnimationStatus.reverse;
|
||||
Curve activeCurve = useForwardCurve ? curve : reverseCurve;
|
||||
|
||||
double t = parent.value;
|
||||
@ -324,7 +307,6 @@ class TrainHoppingAnimation extends Animation<double>
|
||||
}
|
||||
|
||||
AnimationStatus get status => _currentTrain.status;
|
||||
AnimationDirection get direction => _currentTrain.direction;
|
||||
|
||||
double _lastValue;
|
||||
void _valueChangeHandler() {
|
||||
|
@ -51,7 +51,7 @@ class _BottomSheetState extends State<BottomSheet> {
|
||||
return renderBox.size.height;
|
||||
}
|
||||
|
||||
bool get _dismissUnderway => config.animationController.direction == AnimationDirection.reverse;
|
||||
bool get _dismissUnderway => config.animationController.status == AnimationStatus.reverse;
|
||||
|
||||
void _handleDragUpdate(double delta) {
|
||||
if (_dismissUnderway)
|
||||
|
@ -810,7 +810,6 @@ class _TabBarViewState extends PageableListState<TabBarView> implements TabBarSe
|
||||
|
||||
TabBarSelectionState _selection;
|
||||
List<Widget> _items;
|
||||
AnimationDirection _scrollDirection = AnimationDirection.forward;
|
||||
|
||||
int get _tabCount => config.children.length;
|
||||
|
||||
@ -907,16 +906,11 @@ class _TabBarViewState extends PageableListState<TabBarView> implements TabBarSe
|
||||
|
||||
if (selectedIndex < previousSelectedIndex) {
|
||||
_updateItemsFromChildren(selectedIndex, previousSelectedIndex);
|
||||
_scrollDirection = AnimationDirection.reverse;
|
||||
scrollTo(1.0 - animation.value);
|
||||
} else {
|
||||
_updateItemsFromChildren(previousSelectedIndex, selectedIndex);
|
||||
_scrollDirection = AnimationDirection.forward;
|
||||
}
|
||||
|
||||
if (_scrollDirection == AnimationDirection.forward)
|
||||
scrollTo(animation.value);
|
||||
else
|
||||
scrollTo(1.0 - animation.value);
|
||||
}
|
||||
}
|
||||
|
||||
void dispatchOnScroll() {
|
||||
|
@ -66,7 +66,10 @@ abstract class RenderToggleable extends RenderConstrainedBox implements Semantic
|
||||
_position
|
||||
..curve = Curves.easeIn
|
||||
..reverseCurve = Curves.easeOut;
|
||||
_positionController.play(value ? AnimationDirection.forward : AnimationDirection.reverse);
|
||||
if (value)
|
||||
_positionController.forward();
|
||||
else
|
||||
_positionController.reverse();
|
||||
}
|
||||
|
||||
Color get activeColor => _activeColor;
|
||||
|
@ -456,7 +456,8 @@ class HeroController extends NavigatorObserver {
|
||||
|
||||
void _addHeroToOverlay(Widget hero, Object tag, OverlayState overlay) {
|
||||
OverlayEntry entry = new OverlayEntry(builder: (_) => hero);
|
||||
if (_animation.direction == AnimationDirection.forward)
|
||||
assert(_animation.status != AnimationStatus.dismissed && _animation.status != AnimationStatus.completed);
|
||||
if (_animation.status == AnimationStatus.forward)
|
||||
_to.insertHeroOverlayEntry(entry, tag, overlay);
|
||||
else
|
||||
_from.insertHeroOverlayEntry(entry, tag, overlay);
|
||||
|
Loading…
x
Reference in New Issue
Block a user