SwiftUI's alert window won't get automatically focus in visionOS

I have three basic elements in this UI page: View, Alert, Toolbar. I put Toolbar and Alert along with the View, when I click a button on Toolbar, my alert window shows up. Below could be a simple version of my code:

@State private var showAlert = false

HStack {
  // ...
}
.alert(Text("Quit the game?"), isPresented: $showAlert) {
    MyAlertWindow()
} message: {
    Text("Description text about this alert")
}
.toolbar {
    ToolbarItem(placement: .bottomOrnament) {
        MyToolBarButton(showAlert: $showAlert)
    }
}

And in MyToolBarButton I just toggle the binded showAlert variable to try to open/close the alert window.

When running on either simulator or device, the bahavior is quite strange. Where when toggle MyToolBarButton the alert window takes like 2-3 seconds to show-up, and all the elements on the alert window is grayed out, behaving like the whole window is losing focus. I have to click the moving control bar below (by dragging gesture) to make the whole window back to focus.

And this is not the only issue, I also find MyToolBarButton cannot be pressed to close the alert window (even thogh when I try to click the button on my alert window it closes itself).

Oh btw I don't know if this may affect but I open the window with my immersive view opened (though I tested it won't affect anything here)

Any idea of what's going on here?

XCode 16.1 / visionOS 2 beta 6

Answered by milanowth in 801787022

Apparently this is only because I am running this in debug mode. With released build, the latency doesn't exist anymore.

Accepted Answer

Apparently this is only because I am running this in debug mode. With released build, the latency doesn't exist anymore.

SwiftUI's alert window won't get automatically focus in visionOS
 
 
Q