@@ -64,49 +64,54 @@ - (void)animateWithTiming:(MDMMotionTiming)timing
64
64
[layer setValue: [values lastObject ] forKeyPath: keyPath];
65
65
[CATransaction commit ];
66
66
67
- if (timing. duration == 0 || timing. curve . type == MDMMotionCurveTypeInstant) {
67
+ void (^exitEarly)( void ) = ^ {
68
68
if (completion) {
69
69
completion ();
70
70
}
71
- return ;
72
- }
71
+ };
73
72
74
73
CGFloat timeScaleFactor = [self computedTimeScaleFactor ];
75
74
CABasicAnimation *animation = MDMAnimationFromTiming (timing, timeScaleFactor);
76
75
77
- if (animation) {
78
- animation.keyPath = keyPath;
76
+ if (animation == nil ) {
77
+ exitEarly ();
78
+ return ;
79
+ }
80
+
81
+ animation.keyPath = keyPath;
79
82
80
- id initialValue;
81
- if (_beginFromCurrentState) {
82
- if ([layer presentationLayer ]) {
83
- initialValue = [[layer presentationLayer ] valueForKeyPath: keyPath];
84
- } else {
85
- initialValue = [layer valueForKeyPath: keyPath];
86
- }
83
+ id initialValue;
84
+ if (_beginFromCurrentState) {
85
+ if ([layer presentationLayer ]) {
86
+ initialValue = [[layer presentationLayer ] valueForKeyPath: keyPath];
87
87
} else {
88
- initialValue = [values firstObject ];
88
+ initialValue = [layer valueForKeyPath: keyPath ];
89
89
}
90
+ } else {
91
+ initialValue = [values firstObject ];
92
+ }
93
+
94
+ animation.fromValue = initialValue;
95
+ animation.toValue = [values lastObject ];
90
96
91
- animation.fromValue = initialValue;
92
- animation.toValue = [values lastObject ];
97
+ if ([animation.fromValue isEqual: animation.toValue]) {
98
+ exitEarly ();
99
+ return ;
100
+ }
93
101
94
- if (![animation.fromValue isEqual: animation.toValue]) {
95
- MDMConfigureAnimation (animation, self.additive , timing);
102
+ MDMConfigureAnimation (animation, self.additive , timing);
96
103
97
- if (timing.delay != 0 ) {
98
- animation.beginTime = ([layer convertTime: CACurrentMediaTime () fromLayer: nil ]
99
- + timing.delay * timeScaleFactor);
100
- animation.fillMode = kCAFillModeBackwards ;
101
- }
104
+ if (timing.delay != 0 ) {
105
+ animation.beginTime = ([layer convertTime: CACurrentMediaTime () fromLayer: nil ]
106
+ + timing.delay * timeScaleFactor);
107
+ animation.fillMode = kCAFillModeBackwards ;
108
+ }
102
109
103
- NSString *key = _additive ? nil : keyPath;
104
- [_registrar addAnimation: animation toLayer: layer forKey: key completion: completion];
110
+ NSString *key = _additive ? nil : keyPath;
111
+ [_registrar addAnimation: animation toLayer: layer forKey: key completion: completion];
105
112
106
- for (void (^tracer)(CALayer *, CAAnimation *) in _tracers) {
107
- tracer (layer, animation);
108
- }
109
- }
113
+ for (void (^tracer)(CALayer *, CAAnimation *) in _tracers) {
114
+ tracer (layer, animation);
110
115
}
111
116
}
112
117
0 commit comments