I want to create a PDFView with embedded PDFThumbnailView for macOS. The PDFThumbnailView should be vertical, on the right side of the PDFView. I wish both views to be inside one NSViewRepresentable. However, I’m not very familiar with UIKit and its constraints and the best I could possibly do is to make the PDFThumbnailView overlap the PDFView. How to make the PDFView and the PDFThumbnailView separate, so they don’t overlap? Here’s the code:
struct PDFViewWrapper: NSViewRepresentable {
let pdfView = PDFView()
@Binding var pdfDisplay: Int
func makeNSView(context: Context) -> PDFView {
let fileURL = FileManagerClient.shared.getDocumentsDirectory().appendingPathComponent("example.PDF")
let pdfDocument = PDFDocument(url: fileURL)
///
let thumbnailView = PDFThumbnailView()
thumbnailView.translatesAutoresizingMaskIntoConstraints = false
pdfView.addSubview(thumbnailView)
thumbnailView.pdfView = pdfView
NSLayoutConstraint.activate(
[
thumbnailView.leadingAnchor.constraint(equalTo: pdfView.safeAreaLayoutGuide.leadingAnchor),
thumbnailView.topAnchor.constraint(equalTo: pdfView.safeAreaLayoutGuide.topAnchor),
thumbnailView.bottomAnchor.constraint(equalTo: pdfView.safeAreaLayoutGuide.bottomAnchor),
thumbnailView.widthAnchor.constraint(equalToConstant: 80),
]
)
thumbnailView.thumbnailSize = CGSize(width: 100, height: 100)
thumbnailView.backgroundColor = .placeholderTextColor
///
pdfView.document = pdfDocument
pdfView.autoScales = true
pdfView.displayMode = PDFDisplayMode(rawValue: pdfDisplay) ?? .singlePageContinuous
return pdfView
}
func updateNSView(_ uiView: PDFView, context: Context) {}
}