Home > Mobile >  OnLongPressGesture blocks ScrollView
OnLongPressGesture blocks ScrollView

Time:09-29

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.

CodePudding user response:

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
                }
        }
    }
}
  • Related