Button Touch Not Canceled in ScrollView on Modal in SwiftUI for iOS 18

When displaying a view with a Button inside a ScrollView using the sheet modifier, if you try to close the sheet by swiping and your finger is touching the Button, the touch is not canceled.

This issue occurs when building with Xcode 16 but does not occur when building with Xcode 15.

Here is screen cast.

https://drive.google.com/file/d/1GaOjggWxvjDY38My4JEl-URyik928iBT/view?usp=sharing

Code

struct ContentView: View {
    @State var isModalPresented: Bool = false
    var body: some View {
        ScrollView {
            Button {
                debugPrint("Hello")
                isModalPresented.toggle()
            } label: {
                Text("Hello")
                    .frame(height: 44)
            }
            Button {
                debugPrint("World")
            } label: {
                Text("World")
                    .frame(height: 44)
            }
            Text("Hoge")
                .frame(height: 44)
                .contentShape(Rectangle())
                .onTapGesture {
                    debugPrint("Hoge")
                }
        }
        .sheet(isPresented: $isModalPresented) {
            ContentView()
        }
    }
}

hi @masaichi ,

Can you please tell me which iOS version you are testing with? I tested with the Xcode 16.1 beta and iOS 18.0 and did not see the issue occur.

Hi Thank you for your reply. The environment I tested on below.

  • Xcode Version: 16.0 (16A242)
  • OS: iOS 18.0
  • Device: iPhone 16 Pro simulator, iPhone 12 mini

I could reproduce the issue with this sample code in both of the environments below.

  • Xcode 16.0 (16A242d), iOS 18.0 simulator
  • Xcode 16.1 beta (16B5001e), iOS 18.1 simulator

I was able to reproduce the issue with this sample code in both environments.

  • Xcode 16.0 (16A242d), iOS 18.0 simulator
  • Xcode 16.1 beta (16B5001e), iOS 18.1 simulator

I found that calling .simultaneousGesture(TapGesture()) on a Button can avoid this issue.

Button Touch Not Canceled in ScrollView on Modal in SwiftUI for iOS 18
 
 
Q