Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

OnLongPressGesture blocks ScrollView

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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
                }
        }
    }
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading