0

I got a ScrollView and a View inside that has a onLongPressGesture. Because the Item inside the ScrollView is full width it blocks the scrolling.

ScrollView {
    MessageBubble()
}
struct MessageBubble: View {
    let width = UIScreen.main.bounds.width

    var body: some View {
        VStack {
            Text("message")
                .frame(width: width)
                .onLongPressGesture(minimumDuration: 1) {
                    // Do something here
                }
        }
    }
}

I couldn't find anything helpful since most other asked questions regarding this have the TapGesture for the ScrollView and onLongPressGesture in the same View.

LuLuGaGa
  • 13,089
  • 6
  • 49
  • 57
AdamLeet
  • 127
  • 8
  • Does this answer your question? [Longpress and list scrolling](https://stackoverflow.com/questions/59440283/longpress-and-list-scrolling) – lazarevzubov Sep 01 '23 at 14:22

1 Answers1

2

Adding onTapGesture should solve your problem:

struct MessageBubble: View {
    let width = UIScreen.main.bounds.width

    var body: some View {
        VStack {
            Text("message")
                .frame(width: width)
                .onTapGesture {
                    // do nothing just allow the scroll view to receive touches
                }
                .onLongPressGesture(minimumDuration: 1) {
                    // Do something here
                }
        }
    }
}
LuLuGaGa
  • 13,089
  • 6
  • 49
  • 57