swiftui

SwiftUI Buttons in a ScrollView is not tappable sometimes


I have a horizontal ScrollView on top of a MapView.

The ScorllView is a collection of Buttons. It is weird that the buttons in the ScrollView are sometime tapable and sometimes not. First tap always works but after that I have to scroll a bit, tap around different areas in the button, make some secret prayers and then it works!

I tried disabling/removing all other components in the view, but still unable to figure out the root cause.

Has anyone experience this ?


Solution

  • I stuck with a same issue with horizontal ScrollView on top and List. While debugging I added empty .onTapGesture to ScrollView and it somehow fix my issue.

    VStack(spacing: 0) {
        ScrollView(.horizontal) {
            HStack {
                Button("one") {}
                Button("two") {}
                Button("three") {}
            }
        }
        .onTapGesture { // <---- fix
        }
        List {
        }
    }