Skip to content

Commit

Permalink
Also ignore the KIFTouchVisualizerView
Browse files Browse the repository at this point in the history
Credit to @amorde for finding this
  • Loading branch information
justinseanmartin committed Jun 18, 2024
1 parent 2c593d2 commit cca866a
Showing 1 changed file with 25 additions and 19 deletions.
44 changes: 25 additions & 19 deletions Sources/KIF/Additions/CALayer-KIFAdditions.m
Original file line number Diff line number Diff line change
Expand Up @@ -27,25 +27,31 @@ - (BOOL)hasAnimations
{
__block BOOL result = NO;
[self performBlockOnDescendentLayers:^(CALayer *layer, BOOL *stop) {
// explicitly exclude _UIParallaxMotionEffect as it is used in alertviews, and we don't want every alertview to be paused
// explicitly exclude UITextSelectionViewCaretBlinkAnimation as it is used in textfields, and we don't want every view with textfields to be paused
BOOL hasAnimation = layer.animationKeys.count != 0 && ![layer.animationKeys containsObject:@"_UIParallaxMotionEffect"] && ![layer.animationKeys containsObject:@"UITextSelectionViewCaretBlinkAnimation"];
if (hasAnimation && !layer.hidden) {
double currentTime = CACurrentMediaTime() * [layer KIF_absoluteSpeed];

[layer.animationKeys enumerateObjectsUsingBlock:^(NSString *animationKey, NSUInteger idx, BOOL *innerStop) {
CAAnimation *animation = [layer animationForKey:animationKey];
double beginTime = [animation beginTime];
double completionTime = [animation KIF_completionTime];

// Ignore long running animations (> 1 minute duration)
if (currentTime >= beginTime && completionTime < currentTime + 60 && currentTime < completionTime) {
result = YES;
*innerStop = YES;
*stop = YES;
}
}];
}
// explicitly exclude _UIParallaxMotionEffect as it is used in alertviews, and we don't want every alertview to be paused
// explicitly exclude UITextSelectionViewCaretBlinkAnimation as it is used in textfields, and we don't want every view with textfields to be paused
BOOL hasAnimation = layer.animationKeys.count != 0 && ![layer.animationKeys containsObject:@"_UIParallaxMotionEffect"] && ![layer.animationKeys containsObject:@"UITextSelectionViewCaretBlinkAnimation"];

// Ignore the animation of the KIF touch visualizer circle as it does not affect any view behavior
if ([NSStringFromClass(layer.delegate.class) isEqualToString:@"KIFTouchVisualizerView"]) {
hasAnimation = NO;
}

if (hasAnimation && !layer.hidden) {
double currentTime = CACurrentMediaTime() * [layer KIF_absoluteSpeed];

[layer.animationKeys enumerateObjectsUsingBlock:^(NSString *animationKey, NSUInteger idx, BOOL *innerStop) {
CAAnimation *animation = [layer animationForKey:animationKey];
double beginTime = [animation beginTime];
double completionTime = [animation KIF_completionTime];

// Ignore long running animations (> 1 minute duration)
if (currentTime >= beginTime && completionTime < currentTime + 60 && currentTime < completionTime) {
result = YES;
*innerStop = YES;
*stop = YES;
}
}];
}
}];
return result;
}
Expand Down

0 comments on commit cca866a

Please sign in to comment.