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?
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
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With