Merge branch 'charlesmchen/onlyLastCellClearsAdapterViews'

pull/1/head
Matthew Chen 8 years ago
commit ba3f964d5e

@ -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)setLastPresentingCell:(nullable id)cell;
- (void)clearCachedMediaViewsIfLastPresentingCell:(id)cell;
@end

@ -22,6 +22,9 @@ NS_ASSUME_NONNULL_BEGIN
@property (nonatomic, nullable) AttachmentUploadView *attachmentUploadView;
@property (nonatomic) BOOL incoming;
// See comments on OWSMessageMediaAdapter.
@property (nonatomic, nullable, weak) id lastPresentingCell;
@end
#pragma mark -
@ -79,6 +82,15 @@ NS_ASSUME_NONNULL_BEGIN
}
}
- (void)clearCachedMediaViewsIfLastPresentingCell:(id)cell
{
OWSAssert(cell);
if (cell == self.lastPresentingCell) {
[self clearCachedMediaViews];
}
}
#pragma mark - JSQMessageMediaData protocol
- (UIView *)mediaView {

@ -22,6 +22,9 @@ NS_ASSUME_NONNULL_BEGIN
@property (nonatomic, nullable) AttachmentUploadView *attachmentUploadView;
@property (nonatomic) BOOL incoming;
// See comments on OWSMessageMediaAdapter.
@property (nonatomic, nullable, weak) id lastPresentingCell;
@end
#pragma mark -
@ -210,6 +213,15 @@ NS_ASSUME_NONNULL_BEGIN
// Ignore.
}
- (void)clearCachedMediaViewsIfLastPresentingCell:(id)cell
{
OWSAssert(cell);
if (cell == self.lastPresentingCell) {
[self clearCachedMediaViews];
}
}
@end
NS_ASSUME_NONNULL_END

@ -17,6 +17,9 @@ NS_ASSUME_NONNULL_BEGIN
@property (nonatomic, nullable) AttachmentUploadView *attachmentUploadView;
@property (nonatomic) BOOL incoming;
// See comments on OWSMessageMediaAdapter.
@property (nonatomic, nullable, weak) id lastPresentingCell;
@end
#pragma mark -
@ -145,6 +148,15 @@ NS_ASSUME_NONNULL_BEGIN
// Ignore.
}
- (void)clearCachedMediaViewsIfLastPresentingCell:(id)cell
{
OWSAssert(cell);
if (cell == self.lastPresentingCell) {
[self clearCachedMediaViews];
}
}
@end
NS_ASSUME_NONNULL_END

@ -31,6 +31,9 @@ NS_ASSUME_NONNULL_BEGIN
@property (nonatomic) BOOL isAudioPlaying;
@property (nonatomic) BOOL isPaused;
// See comments on OWSMessageMediaAdapter.
@property (nonatomic, nullable, weak) id lastPresentingCell;
@end
#pragma mark -
@ -294,6 +297,15 @@ NS_ASSUME_NONNULL_BEGIN
// Ignore.
}
- (void)clearCachedMediaViewsIfLastPresentingCell:(id)cell
{
OWSAssert(cell);
if (cell == self.lastPresentingCell) {
[self clearCachedMediaViews];
}
}
@end
NS_ASSUME_NONNULL_END

@ -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 clearCachedMediaViewsIfLastPresentingCell:self];
[_mediaAdapter setLastPresentingCell:nil];
self.mediaAdapter = nil;
}
- (void)setMediaAdapter:(nullable id<OWSMessageMediaAdapter>)mediaAdapter
{
_mediaAdapter = mediaAdapter;
// Mark this as the last cell to use this adapter.
[_mediaAdapter setLastPresentingCell:self];
}
// pragma mark - OWSMessageCollectionViewCell
- (void)setCellVisible:(BOOL)isVisible

@ -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 clearCachedMediaViewsIfLastPresentingCell:self];
[_mediaAdapter setLastPresentingCell:nil];
self.mediaAdapter = nil;
}
- (void)setMediaAdapter:(nullable id<OWSMessageMediaAdapter>)mediaAdapter
{
_mediaAdapter = mediaAdapter;
// Mark this as the last cell to use this adapter.
[_mediaAdapter setLastPresentingCell:self];
}
// pragma mark - OWSMessageCollectionViewCell
- (void)setCellVisible:(BOOL)isVisible

Loading…
Cancel
Save