diff --git a/submodules/DirectMediaImageCache/Sources/DirectMediaImageCache.swift b/submodules/DirectMediaImageCache/Sources/DirectMediaImageCache.swift index b8810d2b10..9e24202888 100644 --- a/submodules/DirectMediaImageCache/Sources/DirectMediaImageCache.swift +++ b/submodules/DirectMediaImageCache/Sources/DirectMediaImageCache.swift @@ -246,8 +246,8 @@ public final class DirectMediaImageCache { selectedSize = progressiveSizes[0] } else if progressiveSizes.count > 1 && width <= 160 { selectedSize = progressiveSizes[2] - } else if progressiveSizes.count > 2 && width <= 400 { - selectedSize = progressiveSizes[3] + } else if progressiveSizes.count > 4 && width <= 400 { + selectedSize = progressiveSizes[4] } else { selectedSize = Int32.max } diff --git a/submodules/SparseItemGrid/Sources/SparseItemGrid.swift b/submodules/SparseItemGrid/Sources/SparseItemGrid.swift index 831ef35902..9933f52eca 100644 --- a/submodules/SparseItemGrid/Sources/SparseItemGrid.swift +++ b/submodules/SparseItemGrid/Sources/SparseItemGrid.swift @@ -719,6 +719,36 @@ public final class SparseItemGrid: ASDisplayNode { self.scrollView.setContentOffset(CGPoint(x: 0.0, y: contentOffset), animated: false) } + func ensureItemVisible(index: Int) { + guard let layout = self.layout, let _ = self.items else { + return + } + if layout.containerLayout.lockScrollingAtTop { + return + } + + let itemFrame = layout.frame(at: index) + let visibleBounds = self.scrollView.bounds + if itemFrame.intersects(visibleBounds) { + return + } + + var contentOffset: CGFloat + if itemFrame.midY >= visibleBounds.maxY { + contentOffset = itemFrame.maxY - self.scrollView.bounds.height + layout.containerLayout.insets.bottom + } else { + contentOffset = itemFrame.minY - layout.containerLayout.insets.top + } + + if contentOffset > self.scrollView.contentSize.height - self.scrollView.bounds.height { + contentOffset = self.scrollView.contentSize.height - self.scrollView.bounds.height + } + if contentOffset < 0.0 { + contentOffset = 0.0 + } + self.scrollView.setContentOffset(CGPoint(x: 0.0, y: contentOffset), animated: false) + } + func scrollToTop() -> Bool { if self.scrollView.contentOffset.y > 0.0 { self.scrollView.setContentOffset(CGPoint(), animated: true) @@ -1569,6 +1599,13 @@ public final class SparseItemGrid: ASDisplayNode { currentViewport.scrollToItem(at: index) } + public func ensureItemVisible(index: Int) { + guard let currentViewport = self.currentViewport else { + return + } + currentViewport.ensureItemVisible(index: index) + } + public func scrollToTop() -> Bool { guard let currentViewport = self.currentViewport else { return false @@ -1615,15 +1652,23 @@ public final class SparseItemGrid: ASDisplayNode { } } + private var brieflyDisabledTouchActions = false + public func brieflyDisableTouchActions() { + if self.brieflyDisabledTouchActions { + return + } + self.brieflyDisabledTouchActions = true + let tapEnabled = self.tapRecognizer?.isEnabled ?? true self.tapRecognizer?.isEnabled = false let pinchEnabled = self.pinchRecognizer?.isEnabled ?? true self.pinchRecognizer?.isEnabled = false - DispatchQueue.main.async { - self.tapRecognizer?.isEnabled = tapEnabled - self.pinchRecognizer?.isEnabled = pinchEnabled + DispatchQueue.main.async { [weak self] in + self?.tapRecognizer?.isEnabled = tapEnabled + self?.pinchRecognizer?.isEnabled = pinchEnabled + self?.brieflyDisabledTouchActions = false } } diff --git a/submodules/TelegramUI/Sources/PeerInfo/Panes/PeerInfoVisualMediaPaneNode.swift b/submodules/TelegramUI/Sources/PeerInfo/Panes/PeerInfoVisualMediaPaneNode.swift index 0a02e05d6b..e1c75c77b9 100644 --- a/submodules/TelegramUI/Sources/PeerInfo/Panes/PeerInfoVisualMediaPaneNode.swift +++ b/submodules/TelegramUI/Sources/PeerInfo/Panes/PeerInfoVisualMediaPaneNode.swift @@ -1709,6 +1709,18 @@ final class PeerInfoVisualMediaPaneNode: ASDisplayNode, PeerInfoPaneNode, UIScro } } strongSelf.itemInteraction.hiddenMedia = hiddenMedia + + if let items = strongSelf.items { + for item in items.items { + if let item = item as? VisualMediaItem { + if hiddenMedia[item.message.id] != nil { + strongSelf.itemGrid.ensureItemVisible(index: item.index) + break + } + } + } + } + strongSelf.updateHiddenMedia() })