Skip to content

Commit

Permalink
Fixes a glitch when dismissing a GIF in the media attachment viewer (#…
Browse files Browse the repository at this point in the history
…6475) (#6476)

* Fixed a glitch in media viewer when dismissing a GIF: the WebView which shows the animation would show in the background while the transition interaction occurred

* adding the changelog entry

Signed-off-by: Milton Moura <[email protected]>
  • Loading branch information
mgcm authored Aug 5, 2022
1 parent c2204fd commit 6cb076b
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 2 deletions.
2 changes: 2 additions & 0 deletions Riot/Modules/MatrixKit/Animators/MXKAttachmentAnimator.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ typedef NS_ENUM(NSInteger, PhotoBrowserAnimationType) {

@protocol MXKDestinationAttachmentAnimatorDelegate <NSObject>

- (BOOL)prepareSubviewsForTransition:(BOOL)isStartInteraction;

- (UIImageView *)finalImageView;

@end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,9 @@ - (void)handleGesture:(UIPanGestureRecognizer *)recognizer
- (void)startInteractiveTransition:(id <UIViewControllerContextTransitioning>)transitionContext
{
self.transitionContext = transitionContext;


[self.destinationViewController prepareSubviewsForTransition:YES];

UIViewController *fromViewController = [transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey];
UIImageView *destinationImageView = [self.destinationViewController finalImageView];
destinationImageView.hidden = YES;
Expand Down Expand Up @@ -158,6 +160,8 @@ - (void)cancelInteractiveTransition {

[self.transitionContext cancelInteractiveTransition];
[self.transitionContext completeTransition:NO];

[self.destinationViewController prepareSubviewsForTransition:NO];
}
}];
}
Expand Down
26 changes: 25 additions & 1 deletion Riot/Modules/Room/Attachements/MXKAttachmentsViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -701,7 +701,7 @@ - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cell
width = minSize;
height = minSize;
}

WKWebView *animatedGifViewer = [[WKWebView alloc] initWithFrame:CGRectMake(0, 0, width, height)];
animatedGifViewer.center = cell.customView.center;
animatedGifViewer.opaque = NO;
Expand Down Expand Up @@ -1379,6 +1379,30 @@ - (void)documentInteractionControllerDidDismissOpenInMenu:(UIDocumentInteraction
}
}

#pragma mark - MXKDestinationAttachmentAnimatorDelegate

- (BOOL)prepareSubviewsForTransition:(BOOL)isStartInteraction
{
MXKMediaCollectionViewCell *cell = (MXKMediaCollectionViewCell *)[self.attachmentsCollection.visibleCells firstObject];
MXKAttachment *attachment = attachments[currentVisibleItemIndex];
NSString *mimeType = attachment.contentInfo[@"mimetype"];

// Check attachment type for GIFs - this is required because of the extra WKWebView
if (attachment.type == MXKAttachmentTypeImage && attachment.contentURL && [mimeType isEqualToString:@"image/gif"])
{
UIView *customView = cell.customView;
for (UIView *v in customView.subviews)
{
if ([v isKindOfClass:[WKWebView class]])
{
v.hidden = isStartInteraction;
return YES;
}
}
}
return NO;
}

- (UIImageView *)finalImageView
{
MXKMediaCollectionViewCell *cell = (MXKMediaCollectionViewCell *)[self.attachmentsCollection.visibleCells firstObject];
Expand Down
1 change: 1 addition & 0 deletions changelog.d/6475.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Media Attachments Viewer: Fixed an issue where dismissing GIFs would show the WebView playing the animation below the interaction transition animation.

0 comments on commit 6cb076b

Please sign in to comment.