How to distinguish between adding and viewing in one DocumentGroup Scene?

The following scene will be created if the user select '+' in the navigation bar, but I don't want to execute the same code again if the user selects an item/file in the DocumentGroup. There is another initializer for selecting items in a DocumentGroup but how can I manage both possibilities (adding and showing) in one Scene? Furthermore how can I customize the DocumentGroup Navigation Bar? (I didn't find anything related to this in the documentation).
Code Block @main

Code Block
struct DocumentApp: App {
    var body: some Scene {
        DocumentGroup(newDocument: DocumentAppDocument()) { file in ContentView(document: file.$document)}
    }
}

Code Block



I have a similar question (https://developer.apple.com/forums/thread/651667).

In regard to the nav bar, you can simply attach navigationBarItems to the content view. I would recommend you do this inside the content view itself, not as I've shown here in the App file.

Code Block
struct testApp: App {
    var body: some Scene {
        DocumentGroup(newDocument: testDocument()) { file in
            ContentView(document: file.$document)
                .navigationBarItems(trailing: Button("Button", action: { print("button tapped") }))
        }
    }
}


I tried something like this (see below), but always the first DocumentGroup will be executed and not the second one, that means whenever I press on '+' or select a document it will execute "DocumentGroup(viewing:DocumentAppDocuments)". How can I distinguish here? Or is this a current issue of the beta version?

@main

Code Block
struct DocumentApp: App {
    @SceneBuilder var body: some Scene {
        // Viewing of document
        DocumentGroup(viewing:DocumentAppDocuments ) { file in
            DocumentPreview(document: file.$document)
        }
        // Adding of a new document
        DocumentGroup(newDocument: DocumentAppDocuments()) { file in
            ContentView(document: file.$document)
        }
    }
}

init is called on your Document when the + is tapped. When an existing document is opened init(fileWrapper: FileWrapper, contentType: UTType) is called.

Remember in SwiftUI the body method is called multiple times to create all the structs but doesn't mean that anything will actually happen, for example if all the structs built are identical then the diff won't detect any changes thus nothing will change.
How to distinguish between adding and viewing in one DocumentGroup Scene?
 
 
Q