Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SwiftUI Buttons (and everything else) with no style become unresponsive when other Button with custom style are present on screen on MacOS Catalyst

I'm having this issue with SwiftUI on Mac Catalyst wherein a simple view like the following :

struct ContentView: View {
    @State var count : Int = 0
    
    var body: some View {
        HStack{
            Button("tap me"){
                count += 1
            }
            Button("test \(count)"){
                count += 1
            }.buttonStyle(CustomButtonStyle())
            Button("test \(count)"){
                count += 1
            }.buttonStyle(CustomButtonStyle())
            Button("test \(count)"){
                count += 1
            }.buttonStyle(CustomButtonStyle())
        }
    }
}

struct CustomButtonStyle: ButtonStyle {
    
    func makeBody(configuration: Configuration) -> some View {
        configuration
            .label
    }
}

The button with no style (but also everything else from pickers to sliders) becomes unresponsive after a number of renders. This happens only when two or more Buttons with custom style are visible on the screen. Having different styles doesn't solve the issue. Have you encountered this issue before? Is it a bug with SwiftUI on mac?

like image 961
Fabio Santo Avatar asked Dec 17 '25 21:12

Fabio Santo


1 Answers

It turns out this problem is reproducible when deploying using "Optimize Interface for Mac". If you use "Scale Interface to Match iPad", it works without a problem. Specifying a contentShape fixes the problem for some reason. FWIW, just specifying the contentShape for the non-custom (i.e., native when using "Optimize Interface for Mac") works in a VStack, but not in an HStack.

struct ContentView: View {
    @State private var count: Int = 0
    
    var body: some View {
        HStack {
            Button("tap me") { count += 1 }
            .contentShape(Rectangle())
            Button("test \(count)") { count += 1 }
            .contentShape(Rectangle())
            .buttonStyle(CustomButtonStyle())
            Button("test \(count)") { count += 1 }
            .contentShape(Rectangle())
            .buttonStyle(CustomButtonStyle())
            Button("test \(count)") { count += 1 }
            .contentShape(Rectangle())
            .buttonStyle(CustomButtonStyle())
        }
    }
    
}

struct CustomButtonStyle: ButtonStyle {
    
    func makeBody(configuration: Configuration) -> some View {
        configuration
            .label
    }
    
}
like image 88
Steve Harris Avatar answered Dec 20 '25 10:12

Steve Harris



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!