MESSENGER-3699 double tap for image attachments

This commit is contained in:
Arnfried Griesert
2022-10-18 06:07:42 +00:00
committed by Frank Rotermund
parent 6445195cf6
commit f2cfaf3b9e
4 changed files with 67 additions and 2 deletions
@@ -820,11 +820,18 @@
// Note: tap gesture recognizer is required here because mxkImageView enables user interaction to allow image stretching.
// [collectionView:didSelectItemAtIndexPath] is not triggered when mxkImageView is displayed.
UITapGestureRecognizer *cellTapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(onCollectionViewCellTap:)];
[cellTapGesture setNumberOfTouchesRequired:1];
[cellTapGesture setNumberOfTapsRequired:1];
cell.tag = item;
[cell addGestureRecognizer:cellTapGesture];
// BWI: allow changing the image zoom level by double tab
if ([BwiBuildSettings allowDoubleTapOnImageAttachmentsForZoom]) {
UITapGestureRecognizer *cellDoubleTapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(onCollectionViewCellDoubleTap:)];
[cellDoubleTapGesture setNumberOfTapsRequired:2];
cell.tag = item;
[cell addGestureRecognizer:cellDoubleTapGesture];
}
UILongPressGestureRecognizer *cellLongPressGesture = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(onCollectionViewCellLongPress:)];
[cell addGestureRecognizer:cellLongPressGesture];
}
@@ -1172,6 +1179,43 @@
}
}
- (void)onCollectionViewCellDoubleTap:(UIGestureRecognizer*)gestureRecognizer
{
MXKMediaCollectionViewCell *selectedCell;
UIView *view = gestureRecognizer.view;
if ([view isKindOfClass:[MXKMediaCollectionViewCell class]])
{
selectedCell = (MXKMediaCollectionViewCell*)view;
}
// Notify the collection view delegate a cell has been selected.
if (selectedCell && selectedCell.tag < attachments.count)
{
NSInteger item = isBackPaginationInProgress ? selectedCell.tag + 1: selectedCell.tag;
if (isBackPaginationInProgress)
{
if (item == 0)
{
return;
}
item --;
}
// Check whether the selected attachment is a video
if (item < attachments.count)
{
MXKAttachment *attachment = attachments[item];
if (attachment.type == MXKAttachmentTypeImage && attachment.contentURL)
{
[selectedCell.mxkImageView toggleZoomLevel];
}
}
}
}
- (void)onCollectionViewCellLongPress:(UIGestureRecognizer*)gestureRecognizer
{
MXKMediaCollectionViewCell *selectedCell;