Commit 61f8651c authored by Hixie's avatar Hixie

Code cleanup

- Add documentation for AnimationTiming.
- typo: defaules -> defaults.
- added type information to isWatching() signature.
- made Widget.toStringName() include more useful information.
- cleaned up StatefulComponent._sync(): more specific signature, change
  redundant if to else, remove redundant cast.
- change order of TransitionBase arguments for consistency.
- prevent TransitionBase from affecting the performance in its
  constructor when it didn't create it (but see #1103).
- remove TODO() from @mpcomplete... no, there is not currently a better
  way to inherit a constructor, unfortunately.
parent 945b5bcd
...@@ -22,7 +22,9 @@ abstract class AnimatedVariable { ...@@ -22,7 +22,9 @@ abstract class AnimatedVariable {
String toString(); String toString();
} }
/// /// Used by [AnimationPerformance] to convert the timing of a performance to a different timescale.
/// For example, by setting different values for the interval and reverseInterval, a performance
/// can be made to take longer in one direction that the other.
class AnimationTiming { class AnimationTiming {
AnimationTiming({ AnimationTiming({
this.interval, this.interval,
...@@ -36,7 +38,7 @@ class AnimationTiming { ...@@ -36,7 +38,7 @@ class AnimationTiming {
/// The interval during which this timing is active in the reverse direction /// The interval during which this timing is active in the reverse direction
/// ///
/// If this field is null, the timing defaules to using [interval] in both directions. /// If this field is null, the timing defaults to using [interval] in both directions.
Interval reverseInterval; Interval reverseInterval;
/// The curve that this timing applies to the animation clock in the forward direction /// The curve that this timing applies to the animation clock in the forward direction
...@@ -44,7 +46,7 @@ class AnimationTiming { ...@@ -44,7 +46,7 @@ class AnimationTiming {
/// The curve that this timing applies to the animation clock in the reverse direction /// The curve that this timing applies to the animation clock in the reverse direction
/// ///
/// If this field is null, the timing defaules to using [curve] in both directions. /// If this field is null, the timing defaults to using [curve] in both directions.
Curve reverseCurve; Curve reverseCurve;
/// Applies this timing to the given animation clock value in the given direction /// Applies this timing to the given animation clock value in the given direction
......
...@@ -20,7 +20,9 @@ abstract class AnimatedComponent extends StatefulComponent { ...@@ -20,7 +20,9 @@ abstract class AnimatedComponent extends StatefulComponent {
}); });
} }
bool isWatching(performance) => _watchedPerformances.contains(performance); bool isWatching(AnimationPerformance performance) {
return _watchedPerformances.contains(performance);
}
void watch(AnimationPerformance performance) { void watch(AnimationPerformance performance) {
assert(!isWatching(performance)); assert(!isWatching(performance));
......
...@@ -511,9 +511,10 @@ abstract class Widget { ...@@ -511,9 +511,10 @@ abstract class Widget {
return '$startPrefix${toStringName()}$suffix\n$childrenString'; return '$startPrefix${toStringName()}$suffix\n$childrenString';
} }
String toStringName() { String toStringName() {
if (key == null) String keyString = key == null ? '' : '$key; ';
return '$runtimeType(unkeyed; hashCode=$hashCode)'; String hashCodeString = 'hashCode=$hashCode';
return '$runtimeType($key; hashCode=$hashCode)'; String mountedString = mounted ? '; mounted' : '; not mounted';
return '$runtimeType($keyString$hashCodeString$mountedString)';
} }
// This function can be safely called when the layout is valid. // This function can be safely called when the layout is valid.
...@@ -916,16 +917,15 @@ abstract class StatefulComponent extends Component { ...@@ -916,16 +917,15 @@ abstract class StatefulComponent extends Component {
// because our retainStatefulNodeIfPossible() method returns true, // because our retainStatefulNodeIfPossible() method returns true,
// when _sync is called, our 'old' is actually the new instance that // when _sync is called, our 'old' is actually the new instance that
// we are to copy state from. // we are to copy state from.
void _sync(Widget old, dynamic slot) { void _sync(StatefulComponent old, dynamic slot) {
if (old == null) { if (old == null) {
if (!_isStateInitialized) { if (!_isStateInitialized) {
initState(); initState();
_isStateInitialized = true; _isStateInitialized = true;
} }
} } else {
if (old != null) {
assert(_isStateInitialized); assert(_isStateInitialized);
assert(!(old as StatefulComponent)._isStateInitialized); assert(!old._isStateInitialized);
syncConstructorArguments(old); syncConstructorArguments(old);
} }
super._sync(old, slot); super._sync(old, slot);
......
...@@ -60,8 +60,8 @@ class _AnchorTransition extends AnimatedComponent { ...@@ -60,8 +60,8 @@ class _AnchorTransition extends AnimatedComponent {
abstract class TransitionBase extends AnimatedComponent { abstract class TransitionBase extends AnimatedComponent {
TransitionBase({ TransitionBase({
Key key, Key key,
this.anchor,
this.child, this.child,
this.anchor,
this.direction, this.direction,
this.duration, this.duration,
this.performance, this.performance,
...@@ -84,9 +84,9 @@ abstract class TransitionBase extends AnimatedComponent { ...@@ -84,9 +84,9 @@ abstract class TransitionBase extends AnimatedComponent {
if (performance == null) { if (performance == null) {
assert(duration != null); assert(duration != null);
performance = new AnimationPerformance(duration: duration); performance = new AnimationPerformance(duration: duration);
if (direction == Direction.reverse)
performance.progress = 1.0;
} }
if (direction == Direction.reverse)
performance.progress = 1.0;
performance.addStatusListener(_checkStatusChanged); performance.addStatusListener(_checkStatusChanged);
watch(performance); watch(performance);
...@@ -127,8 +127,6 @@ abstract class TransitionBase extends AnimatedComponent { ...@@ -127,8 +127,6 @@ abstract class TransitionBase extends AnimatedComponent {
} }
class SlideTransition extends TransitionBase { class SlideTransition extends TransitionBase {
// TODO(mpcomplete): this constructor is mostly boilerplate, passing values
// to super. Is there a simpler way?
SlideTransition({ SlideTransition({
Key key, Key key,
Anchor anchor, Anchor anchor,
......
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