Prevent slide out behavior of Sidebar in NavigationSplitView

79 views Asked by At

I have a navigationSplitView on an iPad. The detail view contains a pdfView (representable) with page style (pdfView.usePageViewController(true)). I have a button to control visibility of the sidebar.

Unfortunately the default slide out behavior of the sidebar is interfering with my backwards paging. Is there anyway to disable the swipe to slide out feature of the sidebar for the navigationSplitView?

I have a columnVisibility argument for my navigationSplitView and initially set it's value to .all

In the example below, with any multi page pdf, when you swipe to end and then back again it keeps pulling out the navigation sidebar rather than paging. Behavior is inconsistent so after trying several times the behavior should be apparent.

import SwiftUI
import PDFKit

enum Detail: Hashable {
    case pdfView
    case anotherView
}

struct ContentView: View {
    
    @State private var selection: Detail?
    @State private var columnVisibility = NavigationSplitViewVisibility.all
    
    var body: some View {
        NavigationSplitView(columnVisibility: $columnVisibility) {
            List(selection: $selection) {
                Section {
                    NavigationLink(value: Detail.pdfView) {
                        HStack(spacing: 12) {
                            Image(systemName: "scroll")
                            Text("PDF View")
                        }
                    }
                    NavigationLink(value: Detail.anotherView) {
                        HStack(spacing: 12) {
                            Image(systemName: "info.circle")
                            Text("Another View")
                        }
                    }
                }
            }
        } detail: {
            if selection == .pdfView {
                if let url = Bundle.main.url(forResource: "example", withExtension: "pdf") {
                    PDFKitView(url: url)
                } else {
                    EmptyView()
                }
            } else {
                Text("Another View")
            }
            
        }
        .navigationSplitViewStyle(.balanced)
    }
}

struct PDFKitView: UIViewRepresentable {
    
    let url: URL
    
    func makeUIView(context: UIViewRepresentableContext<PDFKitView>) -> PDFKitView.UIViewType {
        let pdfView = PDFView()
        pdfView.document = PDFDocument(url: self.url)
        pdfView.autoScales = true
        pdfView.displayMode = .singlePage
        pdfView.displayDirection = .horizontal
        pdfView.usePageViewController(true)
        return pdfView
    }

    func updateUIView(_ uiView: UIView, context: UIViewRepresentableContext<PDFKitView>) {

    }
}
0

There are 0 answers