software-mansion / react-native-reanimated

React Native's Animated library reimplemented
https://docs.swmansion.com/react-native-reanimated/
MIT License
8.83k stars 1.29k forks source link

The inside code of <Animated.Code> is always executed when render runs #814

Closed gaishimo closed 4 years ago

gaishimo commented 4 years ago

Description

The inside code of <Animated.Code> is always executed when render runs. This happens in version 1.5 and above. (doesn't happen in version 1.4)

Please let me know if my code has some problems or there are any effective workarounds.

Screenshots

version 1.4 version 1.5 and above

Steps To Reproduce

Run this example Expo app on iOS or Android and drag the shape. https://github.com/gaishimo/rn-gesture-with-renimated/

Expected behavior

The inside code of <Animated.Code> should be executed only once.

https://github.com/software-mansion/react-native-reanimated/blob/9ab83d8f601c0280580e1a47794aa20d32e45f0b/docs/pages/09.code.md

Note that the code you put is going to be executed only once. We currently have no way of telling if your code changes and so it will only be run in componentDidMount. If you wish for your reanimated nodes to be updated when the component updates, you can update the key property of the Animated.Code component, which will effectively unmount old and mount new versions of it in the React tree.

Actual behavior

The inside code of <Animated.Code> is always executed when render runs.

Snack or minimal code example

https://github.com/gaishimo/rn-gesture-with-reanimated/blob/master/App.tsx#L74-L98

Package versions

jakub-gonet commented 4 years ago

This may be the same issue as #570

jakub-gonet commented 4 years ago

This should be resolved in master (most likely by this commit).