SwiftUI does not show ProgressView until after task is complete

I have a swift UI view that when tapped should show a progress view:

struct ProjectItem: View {
@EnvironmentObject var controller: ProjectController
@State var showLoadingIcon: Bool = false
let document: Document

var body: some View {
	VStack {
		ZStack {
		Text(document.name).font(Interface.Text.PopoverDialogLabel)
		Text(document.editTime.toString(true)).font(.caption2).foregroundColor(.gray)
		if showLoadingIcon {
			ProgressView()

		}
	}
	.padding(Interface.Sizes.StandardPadding)
	.if(controller.editedDocumentID == nil) { $0.onTapGesture(count: 1, perform: {
				// Open Project
				showLoadingIcon = true //This occours after TransitionView
				controller.openDocument(document: document)
                TransitionView() //this happens before the progressView is shown
	})}
} // we also handle different taps here but is removed from this example

When tapped it can take a couple of seconds to open the document and we would like to show a progressView to the user to display something is happening. However the progressView will only show to the user after the document has loaded. In the view controller the openDoucment simply calls part of an app:

	func openDocument(document: Document) {
	app.setProject(document.id) //this takes a few seconds 
}

app.setProject(document.id) is on the main thread and ideally, this will be moved to its own thread in the future but we cannot for now. How can the progress view be displayed before the loadDocument call is made?

I have tried to wrap the following into a Task{}

controller.openDocument(document: document)
                    TransitionView()

I have also made the openDocument call async and sync which did not fix the issue. I have also disabled the transitionView call and can see from my breakpoints that controller.openDocument call occurs before the

if showLoadingIcon {
				ProgressView()

			}

switches to showLoadingicon is switched - meaning that showLoadingIcons is checked by the app after controller.openDocument is completed and is shown.

I have also tried

    case idle, loading, loaded
}

@Published var state : ProjectState = .idle

To display with a switch statement the view.

Thank you again for your help

SwiftUI does not show ProgressView until after task is complete
 
 
Q