Skip to content
This repository has been archived by the owner on Mar 24, 2022. It is now read-only.

Commit

Permalink
Add resume animations that resumes all queued up animations
Browse files Browse the repository at this point in the history
Also add way to reset animations in the case that cedar is not being used
  • Loading branch information
younata committed Jan 17, 2016
1 parent db11948 commit dacaae8
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 3 deletions.
16 changes: 16 additions & 0 deletions UIKit/Spec/Stubs/UIViewSpec+StubbedAnimations.mm
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,22 @@
[[UIView lastAnimation] duration] should equal(0.666);
});

it(@"should resume all queued up animations when resume is called", ^{
[UIView resumeAnimations];

animationBlockCalled should be_truthy;
completionBlockCalled should be_truthy;
[UIView animations] should be_empty;
});

it(@"should reset all animations if +reset is called", ^{
[UIView resetAnimations];

animationBlockCalled should be_falsy;
completionBlockCalled should be_falsy;
[UIView animations] should be_empty;
});

describe(@"running animations", ^{
beforeEach(^{
[[UIView lastAnimation] animate];
Expand Down
4 changes: 3 additions & 1 deletion UIKit/SpecHelper/Stubs/UIView+StubbedAnimation.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@
+ (CGFloat)lastAnimationInitialSpringVelocity;

+ (void)pauseAnimations;
+ (void)resumeAnimations;
+ (NSArray *)animations;
+ (PCKViewAnimation *)lastAnimation;
+ (void)resetAnimations;

@end
@end
19 changes: 17 additions & 2 deletions UIKit/SpecHelper/Stubs/UIView+StubbedAnimation.m
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,17 @@ + (void)pauseAnimations {
shouldImmediatelyExecuteAnimationBlocks__ = NO;
}

+ (void)resumeAnimations {
shouldImmediatelyExecuteAnimationBlocks__ = YES;
while (animations__.count != 0) {
PCKViewAnimation *animation = [animations__ firstObject];
[animations__ removeObjectAtIndex:0];

[animation animate];
[animation complete];
}
}

+ (NSArray *)animations {
return animations__;
}
Expand All @@ -37,6 +48,11 @@ + (PCKViewAnimation *)lastAnimation {
return [animations__ lastObject];
}

+ (void)resetAnimations {
shouldImmediatelyExecuteAnimationBlocks__ = YES;
animations__ = [NSMutableArray array];
}

#pragma mark - Overrides

+ (void)animateWithDuration:(NSTimeInterval)duration animations:(void (^)(void))animations completion:(void (^)(BOOL))completion {
Expand Down Expand Up @@ -72,8 +88,7 @@ + (void)animateWithDuration:(NSTimeInterval)duration delay:(NSTimeInterval)delay
#pragma mark - CedarHooks

+ (void)beforeEach {
shouldImmediatelyExecuteAnimationBlocks__ = YES;
animations__ = [NSMutableArray array];
[self resetAnimations];
}

@end
Expand Down

0 comments on commit dacaae8

Please sign in to comment.