Skip to content

Commit

Permalink
Renamed viewport in AsyncAttachmentDelegate to avoid conflict with th…
Browse files Browse the repository at this point in the history
…e same in Editor
  • Loading branch information
rajdeep committed Nov 7, 2023
1 parent 2f1a1a8 commit 9dc5efc
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ class ListFormattingProvider: EditorListFormattingProvider {
}

extension CommandsExampleViewController: AsyncAttachmentRenderingDelegate {
var viewport: CGRect? { nil }
var prioritizedViewport: CGRect? { nil }

func shouldRenderAsync(attachment: Proton.Attachment) -> Bool {
attachment is GridViewAttachment
Expand Down
2 changes: 1 addition & 1 deletion Proton/Sources/Swift/Attachment/Attachment.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public protocol AsyncAttachmentRenderingDelegate: AnyObject {
/// `EditorView` also has a `viewport` property that also depends on this property.
/// Care must be taken to not to return `editor.viewport` here. Doing so will cause a stack overflow crash.
/// An independently calculated value can safely be returned here.
var viewport: CGRect? { get }
var prioritizedViewport: CGRect? { get }

/// Determines if particular attachment should be rendered asynchronously.
/// The check may also be used to render certain types of attachments synchronously or asynchronously.
Expand Down
2 changes: 1 addition & 1 deletion Proton/Sources/Swift/Editor/EditorView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,7 @@ open class EditorView: UIView {
/// A `ViewportProvider` may be needed in cases where `EditorView` is hosted inside another `UIScrollView` and the
/// viewport needs to be calculated based on the viewport of container `UIScrollView`.
open var viewport: CGRect {
return asyncAttachmentRenderingDelegate?.viewport ?? richTextView.viewport
return asyncAttachmentRenderingDelegate?.prioritizedViewport ?? richTextView.viewport
}

/// Returns the visible text range. In case of non-scrollable `EditorView`, entire range is `visibleRange`.
Expand Down
12 changes: 6 additions & 6 deletions Proton/Tests/Editor/EditorViewportSnapshotTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class EditorViewportSnapshotTests: SnapshotTestCase {
var renderingNotified = false
asyncRenderingDelegate.onDidCompleteRenderingViewport = { viewport, _ in
renderingNotified = true
XCTAssertEqual(viewport, asyncRenderingDelegate.viewport)
XCTAssertEqual(viewport, asyncRenderingDelegate.prioritizedViewport)
}

DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
Expand Down Expand Up @@ -104,7 +104,7 @@ class EditorViewportSnapshotTests: SnapshotTestCase {
editor.attributedText = text

asyncRenderingDelegate.onDidCompleteRenderingViewport = { viewport, _ in
XCTAssertEqual(viewport, asyncRenderingDelegate.viewport)
XCTAssertEqual(viewport, asyncRenderingDelegate.prioritizedViewport)
assertSnapshot(matching: viewController.view, as: .image, record: self.recordMode)
ex.fulfill()
}
Expand Down Expand Up @@ -143,17 +143,17 @@ class EditorViewportSnapshotTests: SnapshotTestCase {
text.append(NSAttributedString(string: "Text after panel"))
}
editor.attributedText = text
var expectedViewport = asyncRenderingDelegate.viewport
var expectedViewport = asyncRenderingDelegate.prioritizedViewport

asyncRenderingDelegate.onDidCompleteRenderingViewport = { viewport, _ in
XCTAssertEqual(viewport, expectedViewport)
assertSnapshot(matching: viewController.view, as: .image, record: self.recordMode)
asyncRenderingDelegate.viewport = CGRect(
asyncRenderingDelegate.prioritizedViewport = CGRect(
origin: CGPoint(x: 0, y: 600),
size: CGSize(width: 260, height: 200)
)
viewportBorderView.frame = asyncRenderingDelegate.viewport ?? viewportBorderView.frame
expectedViewport = asyncRenderingDelegate.viewport
viewportBorderView.frame = asyncRenderingDelegate.prioritizedViewport ?? viewportBorderView.frame
expectedViewport = asyncRenderingDelegate.prioritizedViewport
ex.fulfill()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ import UIKit
import Proton

class MockAsyncAttachmentRenderingDelegate: AsyncAttachmentRenderingDelegate {
var viewport: CGRect?
var prioritizedViewport: CGRect?
var onShouldRenderAsync: (Attachment) -> Bool = { _ in return true }
var onDidRenderAttachment: ((Attachment, EditorView) -> Void)?
var onDidCompleteRenderingViewport: ((CGRect, EditorView) -> Void)?

init(viewport: CGRect? = nil) {
self.viewport = viewport
self.prioritizedViewport = viewport
}

func shouldRenderAsync(attachment: Attachment) -> Bool {
Expand Down

0 comments on commit 9dc5efc

Please sign in to comment.