Only the last cell associated with a media adapter should clear its views.

// FREEBIE
This commit is contained in:
Matthew Chen 2017-04-21 09:56:31 -04:00
parent 50b65f0514
commit 03a97cdd70
7 changed files with 71 additions and 3 deletions

View File

@ -8,7 +8,11 @@ NS_ASSUME_NONNULL_BEGIN
- (void)setCellVisible:(BOOL)isVisible;
- (void)clearCachedMediaViews;
// Cells will request that this adapter clear its cached media views,
// but the adapter should only honor requests from the last cell to
// use its views.
- (void)setLastCell:(nullable id)cell;
- (void)clearCachedMediaViewsIfLastCell:(id)cell;
@end

View File

@ -21,6 +21,7 @@ NS_ASSUME_NONNULL_BEGIN
@property (nonatomic) TSAttachmentStream *attachment;
@property (nonatomic, nullable) AttachmentUploadView *attachmentUploadView;
@property (nonatomic) BOOL incoming;
@property (nonatomic, nullable, weak) id lastCell;
@end
@ -79,6 +80,15 @@ NS_ASSUME_NONNULL_BEGIN
}
}
- (void)clearCachedMediaViewsIfLastCell:(id)cell
{
OWSAssert(cell);
if (cell == self.lastCell) {
[self clearCachedMediaViews];
}
}
#pragma mark - JSQMessageMediaData protocol
- (UIView *)mediaView {

View File

@ -21,6 +21,7 @@ NS_ASSUME_NONNULL_BEGIN
@property (nonatomic) TSAttachmentStream *attachment;
@property (nonatomic, nullable) AttachmentUploadView *attachmentUploadView;
@property (nonatomic) BOOL incoming;
@property (nonatomic, nullable, weak) id lastCell;
@end
@ -210,6 +211,15 @@ NS_ASSUME_NONNULL_BEGIN
// Ignore.
}
- (void)clearCachedMediaViewsIfLastCell:(id)cell
{
OWSAssert(cell);
if (cell == self.lastCell) {
[self clearCachedMediaViews];
}
}
@end
NS_ASSUME_NONNULL_END

View File

@ -16,6 +16,7 @@ NS_ASSUME_NONNULL_BEGIN
@property (nonatomic, nullable) UIImageView *cachedImageView;
@property (nonatomic, nullable) AttachmentUploadView *attachmentUploadView;
@property (nonatomic) BOOL incoming;
@property (nonatomic, nullable, weak) id lastCell;
@end
@ -145,6 +146,15 @@ NS_ASSUME_NONNULL_BEGIN
// Ignore.
}
- (void)clearCachedMediaViewsIfLastCell:(id)cell
{
OWSAssert(cell);
if (cell == self.lastCell) {
[self clearCachedMediaViews];
}
}
@end
NS_ASSUME_NONNULL_END

View File

@ -30,6 +30,7 @@ NS_ASSUME_NONNULL_BEGIN
@property (nonatomic, nullable) AttachmentUploadView *attachmentUploadView;
@property (nonatomic) BOOL isAudioPlaying;
@property (nonatomic) BOOL isPaused;
@property (nonatomic, nullable, weak) id lastCell;
@end
@ -294,6 +295,15 @@ NS_ASSUME_NONNULL_BEGIN
// Ignore.
}
- (void)clearCachedMediaViewsIfLastCell:(id)cell
{
OWSAssert(cell);
if (cell == self.lastCell) {
[self clearCachedMediaViews];
}
}
@end
NS_ASSUME_NONNULL_END

View File

@ -30,10 +30,22 @@ NS_ASSUME_NONNULL_BEGIN
self.expirationTimerViewWidthConstraint.constant = 0.0f;
[self.mediaAdapter setCellVisible:NO];
[self.mediaAdapter clearCachedMediaViews];
// Clear this adapter's views IFF this was the last cell to use this adapter.
[self.mediaAdapter clearCachedMediaViewsIfLastCell:self];
[_mediaAdapter setLastCell:nil];
self.mediaAdapter = nil;
}
- (void)setMediaAdapter:(nullable id<OWSMessageMediaAdapter>)mediaAdapter
{
_mediaAdapter = mediaAdapter;
// Mark this as the last cell to use this adapter.
[_mediaAdapter setLastCell:self];
}
// pragma mark - OWSMessageCollectionViewCell
- (void)setCellVisible:(BOOL)isVisible

View File

@ -31,10 +31,22 @@ NS_ASSUME_NONNULL_BEGIN
self.expirationTimerViewWidthConstraint.constant = 0.0f;
[self.mediaAdapter setCellVisible:NO];
[self.mediaAdapter clearCachedMediaViews];
// Clear this adapter's views IFF this was the last cell to use this adapter.
[self.mediaAdapter clearCachedMediaViewsIfLastCell:self];
[_mediaAdapter setLastCell:nil];
self.mediaAdapter = nil;
}
- (void)setMediaAdapter:(nullable id<OWSMessageMediaAdapter>)mediaAdapter
{
_mediaAdapter = mediaAdapter;
// Mark this as the last cell to use this adapter.
[_mediaAdapter setLastCell:self];
}
// pragma mark - OWSMessageCollectionViewCell
- (void)setCellVisible:(BOOL)isVisible