From d59da41bfc72529d95d225d88762b512649252ff Mon Sep 17 00:00:00 2001 From: Adam Barth Date: Wed, 20 Jan 2016 20:47:15 -0800 Subject: [PATCH 1/2] Use parent consistently for parent animation Some of the Animation classes that we converted from performances use the term "master" to refer to the animation upon which they're based. This patch changes them to use the term "parent", which is consistent with the rest of the animation classes. --- .../flutter/lib/src/animation/animations.dart | 66 +++++++++---------- packages/flutter/lib/src/widgets/routes.dart | 14 ++-- 2 files changed, 40 insertions(+), 40 deletions(-) diff --git a/packages/flutter/lib/src/animation/animations.dart b/packages/flutter/lib/src/animation/animations.dart index b5585dc44e..f5c20f89ec 100644 --- a/packages/flutter/lib/src/animation/animations.dart +++ b/packages/flutter/lib/src/animation/animations.dart @@ -64,8 +64,8 @@ abstract class ProxyAnimatedMixin { class ProxyAnimation extends Animation with LazyListenerMixin, LocalPerformanceListenersMixin, LocalPerformanceStatusListenersMixin { ProxyAnimation([Animation animation]) { - _masterAnimation = animation; - if (_masterAnimation == null) { + _parent = animation; + if (_parent == null) { _status = AnimationStatus.dismissed; _direction = AnimationDirection.forward; _value = 0.0; @@ -76,26 +76,26 @@ class ProxyAnimation extends Animation AnimationDirection _direction; double _value; - Animation get masterAnimation => _masterAnimation; - Animation _masterAnimation; - void set masterAnimation(Animation value) { - if (value == _masterAnimation) + Animation get parent => _parent; + Animation _parent; + void set parent(Animation value) { + if (value == _parent) return; - if (_masterAnimation != null) { - _status = _masterAnimation.status; - _direction = _masterAnimation.direction; - _value = _masterAnimation.value; + if (_parent != null) { + _status = _parent.status; + _direction = _parent.direction; + _value = _parent.value; if (isListening) didStopListening(); } - _masterAnimation = value; - if (_masterAnimation != null) { + _parent = value; + if (_parent != null) { if (isListening) didStartListening(); - if (_value != _masterAnimation.value) + if (_value != _parent.value) notifyListeners(); - if (_status != _masterAnimation.status) - notifyStatusListeners(_masterAnimation.status); + if (_status != _parent.status) + notifyStatusListeners(_parent.status); _status = null; _direction = null; _value = null; @@ -103,54 +103,54 @@ class ProxyAnimation extends Animation } void didStartListening() { - if (_masterAnimation != null) { - _masterAnimation.addListener(notifyListeners); - _masterAnimation.addStatusListener(notifyStatusListeners); + if (_parent != null) { + _parent.addListener(notifyListeners); + _parent.addStatusListener(notifyStatusListeners); } } void didStopListening() { - if (_masterAnimation != null) { - _masterAnimation.removeListener(notifyListeners); - _masterAnimation.removeStatusListener(notifyStatusListeners); + if (_parent != null) { + _parent.removeListener(notifyListeners); + _parent.removeStatusListener(notifyStatusListeners); } } - AnimationStatus get status => _masterAnimation != null ? _masterAnimation.status : _status; - AnimationDirection get direction => _masterAnimation != null ? _masterAnimation.direction : _direction; - double get value => _masterAnimation != null ? _masterAnimation.value : _value; + AnimationStatus get status => _parent != null ? _parent.status : _status; + AnimationDirection get direction => _parent != null ? _parent.direction : _direction; + double get value => _parent != null ? _parent.value : _value; } class ReverseAnimation extends Animation with LazyListenerMixin, LocalPerformanceStatusListenersMixin { - ReverseAnimation(this.masterAnimation); + ReverseAnimation(this.parent); - final Animation masterAnimation; + final Animation parent; void addListener(VoidCallback listener) { didRegisterListener(); - masterAnimation.addListener(listener); + parent.addListener(listener); } void removeListener(VoidCallback listener) { - masterAnimation.removeListener(listener); + parent.removeListener(listener); didUnregisterListener(); } void didStartListening() { - masterAnimation.addStatusListener(_statusChangeHandler); + parent.addStatusListener(_statusChangeHandler); } void didStopListening() { - masterAnimation.removeStatusListener(_statusChangeHandler); + parent.removeStatusListener(_statusChangeHandler); } void _statusChangeHandler(AnimationStatus status) { notifyStatusListeners(_reverseStatus(status)); } - AnimationStatus get status => _reverseStatus(masterAnimation.status); - AnimationDirection get direction => _reverseDirection(masterAnimation.direction); - double get value => 1.0 - masterAnimation.value; + AnimationStatus get status => _reverseStatus(parent.status); + AnimationDirection get direction => _reverseDirection(parent.direction); + double get value => 1.0 - parent.value; AnimationStatus _reverseStatus(AnimationStatus status) { switch (status) { diff --git a/packages/flutter/lib/src/widgets/routes.dart b/packages/flutter/lib/src/widgets/routes.dart index d0dd45870a..7f51cc8902 100644 --- a/packages/flutter/lib/src/widgets/routes.dart +++ b/packages/flutter/lib/src/widgets/routes.dart @@ -177,7 +177,7 @@ abstract class TransitionRoute extends OverlayRoute { void _updateForwardAnimation(Route nextRoute) { if (nextRoute is TransitionRoute && canTransitionTo(nextRoute) && nextRoute.canTransitionFrom(this)) { - Animation current = _forwardAnimation.masterAnimation; + Animation current = _forwardAnimation.parent; if (current != null) { if (current is TrainHoppingAnimation) { TrainHoppingAnimation newAnimation; @@ -185,22 +185,22 @@ abstract class TransitionRoute extends OverlayRoute { current.currentTrain, nextRoute.animation, onSwitchedTrain: () { - assert(_forwardAnimation.masterAnimation == newAnimation); + assert(_forwardAnimation.parent == newAnimation); assert(newAnimation.currentTrain == nextRoute.animation); - _forwardAnimation.masterAnimation = newAnimation.currentTrain; + _forwardAnimation.parent = newAnimation.currentTrain; newAnimation.dispose(); } ); - _forwardAnimation.masterAnimation = newAnimation; + _forwardAnimation.parent = newAnimation; current.dispose(); } else { - _forwardAnimation.masterAnimation = new TrainHoppingAnimation(current, nextRoute.animation); + _forwardAnimation.parent = new TrainHoppingAnimation(current, nextRoute.animation); } } else { - _forwardAnimation.masterAnimation = nextRoute.animation; + _forwardAnimation.parent = nextRoute.animation; } } else { - _forwardAnimation.masterAnimation = kAlwaysDismissedAnimation; + _forwardAnimation.parent = kAlwaysDismissedAnimation; } } From 89320ee23337be409b859b7d5246b392b9a1f194 Mon Sep 17 00:00:00 2001 From: Adam Barth Date: Wed, 20 Jan 2016 20:51:43 -0800 Subject: [PATCH 2/2] Rename Performance to Animation in a couple more places These should be the last references to the old "performance" name. --- .../src/animation/animation_controller.dart | 2 +- .../flutter/lib/src/animation/animations.dart | 6 ++-- .../lib/src/animation/listener_helpers.dart | 4 +-- packages/flutter/lib/src/material/tabs.dart | 36 +++++++++---------- .../flutter/lib/src/widgets/transitions.dart | 5 ++- 5 files changed, 26 insertions(+), 27 deletions(-) diff --git a/packages/flutter/lib/src/animation/animation_controller.dart b/packages/flutter/lib/src/animation/animation_controller.dart index 8a20008358..c2c7d62504 100644 --- a/packages/flutter/lib/src/animation/animation_controller.dart +++ b/packages/flutter/lib/src/animation/animation_controller.dart @@ -14,7 +14,7 @@ import 'listener_helpers.dart'; import 'ticker.dart'; class AnimationController extends Animation - with EagerListenerMixin, LocalPerformanceListenersMixin, LocalPerformanceStatusListenersMixin { + with EagerListenerMixin, LocalAnimationListenersMixin, LocalAnimationStatusListenersMixin { AnimationController({ double value, this.duration, diff --git a/packages/flutter/lib/src/animation/animations.dart b/packages/flutter/lib/src/animation/animations.dart index f5c20f89ec..ae334ded96 100644 --- a/packages/flutter/lib/src/animation/animations.dart +++ b/packages/flutter/lib/src/animation/animations.dart @@ -62,7 +62,7 @@ abstract class ProxyAnimatedMixin { } class ProxyAnimation extends Animation - with LazyListenerMixin, LocalPerformanceListenersMixin, LocalPerformanceStatusListenersMixin { + with LazyListenerMixin, LocalAnimationListenersMixin, LocalAnimationStatusListenersMixin { ProxyAnimation([Animation animation]) { _parent = animation; if (_parent == null) { @@ -122,7 +122,7 @@ class ProxyAnimation extends Animation } class ReverseAnimation extends Animation - with LazyListenerMixin, LocalPerformanceStatusListenersMixin { + with LazyListenerMixin, LocalAnimationStatusListenersMixin { ReverseAnimation(this.parent); final Animation parent; @@ -240,7 +240,7 @@ enum _TrainHoppingMode { minimize, maximize } /// removed, it exposes a [dispose()] method. Call this method to shut this /// object down. class TrainHoppingAnimation extends Animation - with EagerListenerMixin, LocalPerformanceListenersMixin, LocalPerformanceStatusListenersMixin { + with EagerListenerMixin, LocalAnimationListenersMixin, LocalAnimationStatusListenersMixin { TrainHoppingAnimation(this._currentTrain, this._nextTrain, { this.onSwitchedTrain }) { assert(_currentTrain != null); if (_nextTrain != null) { diff --git a/packages/flutter/lib/src/animation/listener_helpers.dart b/packages/flutter/lib/src/animation/listener_helpers.dart index 174f2e1a6e..5913377021 100644 --- a/packages/flutter/lib/src/animation/listener_helpers.dart +++ b/packages/flutter/lib/src/animation/listener_helpers.dart @@ -38,7 +38,7 @@ abstract class EagerListenerMixin implements _ListenerMixin { void dispose(); } -abstract class LocalPerformanceListenersMixin extends _ListenerMixin { +abstract class LocalAnimationListenersMixin extends _ListenerMixin { final List _listeners = []; void addListener(VoidCallback listener) { didRegisterListener(); @@ -55,7 +55,7 @@ abstract class LocalPerformanceListenersMixin extends _ListenerMixin { } } -abstract class LocalPerformanceStatusListenersMixin extends _ListenerMixin { +abstract class LocalAnimationStatusListenersMixin extends _ListenerMixin { final List _statusListeners = []; void addStatusListener(AnimationStatusListener listener) { didRegisterListener(); diff --git a/packages/flutter/lib/src/material/tabs.dart b/packages/flutter/lib/src/material/tabs.dart index 8edaf10593..74815fd2b7 100644 --- a/packages/flutter/lib/src/material/tabs.dart +++ b/packages/flutter/lib/src/material/tabs.dart @@ -381,7 +381,7 @@ class _TabsScrollBehavior extends BoundedBehavior { } } -abstract class TabBarSelectionPerformanceListener { +abstract class TabBarSelectionAnimationListener { void handleStatusChange(AnimationStatus status); void handleProgressChange(); void handleSelectionDeactivate(); @@ -503,28 +503,28 @@ class TabBarSelectionState extends State> { }); } - final List _performanceListeners = []; + final List _animationListeners = []; - void registerPerformanceListener(TabBarSelectionPerformanceListener listener) { - _performanceListeners.add(listener); + void registerAnimationListener(TabBarSelectionAnimationListener listener) { + _animationListeners.add(listener); _controller ..addStatusListener(listener.handleStatusChange) ..addListener(listener.handleProgressChange); } - void unregisterPerformanceListener(TabBarSelectionPerformanceListener listener) { - _performanceListeners.remove(listener); + void unregisterAnimationListener(TabBarSelectionAnimationListener listener) { + _animationListeners.remove(listener); _controller ..removeStatusListener(listener.handleStatusChange) ..removeListener(listener.handleProgressChange); } void deactivate() { - for (TabBarSelectionPerformanceListener listener in _performanceListeners.toList()) { + for (TabBarSelectionAnimationListener listener in _animationListeners.toList()) { listener.handleSelectionDeactivate(); - unregisterPerformanceListener(listener); + unregisterAnimationListener(listener); } - assert(_performanceListeners.isEmpty); + assert(_animationListeners.isEmpty); } Widget build(BuildContext context) { @@ -552,15 +552,15 @@ class TabBar extends Scrollable { _TabBarState createState() => new _TabBarState(); } -class _TabBarState extends ScrollableState> implements TabBarSelectionPerformanceListener { +class _TabBarState extends ScrollableState> implements TabBarSelectionAnimationListener { TabBarSelectionState _selection; bool _valueIsChanging = false; void _initSelection(TabBarSelectionState selection) { - _selection?.unregisterPerformanceListener(this); + _selection?.unregisterAnimationListener(this); _selection = selection; - _selection?.registerPerformanceListener(this); + _selection?.registerAnimationListener(this); } void initState() { @@ -576,7 +576,7 @@ class _TabBarState extends ScrollableState> implements TabBarSelect } void dispose() { - _selection?.unregisterPerformanceListener(this); + _selection?.unregisterAnimationListener(this); super.dispose(); } @@ -791,7 +791,7 @@ class TabBarView extends PageableList { _TabBarViewState createState() => new _TabBarViewState(); } -class _TabBarViewState extends PageableListState implements TabBarSelectionPerformanceListener { +class _TabBarViewState extends PageableListState implements TabBarSelectionAnimationListener { TabBarSelectionState _selection; List _items; @@ -809,7 +809,7 @@ class _TabBarViewState extends PageableListState implements TabBarSe void _initSelection(TabBarSelectionState selection) { _selection = selection; if (_selection != null) { - _selection.registerPerformanceListener(this); + _selection.registerAnimationListener(this); _updateItemsAndScrollBehavior(); } } @@ -826,7 +826,7 @@ class _TabBarViewState extends PageableListState implements TabBarSe } void dispose() { - _selection?.unregisterPerformanceListener(this); + _selection?.unregisterAnimationListener(this); super.dispose(); } @@ -874,7 +874,7 @@ class _TabBarViewState extends PageableListState implements TabBarSe void handleProgressChange() { if (_selection == null || !_selection.valueIsChanging) return; - // The TabBar is driving the TabBarSelection performance. + // The TabBar is driving the TabBarSelection animation. final Animation animation = _selection.animation; @@ -906,7 +906,7 @@ class _TabBarViewState extends PageableListState implements TabBarSe void dispatchOnScroll() { if (_selection == null || _selection.valueIsChanging) return; - // This class is driving the TabBarSelection's performance. + // This class is driving the TabBarSelection's animation. final AnimationController controller = _selection._controller; diff --git a/packages/flutter/lib/src/widgets/transitions.dart b/packages/flutter/lib/src/widgets/transitions.dart index e17ee25b6b..f32a18fa5c 100644 --- a/packages/flutter/lib/src/widgets/transitions.dart +++ b/packages/flutter/lib/src/widgets/transitions.dart @@ -175,9 +175,8 @@ class RelativeRectTween extends Tween { } /// Animated version of [Positioned] which takes a specific -/// [AnimatedRelativeRectValue] and a [PerformanceView] to transition the -/// child's position from a start position to and end position over the lifetime -/// of the performance. +/// [Animation] to transition the child's position from a start +/// position to and end position over the lifetime of the animation. /// /// Only works if it's the child of a [Stack]. class PositionedTransition extends AnimatedComponent {