Post

Replies

Boosts

Views

Activity

View flashes when setting new PDFDocument in PDFView
I have a SwiftUI View containing a PDFView from PDFKit (via NSViewRepresentable). When setting a new PDFDocument the view flashes briefly with the background color before displaying the new document. Curiously the flashing is vastly reduced (but not eliminated) by calling layoutDocumentView() which should already be called from setDocument according to its documentation. struct SheetView: NSViewRepresentable { var pdf: PDFDocument? func makeNSView(context: Context) -> PDFView { let pdfView = PDFView() pdfView.displaysPageBreaks = false pdfView.displayMode = .singlePage pdfView.pageShadowsEnabled = false pdfView.autoScales = true return pdfView } func updateNSView(_ pdfView: PDFView, context: Context) { if pdf != pdfView.document { pdfView.document = pdf pdfView.layoutDocumentView() // reduces flashing but does not eliminate it } } }
1
0
254
Sep ’24