Mac Catalyst SwiftUI – . focused() not working

Hello,

given this following simple SwiftUI setup:

struct ContentView: View {
    var body: some View {
        CustomFocusView()
    }
}

struct CustomFocusView: View {
    @FocusState private var isFocused: Bool
    
    var body: some View {
        color
            .frame(width: 128, height: 128)
            .focusable(true)
            .focused($isFocused)
            .onTapGesture {
                isFocused.toggle()
            }
            .onKeyPress("a") {
                print("A pressed")
                return .handled
            }
    }
    
    var color: Color {
        isFocused ? .blue : .red
    }
}

If I run this via Mac – Designed for iPad, the CustomFocusView toggles focus as expected and cycles through red and blue. Now if I run this same exact code via Mac Catalyst absolutely nothing happens and so far I wasn't able to ever get this view to accept focused state. Is this expected? I would appreciate if anyone could hint me on how to get this working.

Thank and best regards!

Anyone? This is one of the last steps of polish of my Catalyst app that I would like to implement, but I just don't see what's going wrong.

Based on these docs: https://developer.apple.com/documentation/swiftui/view/focusable(_:interactions:)

The focus interactions allowed for custom views changed in macOS 14—previously, custom views could only become focused with keyboard navigation enabled system-wide. Clients built using older SDKs will continue to see the older focus behavior, while custom views in clients built using macOS 14 or later will always be focusable unless the client requests otherwise by specifying a restricted set of focus interactions.

It reads to me like this should be possible with macOS 14 or later? Essentially what I want is similar to the behavior in Reality Composer Pro where when the user clicks the scene view keyboard controls are enabled to move around in the scene, whereas when focus changes e.g to elements on the sidebar keyboard navigation will cycle between them.

What works in my example above is using the arrow keys right away to focus the way. Although then I only get the focus ring, but the isFocused FocusState still does not update. Very confusing.

This video also didn't help much: https://developer.apple.com/documentation/swiftui/focus-cookbook-sample

Is this just somewhat unfinished behavior specific to Mac Catalyst?

Mac Catalyst SwiftUI – . focused() not working
 
 
Q