fix: dependency array; removes shared value access warning from react-native-reanimated#710
Conversation
🦋 Changeset detectedLatest commit: 86b8308 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
|
I still get these warnings on newest version? |
|
Are there any updates on this pull request? Do we know if it’s going to be merged? |
|
Would be great if we can have this merged |
|
Thanks for this fix! It's killing the console on Expo SDK 52 beta |
|
Do we have an ETA on when this will be merged? |
|
bump on this too |
|
For me this fix did not help with all warnings. I had to remove other |
hi @LukasMod - it looks like your patch is for an older version (3.5.1) than the current mainline branch. I think those other |
|
This is another reason why we need to release 4.0.0 ASAP. |
|
Please release this ASAP! @dohooo |
|
Can we get a major version if everything is Stable? I'm just starte using the canary for this reason.. |
Fixes #706
What: the bug
Where in our code
In
ScrollViewGesture.tsx, we had includedtouching.valueandscrollEndTranslation.valuein the dependency arrays for a couple of React callbacks. Not only is this not necessary, but it also causes a warning message to appear (and introduces the potential performance implication mentioned below).These dependency array
.values were introduced in eb21293 (as a part of #116).Warning message in react-native-reanimated
As per #706 (thank you, @joaofelippe911), a console warning appears when using react-native-reanimated version 3.16.0 or higher. This new warning was added via software-mansion/react-native-reanimated#6310
The warning looks like:
Why: potential performance implication
As per https://docs.swmansion.com/react-native-reanimated/docs/core/useSharedValue/#remarks ,
What: the fix
Don't depend on
touching.valueandscrollEndTranslation.valuein our dependency arrays inuseCallback().These aren't needed: all accesses to
touching.valueandscrollEndTranslation.valueare within worklets, and as per https://docs.swmansion.com/react-native-reanimated/docs/core/useSharedValue/#remarks :Verification: in local testing, the warning disappears!
In my local testing, this makes the warning disappear completely! And the carousel still behaves as normal.
Aside: where is this code used anyway?
In
ScrollViewGesture, there is auseAnimatedReaction()which callsresetBoundary()for changes totranslation.valuewheneverpagingEnabledisfalse.resetBoundary()callsactiveDecay()in some cases... which in turn callsonFinish()in some cases.It is worth noting that
onFinish,activeDecay, andresetBoundaryare only ever used whenpagingEnabledisfalse.(After a few minutes of playing around with my code for my use case, I was not able to cause
activeDecay()to ever run.)