Xcode 16: SwiftUI plain Button & UIImageView not working

It looks like Xcode 16 has changed this behaviour so I'm not sure if this is a bug or not.

When a SwiftUI Button wraps a UIImageView and the button style is .plain the button doesn't work without setting isUserInteractionEnabled.

struct ContentView: View {
    var body: some View {
        Button {
            print("Hello World!")
        } label: {
            UITestImage()
        }
        .buttonStyle(.plain)
    }
}

struct UITestImage: UIViewRepresentable {
    func makeUIView(context: Context) -> UIImageView {
        let view = UIImageView()
        // view.isUserInteractionEnabled = true // Fix
        view.image = UIImage(systemName: "plus")
        view.contentMode = .scaleAspectFit
        view.setContentCompressionResistancePriority(.defaultLow, for: .horizontal)
        view.setContentCompressionResistancePriority(.defaultLow, for: .vertical)
        view.layoutMargins = .zero
        return view
    }
    
    public func updateUIView(_ uiView: UIImageView, context: Context) {}
}

This feels unexpected, is this a bug?

Answered by DTS Engineer in 790504022

@JoshyMW Could you please file a bug report on Feedback Assistant include the code snippet and then post the FB number here.

@JoshyMW Could you please file a bug report on Feedback Assistant include the code snippet and then post the FB number here.

Xcode 16: SwiftUI plain Button & UIImageView not working
 
 
Q