SwiftUI document-based app bug

I have a simple text editor style app, based on the XCode template of an iOS document-based app. Everything works really – except the unfolding of the dropdown on the first opening of a new file. On real hardware (eg. my iPhone or iPad) it is consistently a problem. Everything is up-to-date and rebooted etc. etc. On the XCode Simulator, I can't get it to do it. I've included 3 screenshots, one showing how it should look when properly unfolded on the XCode Simulator, the other when it hasn't unfolded properly on the first opening of a document, and lastly, subsequent visits to that dropdown and it will behave correctly.

Can you share a minimal code snippet that reproduces the issue?

Sure thing. I'm not sure which code snippet helps the most, but happy to share. Here's the textEditorApp.swift:

import SwiftUI

@main
struct textEditorApp: App
{
    var body: some Scene
    {
        DocumentGroup(newDocument: textEditorDocument())
        {
            file in ContentView(document: file.$document)
        }
    }
}

and here is the ContentView.swift:

import SwiftUI

struct ContentView: View
{
    @Binding var document: textEditorDocument
    @State private var showingSettings = false
    @ObservedObject var settings = SettingsModel()

    var body: some View
    {
        TextEditor(text: $document.text)
            .font(.custom(settings.fontName, size: CGFloat(settings.fontSize)))
            .padding(.leading, 20)
            .border(Color.blue.opacity(0.3))

            .toolbar
            {
                #if os(iOS)
                    ToolbarItem(placement: .navigationBarTrailing)
                    {
                        Button(action: { UIApplication.shared.endEditing() } )
                        {
                            Image(systemName: "keyboard.chevron.compact.down")
                        }
                    }
                    ToolbarItem(placement: .navigationBarTrailing)
                    {
                        Button(action: { showingSettings.toggle() } )
                        {
                            Image(systemName: "slider.horizontal.3")
                        }
                    }
                #elseif os(macOS)
                    ToolbarItem
                    {
                        addButton
                    }
                    ToolbarItem
                    {
                        deleteButton
                    }
                #endif // os(iOS)
            }

            .sheet(isPresented: $showingSettings)
            {
                SettingsView(settings: settings)
                    //.presentationBackground(Color(.sRGB, red: 0.9, green: 0.9, blue: 0.9, opacity: 0.90))
                    .presentationBackground(Color(.secondarySystemBackground))
                    .presentationDragIndicator(.visible)
            }
    }
}

extension UIApplication
{
    func endEditing()
    {
        sendAction(#selector(UIResponder.resignFirstResponder), to: nil, from: nil, for: nil)
    }
}
SwiftUI document-based app bug
 
 
Q