Commit 51e2a0a2 authored by Adam Barth's avatar Adam Barth

Merge pull request #1325 from abarth/use_parent

Minor animation renames
parents bdb52ce0 89320ee2
...@@ -14,7 +14,7 @@ import 'listener_helpers.dart'; ...@@ -14,7 +14,7 @@ import 'listener_helpers.dart';
import 'ticker.dart'; import 'ticker.dart';
class AnimationController extends Animation<double> class AnimationController extends Animation<double>
with EagerListenerMixin, LocalPerformanceListenersMixin, LocalPerformanceStatusListenersMixin { with EagerListenerMixin, LocalAnimationListenersMixin, LocalAnimationStatusListenersMixin {
AnimationController({ AnimationController({
double value, double value,
this.duration, this.duration,
......
...@@ -62,10 +62,10 @@ abstract class ProxyAnimatedMixin { ...@@ -62,10 +62,10 @@ abstract class ProxyAnimatedMixin {
} }
class ProxyAnimation extends Animation<double> class ProxyAnimation extends Animation<double>
with LazyListenerMixin, LocalPerformanceListenersMixin, LocalPerformanceStatusListenersMixin { with LazyListenerMixin, LocalAnimationListenersMixin, LocalAnimationStatusListenersMixin {
ProxyAnimation([Animation<double> animation]) { ProxyAnimation([Animation<double> animation]) {
_masterAnimation = animation; _parent = animation;
if (_masterAnimation == null) { if (_parent == null) {
_status = AnimationStatus.dismissed; _status = AnimationStatus.dismissed;
_direction = AnimationDirection.forward; _direction = AnimationDirection.forward;
_value = 0.0; _value = 0.0;
...@@ -76,26 +76,26 @@ class ProxyAnimation extends Animation<double> ...@@ -76,26 +76,26 @@ class ProxyAnimation extends Animation<double>
AnimationDirection _direction; AnimationDirection _direction;
double _value; double _value;
Animation<double> get masterAnimation => _masterAnimation; Animation<double> get parent => _parent;
Animation<double> _masterAnimation; Animation<double> _parent;
void set masterAnimation(Animation<double> value) { void set parent(Animation<double> value) {
if (value == _masterAnimation) if (value == _parent)
return; return;
if (_masterAnimation != null) { if (_parent != null) {
_status = _masterAnimation.status; _status = _parent.status;
_direction = _masterAnimation.direction; _direction = _parent.direction;
_value = _masterAnimation.value; _value = _parent.value;
if (isListening) if (isListening)
didStopListening(); didStopListening();
} }
_masterAnimation = value; _parent = value;
if (_masterAnimation != null) { if (_parent != null) {
if (isListening) if (isListening)
didStartListening(); didStartListening();
if (_value != _masterAnimation.value) if (_value != _parent.value)
notifyListeners(); notifyListeners();
if (_status != _masterAnimation.status) if (_status != _parent.status)
notifyStatusListeners(_masterAnimation.status); notifyStatusListeners(_parent.status);
_status = null; _status = null;
_direction = null; _direction = null;
_value = null; _value = null;
...@@ -103,54 +103,54 @@ class ProxyAnimation extends Animation<double> ...@@ -103,54 +103,54 @@ class ProxyAnimation extends Animation<double>
} }
void didStartListening() { void didStartListening() {
if (_masterAnimation != null) { if (_parent != null) {
_masterAnimation.addListener(notifyListeners); _parent.addListener(notifyListeners);
_masterAnimation.addStatusListener(notifyStatusListeners); _parent.addStatusListener(notifyStatusListeners);
} }
} }
void didStopListening() { void didStopListening() {
if (_masterAnimation != null) { if (_parent != null) {
_masterAnimation.removeListener(notifyListeners); _parent.removeListener(notifyListeners);
_masterAnimation.removeStatusListener(notifyStatusListeners); _parent.removeStatusListener(notifyStatusListeners);
} }
} }
AnimationStatus get status => _masterAnimation != null ? _masterAnimation.status : _status; AnimationStatus get status => _parent != null ? _parent.status : _status;
AnimationDirection get direction => _masterAnimation != null ? _masterAnimation.direction : _direction; AnimationDirection get direction => _parent != null ? _parent.direction : _direction;
double get value => _masterAnimation != null ? _masterAnimation.value : _value; double get value => _parent != null ? _parent.value : _value;
} }
class ReverseAnimation extends Animation<double> class ReverseAnimation extends Animation<double>
with LazyListenerMixin, LocalPerformanceStatusListenersMixin { with LazyListenerMixin, LocalAnimationStatusListenersMixin {
ReverseAnimation(this.masterAnimation); ReverseAnimation(this.parent);
final Animation<double> masterAnimation; final Animation<double> parent;
void addListener(VoidCallback listener) { void addListener(VoidCallback listener) {
didRegisterListener(); didRegisterListener();
masterAnimation.addListener(listener); parent.addListener(listener);
} }
void removeListener(VoidCallback listener) { void removeListener(VoidCallback listener) {
masterAnimation.removeListener(listener); parent.removeListener(listener);
didUnregisterListener(); didUnregisterListener();
} }
void didStartListening() { void didStartListening() {
masterAnimation.addStatusListener(_statusChangeHandler); parent.addStatusListener(_statusChangeHandler);
} }
void didStopListening() { void didStopListening() {
masterAnimation.removeStatusListener(_statusChangeHandler); parent.removeStatusListener(_statusChangeHandler);
} }
void _statusChangeHandler(AnimationStatus status) { void _statusChangeHandler(AnimationStatus status) {
notifyStatusListeners(_reverseStatus(status)); notifyStatusListeners(_reverseStatus(status));
} }
AnimationStatus get status => _reverseStatus(masterAnimation.status); AnimationStatus get status => _reverseStatus(parent.status);
AnimationDirection get direction => _reverseDirection(masterAnimation.direction); AnimationDirection get direction => _reverseDirection(parent.direction);
double get value => 1.0 - masterAnimation.value; double get value => 1.0 - parent.value;
AnimationStatus _reverseStatus(AnimationStatus status) { AnimationStatus _reverseStatus(AnimationStatus status) {
switch (status) { switch (status) {
...@@ -240,7 +240,7 @@ enum _TrainHoppingMode { minimize, maximize } ...@@ -240,7 +240,7 @@ enum _TrainHoppingMode { minimize, maximize }
/// removed, it exposes a [dispose()] method. Call this method to shut this /// removed, it exposes a [dispose()] method. Call this method to shut this
/// object down. /// object down.
class TrainHoppingAnimation extends Animation<double> class TrainHoppingAnimation extends Animation<double>
with EagerListenerMixin, LocalPerformanceListenersMixin, LocalPerformanceStatusListenersMixin { with EagerListenerMixin, LocalAnimationListenersMixin, LocalAnimationStatusListenersMixin {
TrainHoppingAnimation(this._currentTrain, this._nextTrain, { this.onSwitchedTrain }) { TrainHoppingAnimation(this._currentTrain, this._nextTrain, { this.onSwitchedTrain }) {
assert(_currentTrain != null); assert(_currentTrain != null);
if (_nextTrain != null) { if (_nextTrain != null) {
......
...@@ -38,7 +38,7 @@ abstract class EagerListenerMixin implements _ListenerMixin { ...@@ -38,7 +38,7 @@ abstract class EagerListenerMixin implements _ListenerMixin {
void dispose(); void dispose();
} }
abstract class LocalPerformanceListenersMixin extends _ListenerMixin { abstract class LocalAnimationListenersMixin extends _ListenerMixin {
final List<VoidCallback> _listeners = <VoidCallback>[]; final List<VoidCallback> _listeners = <VoidCallback>[];
void addListener(VoidCallback listener) { void addListener(VoidCallback listener) {
didRegisterListener(); didRegisterListener();
...@@ -55,7 +55,7 @@ abstract class LocalPerformanceListenersMixin extends _ListenerMixin { ...@@ -55,7 +55,7 @@ abstract class LocalPerformanceListenersMixin extends _ListenerMixin {
} }
} }
abstract class LocalPerformanceStatusListenersMixin extends _ListenerMixin { abstract class LocalAnimationStatusListenersMixin extends _ListenerMixin {
final List<AnimationStatusListener> _statusListeners = <AnimationStatusListener>[]; final List<AnimationStatusListener> _statusListeners = <AnimationStatusListener>[];
void addStatusListener(AnimationStatusListener listener) { void addStatusListener(AnimationStatusListener listener) {
didRegisterListener(); didRegisterListener();
......
...@@ -381,7 +381,7 @@ class _TabsScrollBehavior extends BoundedBehavior { ...@@ -381,7 +381,7 @@ class _TabsScrollBehavior extends BoundedBehavior {
} }
} }
abstract class TabBarSelectionPerformanceListener { abstract class TabBarSelectionAnimationListener {
void handleStatusChange(AnimationStatus status); void handleStatusChange(AnimationStatus status);
void handleProgressChange(); void handleProgressChange();
void handleSelectionDeactivate(); void handleSelectionDeactivate();
...@@ -503,28 +503,28 @@ class TabBarSelectionState<T> extends State<TabBarSelection<T>> { ...@@ -503,28 +503,28 @@ class TabBarSelectionState<T> extends State<TabBarSelection<T>> {
}); });
} }
final List<TabBarSelectionPerformanceListener> _performanceListeners = <TabBarSelectionPerformanceListener>[]; final List<TabBarSelectionAnimationListener> _animationListeners = <TabBarSelectionAnimationListener>[];
void registerPerformanceListener(TabBarSelectionPerformanceListener listener) { void registerAnimationListener(TabBarSelectionAnimationListener listener) {
_performanceListeners.add(listener); _animationListeners.add(listener);
_controller _controller
..addStatusListener(listener.handleStatusChange) ..addStatusListener(listener.handleStatusChange)
..addListener(listener.handleProgressChange); ..addListener(listener.handleProgressChange);
} }
void unregisterPerformanceListener(TabBarSelectionPerformanceListener listener) { void unregisterAnimationListener(TabBarSelectionAnimationListener listener) {
_performanceListeners.remove(listener); _animationListeners.remove(listener);
_controller _controller
..removeStatusListener(listener.handleStatusChange) ..removeStatusListener(listener.handleStatusChange)
..removeListener(listener.handleProgressChange); ..removeListener(listener.handleProgressChange);
} }
void deactivate() { void deactivate() {
for (TabBarSelectionPerformanceListener listener in _performanceListeners.toList()) { for (TabBarSelectionAnimationListener listener in _animationListeners.toList()) {
listener.handleSelectionDeactivate(); listener.handleSelectionDeactivate();
unregisterPerformanceListener(listener); unregisterAnimationListener(listener);
} }
assert(_performanceListeners.isEmpty); assert(_animationListeners.isEmpty);
} }
Widget build(BuildContext context) { Widget build(BuildContext context) {
...@@ -552,15 +552,15 @@ class TabBar<T> extends Scrollable { ...@@ -552,15 +552,15 @@ class TabBar<T> extends Scrollable {
_TabBarState createState() => new _TabBarState(); _TabBarState createState() => new _TabBarState();
} }
class _TabBarState<T> extends ScrollableState<TabBar<T>> implements TabBarSelectionPerformanceListener { class _TabBarState<T> extends ScrollableState<TabBar<T>> implements TabBarSelectionAnimationListener {
TabBarSelectionState _selection; TabBarSelectionState _selection;
bool _valueIsChanging = false; bool _valueIsChanging = false;
void _initSelection(TabBarSelectionState<T> selection) { void _initSelection(TabBarSelectionState<T> selection) {
_selection?.unregisterPerformanceListener(this); _selection?.unregisterAnimationListener(this);
_selection = selection; _selection = selection;
_selection?.registerPerformanceListener(this); _selection?.registerAnimationListener(this);
} }
void initState() { void initState() {
...@@ -576,7 +576,7 @@ class _TabBarState<T> extends ScrollableState<TabBar<T>> implements TabBarSelect ...@@ -576,7 +576,7 @@ class _TabBarState<T> extends ScrollableState<TabBar<T>> implements TabBarSelect
} }
void dispose() { void dispose() {
_selection?.unregisterPerformanceListener(this); _selection?.unregisterAnimationListener(this);
super.dispose(); super.dispose();
} }
...@@ -791,7 +791,7 @@ class TabBarView extends PageableList { ...@@ -791,7 +791,7 @@ class TabBarView extends PageableList {
_TabBarViewState createState() => new _TabBarViewState(); _TabBarViewState createState() => new _TabBarViewState();
} }
class _TabBarViewState extends PageableListState<TabBarView> implements TabBarSelectionPerformanceListener { class _TabBarViewState extends PageableListState<TabBarView> implements TabBarSelectionAnimationListener {
TabBarSelectionState _selection; TabBarSelectionState _selection;
List<Widget> _items; List<Widget> _items;
...@@ -809,7 +809,7 @@ class _TabBarViewState extends PageableListState<TabBarView> implements TabBarSe ...@@ -809,7 +809,7 @@ class _TabBarViewState extends PageableListState<TabBarView> implements TabBarSe
void _initSelection(TabBarSelectionState selection) { void _initSelection(TabBarSelectionState selection) {
_selection = selection; _selection = selection;
if (_selection != null) { if (_selection != null) {
_selection.registerPerformanceListener(this); _selection.registerAnimationListener(this);
_updateItemsAndScrollBehavior(); _updateItemsAndScrollBehavior();
} }
} }
...@@ -826,7 +826,7 @@ class _TabBarViewState extends PageableListState<TabBarView> implements TabBarSe ...@@ -826,7 +826,7 @@ class _TabBarViewState extends PageableListState<TabBarView> implements TabBarSe
} }
void dispose() { void dispose() {
_selection?.unregisterPerformanceListener(this); _selection?.unregisterAnimationListener(this);
super.dispose(); super.dispose();
} }
...@@ -874,7 +874,7 @@ class _TabBarViewState extends PageableListState<TabBarView> implements TabBarSe ...@@ -874,7 +874,7 @@ class _TabBarViewState extends PageableListState<TabBarView> implements TabBarSe
void handleProgressChange() { void handleProgressChange() {
if (_selection == null || !_selection.valueIsChanging) if (_selection == null || !_selection.valueIsChanging)
return; return;
// The TabBar is driving the TabBarSelection performance. // The TabBar is driving the TabBarSelection animation.
final Animation<double> animation = _selection.animation; final Animation<double> animation = _selection.animation;
...@@ -906,7 +906,7 @@ class _TabBarViewState extends PageableListState<TabBarView> implements TabBarSe ...@@ -906,7 +906,7 @@ class _TabBarViewState extends PageableListState<TabBarView> implements TabBarSe
void dispatchOnScroll() { void dispatchOnScroll() {
if (_selection == null || _selection.valueIsChanging) if (_selection == null || _selection.valueIsChanging)
return; return;
// This class is driving the TabBarSelection's performance. // This class is driving the TabBarSelection's animation.
final AnimationController controller = _selection._controller; final AnimationController controller = _selection._controller;
......
...@@ -177,7 +177,7 @@ abstract class TransitionRoute<T> extends OverlayRoute<T> { ...@@ -177,7 +177,7 @@ abstract class TransitionRoute<T> extends OverlayRoute<T> {
void _updateForwardAnimation(Route nextRoute) { void _updateForwardAnimation(Route nextRoute) {
if (nextRoute is TransitionRoute && canTransitionTo(nextRoute) && nextRoute.canTransitionFrom(this)) { if (nextRoute is TransitionRoute && canTransitionTo(nextRoute) && nextRoute.canTransitionFrom(this)) {
Animation<double> current = _forwardAnimation.masterAnimation; Animation<double> current = _forwardAnimation.parent;
if (current != null) { if (current != null) {
if (current is TrainHoppingAnimation) { if (current is TrainHoppingAnimation) {
TrainHoppingAnimation newAnimation; TrainHoppingAnimation newAnimation;
...@@ -185,22 +185,22 @@ abstract class TransitionRoute<T> extends OverlayRoute<T> { ...@@ -185,22 +185,22 @@ abstract class TransitionRoute<T> extends OverlayRoute<T> {
current.currentTrain, current.currentTrain,
nextRoute.animation, nextRoute.animation,
onSwitchedTrain: () { onSwitchedTrain: () {
assert(_forwardAnimation.masterAnimation == newAnimation); assert(_forwardAnimation.parent == newAnimation);
assert(newAnimation.currentTrain == nextRoute.animation); assert(newAnimation.currentTrain == nextRoute.animation);
_forwardAnimation.masterAnimation = newAnimation.currentTrain; _forwardAnimation.parent = newAnimation.currentTrain;
newAnimation.dispose(); newAnimation.dispose();
} }
); );
_forwardAnimation.masterAnimation = newAnimation; _forwardAnimation.parent = newAnimation;
current.dispose(); current.dispose();
} else { } else {
_forwardAnimation.masterAnimation = new TrainHoppingAnimation(current, nextRoute.animation); _forwardAnimation.parent = new TrainHoppingAnimation(current, nextRoute.animation);
} }
} else { } else {
_forwardAnimation.masterAnimation = nextRoute.animation; _forwardAnimation.parent = nextRoute.animation;
} }
} else { } else {
_forwardAnimation.masterAnimation = kAlwaysDismissedAnimation; _forwardAnimation.parent = kAlwaysDismissedAnimation;
} }
} }
......
...@@ -175,9 +175,8 @@ class RelativeRectTween extends Tween<RelativeRect> { ...@@ -175,9 +175,8 @@ class RelativeRectTween extends Tween<RelativeRect> {
} }
/// Animated version of [Positioned] which takes a specific /// Animated version of [Positioned] which takes a specific
/// [AnimatedRelativeRectValue] and a [PerformanceView] to transition the /// [Animation<RelativeRect>] to transition the child's position from a start
/// child's position from a start position to and end position over the lifetime /// position to and end position over the lifetime of the animation.
/// of the performance.
/// ///
/// Only works if it's the child of a [Stack]. /// Only works if it's the child of a [Stack].
class PositionedTransition extends AnimatedComponent { class PositionedTransition extends AnimatedComponent {
......
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