software-mansion / react-native-gesture-handler

Declarative API exposing platform native touch and gesture system to React Native.
https://docs.swmansion.com/react-native-gesture-handler/
MIT License
6.13k stars 982 forks source link

Remove shared value read on the JS thread during detector update #2957

Closed j-piasecki closed 4 months ago

j-piasecki commented 5 months ago

Description

In https://github.com/software-mansion/react-native-gesture-handler/pull/2037 support for memoizing gestures was added, which relied on reading the current handlers from the shared value and comparing them to the new ones.

This worked well with Reanimated 2, where shared values kept a copy of their value on JS thread, and the assumption about Reanimated 3, was that even though the read is synchronous, it's quick enough not to cause problems. This assumption was wrong since it can result in JS thread being blocked until the UI thread finishes its current work to allow for SV read.

This PR eliminates the necessity of reading from the shared value by relying on information already available on the JS thread to decide whether the shared value should be updated.

Test plan

Test on the Example app to make sure nothing breaks, and make sure that memorized gestures don't result in updating the shared value.