SwiftUI Catalyst app on Big Sur losing focus.

I have been working with several SwiftUI apps using Catalyst for Mac support. There seems to be a major issue where the entire app or portions of the app become unresponsive to clicks or other events seemingly because a loss of focus. Sometimes it is recoverable by clicking around random parts of the window, but sometimes it is just stuck. Does anyone know how to get this under control, or perhaps start controlling which parts of the app get focus?

Also, when returning from modal states, focus seems to land on a random ui element. I would like to know how to control this.
  • This is a complete mess. It can not be controlled, and documentation of this use case is pretty nonexistent.

    I'm tying to use an SwiftUI framework on Mac that has many dependencies to UIColor, so Mac Catalayst is the only way to go. Trying to get that running with the Document based App template is a total mess, and the focus issue complete destroys the interactivity of the interface randomly. Drag operations seem to be particularly vulnerable.

Add a Comment

Accepted Reply

I have a workaround for this bug that seems to work. Sharing it in hopes of helping others...

So it seems this bad behavior occurs (in my case anyway) when you wrap a NavigationView with other custom UI. In my case I had a custom tab bar view which wrapped a NavigationView.

Sometimes the content inside the NavigationView would become completely unresponsive to user interaction but the custom tab bar would remain functional.

Now for the workaround:

I found that if I set the custom tab bar view to disabled(true) then focus would be forced to change back to the NavigationView. So a workaround would be to temporarily disable all of the custom UI surrounding the NavigationView then re-enable it. You'd have to get creative with making this work reliably--something like a periodic async timer that enables/disables stuff. I'm still figuring out the best solution for my app. Just thought I'd share.

Replies

Same thing happening here. My application been running on SwiftUI since first version but after Big Sur's release.. Yea no click responses at all. It's like views gaining focus and never give it back.
Modals for me doesn't load it's content when popping up, showing empty view. It needs to manually resize the app window so the content appear.


Same for me... I don't understand if are bugs from Big Sur or not...
Yep it's happening to everyone running MacCatalyst app on macOS 11 : https://stackoverflow.com/questions/64819031/clicking-problems-in-swiftui-catalyst-with-big-sur
Tried to remove the old AppDelegate + SceneDelegate that were used in SwiftUI 1 and implement the new LifeCycle using @Main, nothing really changed.
Same bug, same problem.
Same issue for me. My Feedback item, for those that wish to dupe is: FB8905985

I wish we could get some acknowledgement that Apple is aware of the issue.
I had the same problem, and what's worse, when I changed all the buttons to “Button action” form, the “override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) ” in my UIVIEW. doesn't work.

I tried to add a piece of code



.gesture(DragGesture()
.onChanged { value in

}
.onEnded { value in

}
)



and it gets better, but sometimes it still fails to click!





#if targetEnvironment(macCatalyst)

Anytools()

.gesture(DragGesture()
.onChanged { value in

}
.onEnded { value in

}
)

#else

Anytools()


#endif
I have a similar problem with my swiftui app on big sur. Navigate into a form and whenever the user scrolls, it freezes. Apple developer support replicated the problem and I have registered a bug with feedback assistant.

same problem here, this is terrible, no idea how to fix it

I have a workaround for this bug that seems to work. Sharing it in hopes of helping others...

So it seems this bad behavior occurs (in my case anyway) when you wrap a NavigationView with other custom UI. In my case I had a custom tab bar view which wrapped a NavigationView.

Sometimes the content inside the NavigationView would become completely unresponsive to user interaction but the custom tab bar would remain functional.

Now for the workaround:

I found that if I set the custom tab bar view to disabled(true) then focus would be forced to change back to the NavigationView. So a workaround would be to temporarily disable all of the custom UI surrounding the NavigationView then re-enable it. You'd have to get creative with making this work reliably--something like a periodic async timer that enables/disables stuff. I'm still figuring out the best solution for my app. Just thought I'd share.