PartialSheet: Button is not working inside ScrollView

I have content for SheetView inside a ScrollView. And under ScrollView there are few UI elements and one button. So when the view loaded the first time the button is not working. But after doing the scroll event the button starts working. Here is my code,

//Main ContentView `var body: some View {

    HStack {
        Spacer()
        Button(action: {
            self.partialSheetManager.showPartialSheet({
                 print("normal sheet dismissed")
            }) {
                 SheetView()
            }
        }, label: {
            Text("Display the Partial Sheet")
        })
    }
}`

//SheetView

`struct SheetView: View { var body: some View { VStack {

        ScrollView {
            Text("Hello")
            
            Button(action: {
                print("Button is tapping")
            }) {
                Text("Tap Here")
            }
        }
    }
}

}`

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 21 (1 by maintainers)

Most upvoted comments

I also had this issue on a TextField. It was also solved by adding onTapGesture {} on it

I have looked a bit more into it and it is indeed the dragGesture that takes over the whole view. In some cases it can be fixed by just adding an onTapGesture {} to your view/button/picker but this does not work the DatePicker - then buttons stops to work.

We need to find a way for having the priority of the drag gesture lowered

I had this problem as well and solved it by adding the modifier .highPriorityGesture() to the ScrollView and passing in the drag gesture from the sheet view. Hope this helps