Skip to content
This repository has been archived by the owner on Dec 12, 2022. It is now read-only.

Commit

Permalink
Merge pull request #261 from matrix-org/riot_1109
Browse files Browse the repository at this point in the history
Bug Fix - Image viewer repeatedly loses overlay menu
  • Loading branch information
giomfo authored Mar 23, 2017
2 parents 71b9fa8 + 0d4e9cc commit 3c2ebcd
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 37 deletions.
52 changes: 15 additions & 37 deletions MatrixKit/Controllers/MXKAttachmentsViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -1019,53 +1019,31 @@ - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPa

- (void)collectionView:(UICollectionView *)collectionView didEndDisplayingCell:(UICollectionViewCell *)cell forItemAtIndexPath:(NSIndexPath *)indexPath
{
// Restore the cell in reusable state
// Here the cell is not displayed anymore, but it may be displayed again if the user swipes on it.
if ([cell isKindOfClass:[MXKMediaCollectionViewCell class]])
{
MXKMediaCollectionViewCell *mediaCollectionViewCell = (MXKMediaCollectionViewCell*)cell;

mediaCollectionViewCell.mxkImageView.hidden = NO;
mediaCollectionViewCell.customView.hidden = YES;

// Cancel potential image download
mediaCollectionViewCell.mxkImageView.enableInMemoryCache = NO;
[mediaCollectionViewCell.mxkImageView setImageURL:nil withType:nil andImageOrientation:UIImageOrientationUp previewImage:nil];
// TODO; we should here reset mxkImageView.stretchable flag
// But we observed wrong behavior in case of reused cell: The stretching mechanism was disabled for unknown reason.
// To reproduce: stretch the current image I1 with the max zoom scale, then scroll to the previous one I0, scroll back to I1: the stretching is disabled: NOK
// Investigation is required before uncommenting the following line
// mediaCollectionViewCell.mxkImageView.stretchable = NO;

// Hide video play icon
mediaCollectionViewCell.centerIcon.hidden = YES;

// Remove potential media download observer
if (mediaCollectionViewCell.notificationObserver)
{
[[NSNotificationCenter defaultCenter] removeObserver:mediaCollectionViewCell.notificationObserver];
mediaCollectionViewCell.notificationObserver = nil;
}

// Stop potential attached player
// Check whether a video was playing in this cell.
if (mediaCollectionViewCell.moviePlayer)
{
// This cell concerns an attached video.
// We stop the player, and restore the default display based on the video thumbnail
[mediaCollectionViewCell.moviePlayer stop];
mediaCollectionViewCell.moviePlayer = nil;

mediaCollectionViewCell.mxkImageView.hidden = NO;
mediaCollectionViewCell.centerIcon.hidden = NO;
mediaCollectionViewCell.customView.hidden = YES;

// Remove potential media download observer
if (mediaCollectionViewCell.notificationObserver)
{
[[NSNotificationCenter defaultCenter] removeObserver:mediaCollectionViewCell.notificationObserver];
mediaCollectionViewCell.notificationObserver = nil;
}
}
// Remove added view in custon view
NSArray *subViews = mediaCollectionViewCell.customView.subviews;
for (UIView *view in subViews)
{
[view removeFromSuperview];
}
}

// Remove all gesture recognizers
while (cell.gestureRecognizers.count)
{
[cell removeGestureRecognizer:cell.gestureRecognizers[0]];
}
cell.tag = -1;
}

- (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset
Expand Down
32 changes: 32 additions & 0 deletions MatrixKit/Views/MXKCollectionViewCell/MXKMediaCollectionViewCell.m
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
Copyright 2015 OpenMarket Ltd
Copyright 2017 Vector Creations Ltd
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -39,6 +40,37 @@ - (void)prepareForReuse
[super prepareForReuse];
[self.moviePlayer stop];
self.moviePlayer = nil;

// Restore the cell in reusable state
self.mxkImageView.hidden = NO;
self.mxkImageView.stretchable = NO;
// Cancel potential image download
self.mxkImageView.enableInMemoryCache = NO;
[self.mxkImageView setImageURL:nil withType:nil andImageOrientation:UIImageOrientationUp previewImage:nil];

self.customView.hidden = YES;
self.centerIcon.hidden = YES;

// Remove added view in custon view
NSArray *subViews = self.customView.subviews;
for (UIView *view in subViews)
{
[view removeFromSuperview];
}

// Remove potential media download observer
if (self.notificationObserver)
{
[[NSNotificationCenter defaultCenter] removeObserver:self.notificationObserver];
self.notificationObserver = nil;
}

// Remove all gesture recognizers
while (self.gestureRecognizers.count)
{
[self removeGestureRecognizer:self.gestureRecognizers[0]];
}
self.tag = -1;
}

- (void)dealloc
Expand Down

0 comments on commit 3c2ebcd

Please sign in to comment.