Skip to content

It's hard to understand how to compose gestures with ScrollView #2616

Open
@gaearon

Description

@gaearon

Description

I've been scratching my head at this for the last few days so I figured I'd report.

Basically, my problem looks like #1082. I have a horizontal ScrollView, and it "steals" horizontal pinches inside of it. The Pinch gesture is inside individual items, but for some reason the outer ScrollView's scroll wins even though I'm definitely pinching (with two fingers).

I'm at a loss about how to debug this or even think about this.

There's something that maybe looks like a fix in #1034, but I'll join the chorus of people who didn't understand what the fix is and how to use it. The comment says to use simultaneousHandlers. But isn't that the opposite of what the OP wanted? The OP wanted to have the pinch gesture "win" and prevent the scrolling. The documentation for simultaneousHandlers seems to imply it's for allowing two gestures to be active at the same time — which is not what the OP wanted. So it's unclear how that fix is related to the issue.

There's also #2370 which seems related but was not reviewed. The problem in the video there seems to be exactly the same as what I'm experiencing (except it's vertical rather than horizontal). I have no idea if that fix makes sense though.

There are some scattered examples in the Issues of using Gesture.Native(), waitFor, simultaneousWithExternalGesture, ScrollView (undocumented?), and so on. For example, #2332 (comment). I found it very difficult to understand how these APIs are supposed to be used based on the docs. Do I want the built-in RN scroll view to "wait for" my pinch gesture inside it? Shouldn't the innermost gesture always win anyway? If I have many items in the list, do I need a ref to a gesture inside every item, and then somehow coordinate those refs with the ScrollView above? Do I need to be using ScrollView from react-native-gesture-handler for gestures to work at all? If I search for waitFor in the docs, I seem to only be getting results with outdated APIs (like this) which makes it further confusing.

Anyway, tldr is:

  • I don't understand why parent ScrollView steals item's pinch
  • I couldn't figure it out from the docs — they barely mention coordination with ScrollView
  • The docs that do mention coordination with ScrollView seem to be focused on old APIs
  • GH issues appear to reference fixes that either have no docs for them, or were not reviewed

I hope this can be improved somehow! I'll try to see if I can find some way that works.

Steps to reproduce

irrelevant

Snack or a link to a repository

irrelevant

Gesture Handler version

2.12.1

React Native version

0.72.4

Platforms

Android

JavaScript runtime

Hermes

Workflow

None

Architecture

None

Build type

None

Device

None

Device model

No response

Acknowledgements

Yes

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions