Skip to content

Commit 6077816

Browse files
authored
Renamed viewport in AsyncAttachmentDelegate to avoid conflict with the same in Editor (#249)
1 parent 2f1a1a8 commit 6077816

File tree

5 files changed

+11
-11
lines changed

5 files changed

+11
-11
lines changed

Diff for: ExampleApp/ExampleApp/AdvancedFeatures/CommandsExampleViewController.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,7 @@ class ListFormattingProvider: EditorListFormattingProvider {
468468
}
469469

470470
extension CommandsExampleViewController: AsyncAttachmentRenderingDelegate {
471-
var viewport: CGRect? { nil }
471+
var prioritizedViewport: CGRect? { nil }
472472

473473
func shouldRenderAsync(attachment: Proton.Attachment) -> Bool {
474474
attachment is GridViewAttachment

Diff for: Proton/Sources/Swift/Attachment/Attachment.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public protocol AsyncAttachmentRenderingDelegate: AnyObject {
4848
/// `EditorView` also has a `viewport` property that also depends on this property.
4949
/// Care must be taken to not to return `editor.viewport` here. Doing so will cause a stack overflow crash.
5050
/// An independently calculated value can safely be returned here.
51-
var viewport: CGRect? { get }
51+
var prioritizedViewport: CGRect? { get }
5252

5353
/// Determines if particular attachment should be rendered asynchronously.
5454
/// The check may also be used to render certain types of attachments synchronously or asynchronously.

Diff for: Proton/Sources/Swift/Editor/EditorView.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -555,7 +555,7 @@ open class EditorView: UIView {
555555
/// A `ViewportProvider` may be needed in cases where `EditorView` is hosted inside another `UIScrollView` and the
556556
/// viewport needs to be calculated based on the viewport of container `UIScrollView`.
557557
open var viewport: CGRect {
558-
return asyncAttachmentRenderingDelegate?.viewport ?? richTextView.viewport
558+
return asyncAttachmentRenderingDelegate?.prioritizedViewport ?? richTextView.viewport
559559
}
560560

561561
/// Returns the visible text range. In case of non-scrollable `EditorView`, entire range is `visibleRange`.

Diff for: Proton/Tests/Editor/EditorViewportSnapshotTests.swift

+6-6
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ class EditorViewportSnapshotTests: SnapshotTestCase {
6161
var renderingNotified = false
6262
asyncRenderingDelegate.onDidCompleteRenderingViewport = { viewport, _ in
6363
renderingNotified = true
64-
XCTAssertEqual(viewport, asyncRenderingDelegate.viewport)
64+
XCTAssertEqual(viewport, asyncRenderingDelegate.prioritizedViewport)
6565
}
6666

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

106106
asyncRenderingDelegate.onDidCompleteRenderingViewport = { viewport, _ in
107-
XCTAssertEqual(viewport, asyncRenderingDelegate.viewport)
107+
XCTAssertEqual(viewport, asyncRenderingDelegate.prioritizedViewport)
108108
assertSnapshot(matching: viewController.view, as: .image, record: self.recordMode)
109109
ex.fulfill()
110110
}
@@ -143,17 +143,17 @@ class EditorViewportSnapshotTests: SnapshotTestCase {
143143
text.append(NSAttributedString(string: "Text after panel"))
144144
}
145145
editor.attributedText = text
146-
var expectedViewport = asyncRenderingDelegate.viewport
146+
var expectedViewport = asyncRenderingDelegate.prioritizedViewport
147147

148148
asyncRenderingDelegate.onDidCompleteRenderingViewport = { viewport, _ in
149149
XCTAssertEqual(viewport, expectedViewport)
150150
assertSnapshot(matching: viewController.view, as: .image, record: self.recordMode)
151-
asyncRenderingDelegate.viewport = CGRect(
151+
asyncRenderingDelegate.prioritizedViewport = CGRect(
152152
origin: CGPoint(x: 0, y: 600),
153153
size: CGSize(width: 260, height: 200)
154154
)
155-
viewportBorderView.frame = asyncRenderingDelegate.viewport ?? viewportBorderView.frame
156-
expectedViewport = asyncRenderingDelegate.viewport
155+
viewportBorderView.frame = asyncRenderingDelegate.prioritizedViewport ?? viewportBorderView.frame
156+
expectedViewport = asyncRenderingDelegate.prioritizedViewport
157157
ex.fulfill()
158158
}
159159

Diff for: Proton/Tests/Editor/Mocks/MockAsyncAttachmentRenderingDelegate.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@ import UIKit
2424
import Proton
2525

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

3232
init(viewport: CGRect? = nil) {
33-
self.viewport = viewport
33+
self.prioritizedViewport = viewport
3434
}
3535

3636
func shouldRenderAsync(attachment: Attachment) -> Bool {

0 commit comments

Comments
 (0)