Skip to content

Commit 023e62e

Browse files
committed
fix reused cell starts blinking too early
There are dispatch_async's waiting to be fired on some re-used cells. // FREEBIE
1 parent 94a2302 commit 023e62e

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

Signal/src/views/OWSExpirationTimerView.m

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88

99
NS_ASSUME_NONNULL_BEGIN
1010

11+
12+
double const OWSExpirationTimerViewBlinkingSeconds = 2;
13+
1114
@interface OWSExpirationTimerView ()
1215

1316
@property (nonatomic) uint32_t initialDurationSeconds;
@@ -142,15 +145,27 @@ - (void)startTimerWithExpiresAtSeconds:(uint64_t)expiresAtSeconds
142145
[maskLayer addAnimation:revealAnimation forKey:@"revealAnimation"];
143146
maskLayer.position = finalPosition; // don't snap back
144147

145-
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, ((long long)secondsLeft - 2) * (long long)NSEC_PER_SEC),
148+
dispatch_after(dispatch_time(DISPATCH_TIME_NOW,
149+
(long long)((secondsLeft - OWSExpirationTimerViewBlinkingSeconds) * NSEC_PER_SEC)),
146150
dispatch_get_main_queue(),
147151
^{
148152
[self startBlinking];
149153
});
150154
}
151155

156+
- (BOOL)itIsTimeToBlink
157+
{
158+
double secondsLeft = (double)self.expiresAtSeconds - [NSDate new].timeIntervalSince1970;
159+
return secondsLeft <= OWSExpirationTimerViewBlinkingSeconds;
160+
}
161+
152162
- (void)startBlinking
153163
{
164+
if (![self itIsTimeToBlink]) {
165+
DDLogVerbose(@"Refusing to start blinking too early. Reused cell?");
166+
return;
167+
}
168+
154169
CABasicAnimation *blinkAnimation = [CABasicAnimation animationWithKeyPath:@"opacity"];
155170
blinkAnimation.duration = 0.5;
156171
blinkAnimation.fromValue = @(1.0);

0 commit comments

Comments
 (0)