From 76d16566b78421ffdde0af683a17fc60e3502aa9 Mon Sep 17 00:00:00 2001 From: Rajdeep Kwatra Date: Wed, 17 Apr 2024 14:54:33 +1000 Subject: [PATCH] Accounted for horizontal scrolling for attachment viewport intersection --- .../CommandsExampleViewController.swift | 13 +++++++++---- Proton/Sources/Swift/Table/TableView.swift | 6 ++++-- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/ExampleApp/ExampleApp/AdvancedFeatures/CommandsExampleViewController.swift b/ExampleApp/ExampleApp/AdvancedFeatures/CommandsExampleViewController.swift index 1e737bdc..8d0b5706 100644 --- a/ExampleApp/ExampleApp/AdvancedFeatures/CommandsExampleViewController.swift +++ b/ExampleApp/ExampleApp/AdvancedFeatures/CommandsExampleViewController.swift @@ -476,10 +476,15 @@ extension CommandsExampleViewController: EditorViewDelegate { extension CommandsExampleViewController: TableViewDelegate { var viewport: CGRect? { var viewport = editor.scrollView.bounds - let offset: CGFloat = 100 - viewport.origin.y += offset - viewport.size.height -= (offset * 2) - Utility.drawRect(rect: CGRect(origin: CGPoint(x: 0, y: offset), size: viewport.size), color: .red, in: editor) + let offsetY: CGFloat = 100 + let offsetX: CGFloat = 40 + + viewport.origin.x += offsetX + viewport.origin.y += offsetY + viewport.size.width -= (offsetX * 2) + viewport.size.height -= (offsetY * 2) + + Utility.drawRect(rect: CGRect(origin: CGPoint(x: offsetX, y: offsetY), size: viewport.size), color: .red, in: editor) return viewport } diff --git a/Proton/Sources/Swift/Table/TableView.swift b/Proton/Sources/Swift/Table/TableView.swift index 0049c9a7..1538ef23 100644 --- a/Proton/Sources/Swift/Table/TableView.swift +++ b/Proton/Sources/Swift/Table/TableView.swift @@ -365,8 +365,10 @@ public class TableView: UIView { let containerViewport = delegate?.viewport ?? container.bounds let adjustedViewport = containerViewport.offsetBy(dx: tableView.bounds.origin.x, dy: tableView.bounds.origin.y) - let adjustedAttachmentContentViewFrame = CGRect(origin: rootOrigin, size: attachmentContentView.frame.size) - guard adjustedViewport.intersects(adjustedAttachmentContentViewFrame) else { + let origin = tableView.bounds.offsetBy(dx: rootOrigin.x, dy: rootOrigin.y).origin + let adjustedAttachmentViewport = CGRect(origin: origin, size: attachmentContentView.frame.size) + + guard adjustedViewport.intersects(adjustedAttachmentViewport) else { cellsInViewport = [] return }