diff --git a/Riot/Modules/MatrixKit/Views/MXKImageView.h b/Riot/Modules/MatrixKit/Views/MXKImageView.h index ddda448c3..d4277f988 100644 --- a/Riot/Modules/MatrixKit/Views/MXKImageView.h +++ b/Riot/Modules/MatrixKit/Views/MXKImageView.h @@ -122,5 +122,7 @@ andImageOrientation:(UIImageOrientation)orientation - (void)dismissSelection; +- (void)toggleZoomLevel; + @end diff --git a/Riot/Modules/MatrixKit/Views/MXKImageView.m b/Riot/Modules/MatrixKit/Views/MXKImageView.m index 92060afc6..8c977c24d 100644 --- a/Riot/Modules/MatrixKit/Views/MXKImageView.m +++ b/Riot/Modules/MatrixKit/Views/MXKImageView.m @@ -317,7 +317,7 @@ scrollView.zoomScale = 1.0; scrollView.minimumZoomScale = 1.0; - scrollView.maximumZoomScale = scaleX; + scrollView.maximumZoomScale = 3.0; // update the image frame to ensure that it fits to the scrollview frame imageView.frame = scrollView.bounds; @@ -922,4 +922,20 @@ andImageOrientation:(UIImageOrientation)orientation return self.stretchable ? imageView : nil; } +// BWI: allow changing the image zoom level by double tab +- (void)toggleZoomLevel +{ + CGFloat currentZoomScale = scrollView.zoomScale; + + if (currentZoomScale < 1.5) { + scrollView.zoomScale = 2.0; + } + else if (currentZoomScale < 2.5) { + scrollView.zoomScale = 3.0; + } + else { + scrollView.zoomScale = 1.0; + } +} + @end diff --git a/Riot/Modules/Room/Attachements/MXKAttachmentsViewController.m b/Riot/Modules/Room/Attachements/MXKAttachmentsViewController.m index 331121341..850eb92ab 100644 --- a/Riot/Modules/Room/Attachements/MXKAttachmentsViewController.m +++ b/Riot/Modules/Room/Attachements/MXKAttachmentsViewController.m @@ -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; diff --git a/bwi/BwiBuildSettings.swift b/bwi/BwiBuildSettings.swift index dc67b9afb..edb79aee3 100644 --- a/bwi/BwiBuildSettings.swift +++ b/bwi/BwiBuildSettings.swift @@ -124,4 +124,7 @@ final class BwiBuildSettings: NSObject { // DMs don't need all roomsettings (like changing avatar, name, topic) static let showUnrelatedRoomSettingsForDirectMessages = false + + // DMs don't need all roomsettings (like changing avatar, name, topic) + static let allowDoubleTapOnImageAttachmentsForZoom = true }