Skip to content

Commit

Permalink
Make virtualised tableview use EditorView as default scrollview if no…
Browse files Browse the repository at this point in the history
…t provided via delegatre
  • Loading branch information
rajdeep committed Aug 8, 2024
1 parent b8d59a2 commit df71fce
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,8 @@ extension CommandsExampleViewController: TableViewDelegate {
}

var containerScrollView: UIScrollView? {
editor.scrollView
nil
// editor.scrollView
}

func tableView(_ tableView: TableView, didReceiveKey key: EditorKey, at range: NSRange, in cell: TableCell) { }
Expand Down
13 changes: 10 additions & 3 deletions Proton/Sources/Swift/Table/TableView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -392,8 +392,15 @@ public class TableView: UIView {
}
}

public override func didMoveToWindow() {
guard window != nil,
observation == nil else { return }

setupScrollObserver()
}

private func setupScrollObserver() {
observation = delegate?.containerScrollView?.observe(\.bounds, options: [.new, .old]) { [weak self] container, change in
observation = self.containerScrollView?.observe(\.bounds, options: [.new, .old]) { [weak self] container, change in
self?.viewportChanged()
}
}
Expand Down Expand Up @@ -438,7 +445,7 @@ public class TableView: UIView {
// ensure editor is not hidden e.g. inside an Expand in collapsed state
attachmentContentView.attachment?.containerEditorView?.isHidden == false,
tableView.bounds != .zero,
let containerScrollView = delegate?.containerScrollView,
let containerScrollView = self.containerScrollView,
let rootEditorView = containerAttachment?.containerEditorView?.rootEditor else {
cellsInViewport = []
return
Expand Down Expand Up @@ -812,7 +819,7 @@ extension TableView: UIScrollViewDelegate {

extension TableView: TableContentViewDelegate {
var containerScrollView: UIScrollView? {
delegate?.containerScrollView
delegate?.containerScrollView ?? containerAttachment?.containerEditorView?.rootEditor.scrollView
}

var viewport: CGRect? {
Expand Down
2 changes: 1 addition & 1 deletion Proton/Tests/Table/TableViewAttachmentSnapshotTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class TableViewAttachmentSnapshotTests: SnapshotTestCase {
delegate = MockTableViewDelegate()
viewController = EditorTestViewController()
editor = viewController.editor
delegate.containerScrollView = editor.scrollView
// Not setting delegate.containerScrollview expects the editor.scrollview as default scrollview
}

func testRendersTableViewAttachment() {
Expand Down

0 comments on commit df71fce

Please sign in to comment.