Skip to content

Commit 49de772

Browse files
authored
Fix slow reloading conversation view. (signalapp#1397)
Fix animation memory leak exacerbated every time you reload a conversation with expiration timers. Stop animation on cells that aren't currently being displayed. This is relatively minor compared to the above, but still, no reason to waste cycles. // FREEBIE
1 parent 50ce283 commit 49de772

File tree

9 files changed

+58
-20
lines changed

9 files changed

+58
-20
lines changed

Podfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ source 'https://github.com/CocoaPods/Specs.git'
33

44
target 'Signal' do
55
pod 'SocketRocket', :git => 'https://github.com/facebook/SocketRocket.git'
6-
pod 'SignalServiceKit', git: 'https://github.com/WhisperSystems/SignalServiceKit.git', branch: 'mkirk/empty-bubble-disappearing-self#1393'
6+
pod 'SignalServiceKit', git: 'https://github.com/WhisperSystems/SignalServiceKit.git'
77
#pod 'SignalServiceKit', path: '../SignalServiceKit'
88
pod 'OpenSSL', '~> 1.0.208'
99
pod 'PastelogKit', '~> 1.3'

Podfile.lock

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,13 +122,12 @@ DEPENDENCIES:
122122
- OpenSSL (~> 1.0.208)
123123
- PastelogKit (~> 1.3)
124124
- SCWaveformView (~> 1.0)
125-
- SignalServiceKit (from `https://github.com/WhisperSystems/SignalServiceKit.git`, branch `mkirk/empty-bubble-disappearing-self#1393`)
125+
- SignalServiceKit (from `https://github.com/WhisperSystems/SignalServiceKit.git`)
126126
- SocketRocket (from `https://github.com/facebook/SocketRocket.git`)
127127
- ZXingObjC
128128

129129
EXTERNAL SOURCES:
130130
SignalServiceKit:
131-
:branch: mkirk/empty-bubble-disappearing-self#1393
132131
:git: https://github.com/WhisperSystems/SignalServiceKit.git
133132
SocketRocket:
134133
:git: https://github.com/facebook/SocketRocket.git
@@ -167,6 +166,6 @@ SPEC CHECKSUMS:
167166
YapDatabase: b1e43555a34a5298e23a045be96817a5ef0da58f
168167
ZXingObjC: bf15b3814f7a105b6d99f47da2333c93a063650a
169168

170-
PODFILE CHECKSUM: e8495fa75a157c62674121b7f0faf30ee7542ec6
169+
PODFILE CHECKSUM: f5e3e3b84c4c471518f4e3a32746e6a0e13808f6
171170

172171
COCOAPODS: 1.0.1

Signal/Signal-Info.plist

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
<key>CFBundlePackageType</key>
2222
<string>APPL</string>
2323
<key>CFBundleShortVersionString</key>
24-
<string>2.6.1</string>
24+
<string>2.6.2</string>
2525
<key>CFBundleSignature</key>
2626
<string>????</string>
2727
<key>CFBundleURLTypes</key>
@@ -38,7 +38,7 @@
3838
</dict>
3939
</array>
4040
<key>CFBundleVersion</key>
41-
<string>2.6.1.3</string>
41+
<string>2.6.2.0</string>
4242
<key>ITSAppUsesNonExemptEncryption</key>
4343
<false/>
4444
<key>LOGS_EMAIL</key>

Signal/src/view controllers/MessagesViewController.m

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -664,6 +664,9 @@ - (void)didPressSendButton:(UIButton *)button
664664
}
665665
}
666666

667+
#pragma mark - UICollectionViewDelegate
668+
669+
// Override JSQMVC
667670
- (BOOL)collectionView:(JSQMessagesCollectionView *)collectionView shouldShowMenuForItemAtIndexPath:(NSIndexPath *)indexPath
668671
{
669672
if (indexPath == nil) {
@@ -679,6 +682,16 @@ - (BOOL)collectionView:(JSQMessagesCollectionView *)collectionView shouldShowMen
679682
return YES;
680683
}
681684

685+
- (void)collectionView:(UICollectionView *)collectionView
686+
didEndDisplayingCell:(nonnull UICollectionViewCell *)cell
687+
forItemAtIndexPath:(nonnull NSIndexPath *)indexPath
688+
{
689+
if ([cell conformsToProtocol:@protocol(OWSExpirableMessageView)]) {
690+
id<OWSExpirableMessageView> expirableView = (id<OWSExpirableMessageView>)cell;
691+
[expirableView stopExpirationTimer];
692+
}
693+
}
694+
682695
#pragma mark - JSQMessages CollectionView DataSource
683696

684697
- (id<OWSMessageData>)collectionView:(JSQMessagesCollectionView *)collectionView

Signal/src/views/OWSExpirableMessageView.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ static const CGFloat OWSExpirableMessageViewTimerWidth = 10.0f;
1515
- (void)startExpirationTimerWithExpiresAtSeconds:(uint64_t)expiresAtSeconds
1616
initialDurationSeconds:(uint32_t)initialDurationSeconds;
1717

18+
- (void)stopExpirationTimer;
19+
1820
@end
1921

2022
NS_ASSUME_NONNULL_END

Signal/src/views/OWSExpirationTimerView.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ NS_ASSUME_NONNULL_BEGIN
1010
- (void)startTimerWithExpiresAtSeconds:(uint64_t)expiresAtSeconds
1111
initialDurationSeconds:(uint32_t)initialDurationSeconds;
1212

13-
- (void)stopBlinking;
13+
- (void)stopTimer;
1414

1515
@end
1616

Signal/src/views/OWSExpirationTimerView.m

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Signal/src/views/OWSIncomingMessageCollectionViewCell.m

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ - (void)awakeFromNib
2424
- (void)prepareForReuse
2525
{
2626
[super prepareForReuse];
27-
[self.expirationTimerView stopBlinking];
2827
self.expirationTimerViewWidthConstraint.constant = 0.0f;
2928
}
3029

@@ -38,6 +37,11 @@ - (void)startExpirationTimerWithExpiresAtSeconds:(uint64_t)expiresAtSeconds
3837
initialDurationSeconds:initialDurationSeconds];
3938
}
4039

40+
- (void)stopExpirationTimer
41+
{
42+
[self.expirationTimerView stopTimer];
43+
}
44+
4145
@end
4246

4347
NS_ASSUME_NONNULL_END

Signal/src/views/OWSOutgoingMessageCollectionViewCell.m

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ - (void)awakeFromNib
2424
- (void)prepareForReuse
2525
{
2626
[super prepareForReuse];
27-
[self.expirationTimerView stopBlinking];
2827
self.expirationTimerViewWidthConstraint.constant = 0.0f;
2928
}
3029

@@ -38,6 +37,11 @@ - (void)startExpirationTimerWithExpiresAtSeconds:(uint64_t)expiresAtSeconds
3837
initialDurationSeconds:initialDurationSeconds];
3938
}
4039

40+
- (void)stopExpirationTimer
41+
{
42+
[self.expirationTimerView stopTimer];
43+
}
44+
4145
@end
4246

4347
NS_ASSUME_NONNULL_END

0 commit comments

Comments
 (0)