mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2026-02-14 23:09:38 +00:00
Merge pull request #111 from kylehickinson/master
Text node highlights fully fade in before fading out
This commit is contained in:
@@ -520,12 +520,24 @@ ASDISPLAYNODE_INLINE CGFloat ceilPixelValue(CGFloat f)
|
||||
|
||||
weakHighlightLayer.opacity = 0.0;
|
||||
|
||||
CFTimeInterval beginTime = CACurrentMediaTime();
|
||||
CABasicAnimation *possibleFadeIn = (CABasicAnimation *)[weakHighlightLayer animationForKey:@"opacity"];
|
||||
if (possibleFadeIn) {
|
||||
// Calculate when we should begin fading out based on the end of the fade in animation,
|
||||
// Also check to make sure that the new begin time hasn't already passed
|
||||
CGFloat newBeginTime = (possibleFadeIn.beginTime + possibleFadeIn.duration);
|
||||
if (newBeginTime > beginTime) {
|
||||
beginTime = newBeginTime;
|
||||
}
|
||||
}
|
||||
|
||||
CABasicAnimation *fadeOut = [CABasicAnimation animationWithKeyPath:@"opacity"];
|
||||
fadeOut.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
|
||||
fadeOut.fromValue = @(((CALayer *)weakHighlightLayer.presentationLayer).opacity);
|
||||
fadeOut.fromValue = possibleFadeIn.toValue ?: @(((CALayer *)weakHighlightLayer.presentationLayer).opacity);
|
||||
fadeOut.toValue = @0.0;
|
||||
fadeOut.fillMode = kCAFillModeBoth;
|
||||
fadeOut.duration = ASTextNodeHighlightFadeOutDuration;
|
||||
fadeOut.beginTime = beginTime;
|
||||
|
||||
dispatch_block_t prev = [CATransaction completionBlock];
|
||||
[CATransaction setCompletionBlock:^{
|
||||
@@ -562,7 +574,6 @@ ASDISPLAYNODE_INLINE CGFloat ceilPixelValue(CGFloat f)
|
||||
// Offset highlight rects to avoid double-counting target layer's bounds.origin.
|
||||
highlightedRect.origin.x -= highlightTargetLayer.bounds.origin.x;
|
||||
highlightedRect.origin.y -= highlightTargetLayer.bounds.origin.y;
|
||||
|
||||
[converted addObject:[NSValue valueWithCGRect:highlightedRect]];
|
||||
}
|
||||
|
||||
@@ -578,6 +589,7 @@ ASDISPLAYNODE_INLINE CGFloat ceilPixelValue(CGFloat f)
|
||||
fadeIn.fromValue = @0.0;
|
||||
fadeIn.toValue = @(overlayLayer.opacity);
|
||||
fadeIn.duration = ASTextNodeHighlightFadeInDuration;
|
||||
fadeIn.beginTime = CACurrentMediaTime();
|
||||
|
||||
[overlayLayer addAnimation:fadeIn forKey:fadeIn.keyPath];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user