FIXED: A grouping context does not inherit the completion handler ...

… from the current context.
Also removed CPAnimationContext -copy method. CPAnimationContext is not
CPCopying compliant.

TEST: CPAnimationContextTest ->
testCompletionHandlerWithoutAnimatorWithGrouping2
This commit is contained in:
cacaodev committed 2017-07-25 12:04:58 +02:00
1 parent 03dccbe613
commit 81916d0f45
3 files changed
+37 -17

No files matched your search

+3 -16
View File
@@ -66,16 +66,6 @@ var _CPAnimationContextStack = nil,
return self;
}
- (id)copy
{
var context = [[CPAnimationContext alloc] init];
[context setDuration:[self duration]];
[context setTimingFunction:[self timingFunction]];
[context setCompletionHandler:[self completionHandler]];
return context;
}
+ (void)_scheduleAnimationContextStackFlush
{
if (!_animationFlushingObserver)
@@ -90,16 +80,13 @@ var _CPAnimationContextStack = nil,
+ (void)beginGrouping
{
var newContext;
var newContext = [[CPAnimationContext alloc] init];
if ([_CPAnimationContextStack count])
{
var currentContext = [_CPAnimationContextStack lastObject];
newContext = [currentContext copy];
}
else
{
newContext = [[CPAnimationContext alloc] init];
[newContext setDuration:[currentContext duration]];
[newContext setTimingFunction:[currentContext timingFunction]];
}
[_CPAnimationContextStack addObject:newContext];
@@ -181,8 +181,18 @@ var ANIMATIONS_NAMES = ["Fade In", "Fade Out", "Background Color", "Frame Origin
*/
- (IBAction)removeFromSuperview:(id)sender
{
[CPAnimationContext beginGrouping];
[[CPAnimationContext currentContext] setDuration:3];
[[CPAnimationContext currentContext] setCompletionHandler:function()
{
CPLogConsole("removedFromSuperview");
}];
[[leftView animator] removeFromSuperview];
[[rightView animator] removeFromSuperview];
[CPAnimationContext endGrouping];
}
- (IBAction)revert:(id)sender
@@ -333,7 +343,7 @@ var ANIMATIONS_NAMES = ["Fade In", "Fade Out", "Background Color", "Frame Origin
- (CABasicAnimation)fadeOutAnimation
{
var animation = [CABasicAnimation animationWithKeyPath:@"alphaValue"];
[animation setDuration:0.2];
[animation setDuration:2];
[animation setFromValue:1];
[animation setToValue:0];
@@ -89,7 +89,22 @@
{
var completions = @[];
var ctx = [CPAnimationContext currentContext];
[ctx setDuration:0.1];
[CPAnimationContext beginGrouping];
[ctx setCompletionHandler:function()
{
[completions addObject:@"done"];
UIAssert([completions isEqualToArray:@["done"]]);
}];
[CPAnimationContext endGrouping];
}
- (void)testCompletionHandlerWithoutAnimatorWithGrouping2
{
var completions = @[];
var ctx = [CPAnimationContext currentContext];
[ctx setDuration:0.1];
@@ -99,6 +114,14 @@
UIAssert([completions isEqualToArray:@["done"]]);
}];
// Cocoa : When grouping begins, the grouping context inherits
// the duration & timingFunction properties from the current context
// but NOT the completionHandler.
// In this test, the completion handler should be performed once as part
// of the current context (with no animations) but not as part of the
// grouping context.
[CPAnimationContext beginGrouping];
[CPAnimationContext endGrouping];
}