react-native-gesture-handler icon indicating copy to clipboard operation
react-native-gesture-handler copied to clipboard

Allow `GestureHandlerRootView` to be manually made active

Open j-piasecki opened this issue 2 years ago • 4 comments

Description

This PR allows users to override whether a particular GestureHandlerRootView is enabled or not. By default, only the topmost root view would be active, allowing all gestures to interact with each other.

The problem with that approach is that if any of the native views underneath calledrequestDisallowInterceptTouchEvent, all gestures would be canceled. It comes from the fact that requestDisallowInterceptTouchEvent calls are propagated up the view hierarchy and we expect GestureHandlerRootView to be relatively close to the top.

The simple solution would be to add another root view underneath the view that may call requestDisallowInterceptTouchEvent to prevent gestures from being canceled, this, however, resulted in two problems:

  • the inner root view would not be enabled
  • after adding the option to enable it manually, both root views would start handling the event, resulting in duplicated event streams

I've fixed the second problem by adding checks at the beginning of extractGestureHandlers and traverseWithPointerEvents to ensure that we're not extracting gestures attached under another enabled root view.

This allows for solving the problem described in https://github.com/software-mansion/react-native-gesture-handler/issues/2383.

Test plan

Tested on the reproduction from https://github.com/software-mansion/react-native-gesture-handler/issues/2383

j-piasecki avatar Feb 01 '23 14:02 j-piasecki

Can we expect this to be merged? It's approved after all 🙈

lpatrun avatar Mar 21 '24 12:03 lpatrun

Actually, I'm not sure if this is the best solution to this problem. I'll try to get back to it in the near future to see if I can find other approaches to this.

j-piasecki avatar Mar 21 '24 14:03 j-piasecki

@j-piasecki thank you for the quick response

lpatrun avatar Mar 21 '24 14:03 lpatrun

Hi still has same problem in 2024, any suggestions? thanks

javaing avatar Jun 27 '24 06:06 javaing