I'm using the new 'DocumentGroup' Scene for an iOS 14 (currently working on Beta) project and I really don't know how can I detect events in the navigation bar like pressing '<' or back (see screen)of the predefined Navigation bar of the 'DoucmentGroup' Scene. For custom buttons it's possible and it's also not a big deal to change the style of the bar(like gray). I tried to disable the button, adding new buttons to the navigation bar etc. The following example is the standard code when you are going to create a new document based app in Xcode:
@main struct DocumentAppApp: App {
@SceneBuilder var body: some Scene {
// Adding of a new document
DocumentGroup(newDocument: DocumentAppDocuments()) { file in
ContentView(document: file.$document) // .navigationBarBackButtonHidden(true)
}
}
}
struct ContentView: View {
@Binding var document: DocumentAppDocuments
var body: some View {
TextEditor(text: $document.text)
}
}
I ended up doing the following in my document's
ContentView.body
:I essentially killed the automatic
NavigationView
that comes with the document browser. This is not ideal for many reasons, the first of which is that I haven't actually figured out how to go back just yet. If we had access to the underlyingNavigationView
so i could set up my sidebar and my content, this wouldn't be a problem, but so far I haven't been successful here, either.DocumentGroup
kind of seems like half-baked garbage though. Why is it pushing, instead of presenting over an "empty" document? Why can't i set the accent color of theDocumentGroup
, etc. I've written feedback for these items but who knows if it will get addressed before release.The last option is to take this over yourself and not use
DocumentGroup
at all, useUIDocumentBrowserViewController
as aUIViewControllerRepresentable
and move on with your life. I will probably end up here soon.UPDATE: I ditched
DocumentGroup
. It just doesn't make any sense. Pushing the content? Dumb. Changing tint color? Can't. My app has also gotten rid of the SwiftUI app entry so I can fully control the UIDocumentBrowserViewController, and I suggest you do the same. The only tough part was figuring out how to best utilizeUIDocument
based storage instead of the nicerFileDocument
SwiftUI provides. To do that, I basically did this:Now it will fully work with SwiftUI views, save properly, everything.