@@ -85,9 +85,10 @@ - (void)layoutSubviews
8585 self.fullHourglassImageView .bounds = hourglassFrame;
8686}
8787
88- - (void )restartAnimation : (NSNotification *)notification
88+ - (void )handleReappearNotification : (NSNotification *)notification
8989{
90- [self startTimerWithExpiresAtSeconds: self .expiresAtSeconds initialDurationSeconds: self .initialDurationSeconds];
90+ DDLogVerbose (@" %@ handleReappearNotification" , self.logTag );
91+ [self startAnimation ];
9192}
9293
9394- (void )startTimerWithExpiresAtSeconds : (uint64_t )expiresAtSeconds
@@ -100,17 +101,26 @@ - (void)startTimerWithExpiresAtSeconds:(uint64_t)expiresAtSeconds
100101 initialDurationSeconds);
101102 }
102103
103- DDLogVerbose (@" %@ Starting animation timer with expiresAtSeconds: %llu initialDurationSeconds: %d " ,
104+ DDLogVerbose (@" %@ Starting timer with expiresAtSeconds: %llu initialDurationSeconds: %d " ,
104105 self.logTag ,
105106 expiresAtSeconds,
106107 initialDurationSeconds);
107108
108109 self.expiresAtSeconds = expiresAtSeconds;
109110 self.initialDurationSeconds = initialDurationSeconds;
110111 [[NSNotificationCenter defaultCenter ] addObserver: self
111- selector: @selector (restartAnimation : )
112+ selector: @selector (handleReappearNotification : )
112113 name: OWSMessagesViewControllerDidAppearNotification
113114 object: nil ];
115+ [self startAnimation ];
116+ }
117+
118+ - (void )startAnimation
119+ {
120+ DDLogVerbose (@" %@ Starting animation with expiresAtSeconds: %llu initialDurationSeconds: %d " ,
121+ self.logTag ,
122+ self.expiresAtSeconds ,
123+ self.initialDurationSeconds );
114124
115125 double secondsLeft = (double )self.expiresAtSeconds - [NSDate new ].timeIntervalSince1970 ;
116126
@@ -154,14 +164,26 @@ - (void)startTimerWithExpiresAtSeconds:(uint64_t)expiresAtSeconds
154164 [maskLayer addAnimation: revealAnimation forKey: @" revealAnimation" ];
155165 maskLayer.position = finalPosition; // don't snap back
156166
167+ __weak typeof (self) wself = self;
157168 dispatch_after (dispatch_time (DISPATCH_TIME_NOW,
158169 (long long )((secondsLeft - OWSExpirationTimerViewBlinkingSeconds) * NSEC_PER_SEC)),
159170 dispatch_get_main_queue (),
160171 ^{
161- [self startBlinking ];
172+ [wself startBlinking ];
162173 });
163174}
164175
176+ - (void )stopTimer
177+ {
178+ DDLogVerbose (@" %@ Stopping Timer." , self.logTag );
179+ [[NSNotificationCenter defaultCenter ] removeObserver: self
180+ name: OWSMessagesViewControllerDidAppearNotification
181+ object: nil ];
182+
183+ [self .layer removeAnimationForKey: @" alphaBlink" ];
184+ self.layer .opacity = 1 ;
185+ }
186+
165187- (BOOL )itIsTimeToBlink
166188{
167189 double secondsLeft = (double )self.expiresAtSeconds - [NSDate new ].timeIntervalSince1970 ;
@@ -185,12 +207,6 @@ - (void)startBlinking
185207 [self .layer addAnimation: blinkAnimation forKey: @" alphaBlink" ];
186208}
187209
188- - (void )stopBlinking
189- {
190- [self .layer removeAnimationForKey: @" alphaBlink" ];
191- self.layer .opacity = 1 ;
192- }
193-
194210#pragma mark - Logging
195211
196212+ (NSString *)logTag
0 commit comments