Only the last cell associated with a media adapter should clear its views.
// FREEBIE
This commit is contained in:
parent
50b65f0514
commit
03a97cdd70
|
@ -8,7 +8,11 @@ NS_ASSUME_NONNULL_BEGIN
|
||||||
|
|
||||||
- (void)setCellVisible:(BOOL)isVisible;
|
- (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
|
@end
|
||||||
|
|
||||||
|
|
|
@ -21,6 +21,7 @@ NS_ASSUME_NONNULL_BEGIN
|
||||||
@property (nonatomic) TSAttachmentStream *attachment;
|
@property (nonatomic) TSAttachmentStream *attachment;
|
||||||
@property (nonatomic, nullable) AttachmentUploadView *attachmentUploadView;
|
@property (nonatomic, nullable) AttachmentUploadView *attachmentUploadView;
|
||||||
@property (nonatomic) BOOL incoming;
|
@property (nonatomic) BOOL incoming;
|
||||||
|
@property (nonatomic, nullable, weak) id lastCell;
|
||||||
|
|
||||||
@end
|
@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
|
#pragma mark - JSQMessageMediaData protocol
|
||||||
|
|
||||||
- (UIView *)mediaView {
|
- (UIView *)mediaView {
|
||||||
|
|
|
@ -21,6 +21,7 @@ NS_ASSUME_NONNULL_BEGIN
|
||||||
@property (nonatomic) TSAttachmentStream *attachment;
|
@property (nonatomic) TSAttachmentStream *attachment;
|
||||||
@property (nonatomic, nullable) AttachmentUploadView *attachmentUploadView;
|
@property (nonatomic, nullable) AttachmentUploadView *attachmentUploadView;
|
||||||
@property (nonatomic) BOOL incoming;
|
@property (nonatomic) BOOL incoming;
|
||||||
|
@property (nonatomic, nullable, weak) id lastCell;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
@ -210,6 +211,15 @@ NS_ASSUME_NONNULL_BEGIN
|
||||||
// Ignore.
|
// Ignore.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void)clearCachedMediaViewsIfLastCell:(id)cell
|
||||||
|
{
|
||||||
|
OWSAssert(cell);
|
||||||
|
|
||||||
|
if (cell == self.lastCell) {
|
||||||
|
[self clearCachedMediaViews];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
NS_ASSUME_NONNULL_END
|
NS_ASSUME_NONNULL_END
|
||||||
|
|
|
@ -16,6 +16,7 @@ NS_ASSUME_NONNULL_BEGIN
|
||||||
@property (nonatomic, nullable) UIImageView *cachedImageView;
|
@property (nonatomic, nullable) UIImageView *cachedImageView;
|
||||||
@property (nonatomic, nullable) AttachmentUploadView *attachmentUploadView;
|
@property (nonatomic, nullable) AttachmentUploadView *attachmentUploadView;
|
||||||
@property (nonatomic) BOOL incoming;
|
@property (nonatomic) BOOL incoming;
|
||||||
|
@property (nonatomic, nullable, weak) id lastCell;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
@ -145,6 +146,15 @@ NS_ASSUME_NONNULL_BEGIN
|
||||||
// Ignore.
|
// Ignore.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void)clearCachedMediaViewsIfLastCell:(id)cell
|
||||||
|
{
|
||||||
|
OWSAssert(cell);
|
||||||
|
|
||||||
|
if (cell == self.lastCell) {
|
||||||
|
[self clearCachedMediaViews];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
NS_ASSUME_NONNULL_END
|
NS_ASSUME_NONNULL_END
|
||||||
|
|
|
@ -30,6 +30,7 @@ NS_ASSUME_NONNULL_BEGIN
|
||||||
@property (nonatomic, nullable) AttachmentUploadView *attachmentUploadView;
|
@property (nonatomic, nullable) AttachmentUploadView *attachmentUploadView;
|
||||||
@property (nonatomic) BOOL isAudioPlaying;
|
@property (nonatomic) BOOL isAudioPlaying;
|
||||||
@property (nonatomic) BOOL isPaused;
|
@property (nonatomic) BOOL isPaused;
|
||||||
|
@property (nonatomic, nullable, weak) id lastCell;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
@ -294,6 +295,15 @@ NS_ASSUME_NONNULL_BEGIN
|
||||||
// Ignore.
|
// Ignore.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void)clearCachedMediaViewsIfLastCell:(id)cell
|
||||||
|
{
|
||||||
|
OWSAssert(cell);
|
||||||
|
|
||||||
|
if (cell == self.lastCell) {
|
||||||
|
[self clearCachedMediaViews];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
NS_ASSUME_NONNULL_END
|
NS_ASSUME_NONNULL_END
|
||||||
|
|
|
@ -30,10 +30,22 @@ NS_ASSUME_NONNULL_BEGIN
|
||||||
self.expirationTimerViewWidthConstraint.constant = 0.0f;
|
self.expirationTimerViewWidthConstraint.constant = 0.0f;
|
||||||
|
|
||||||
[self.mediaAdapter setCellVisible:NO];
|
[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;
|
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
|
// pragma mark - OWSMessageCollectionViewCell
|
||||||
|
|
||||||
- (void)setCellVisible:(BOOL)isVisible
|
- (void)setCellVisible:(BOOL)isVisible
|
||||||
|
|
|
@ -31,10 +31,22 @@ NS_ASSUME_NONNULL_BEGIN
|
||||||
self.expirationTimerViewWidthConstraint.constant = 0.0f;
|
self.expirationTimerViewWidthConstraint.constant = 0.0f;
|
||||||
|
|
||||||
[self.mediaAdapter setCellVisible:NO];
|
[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;
|
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
|
// pragma mark - OWSMessageCollectionViewCell
|
||||||
|
|
||||||
- (void)setCellVisible:(BOOL)isVisible
|
- (void)setCellVisible:(BOOL)isVisible
|
||||||
|
|
Loading…
Reference in New Issue