I am trying to use the react-native-reanimated
v2 to animate an array of Animated.View
s.
For my case, there are 2 handicaps:
- The objects will eventually animate each other. Because of this I am not able to generate a new sub-component for each draggable object. (If I try to do so, signaling between sub-components probably will be a hell.)
- The Rules of Hooks forbids the usage of the hooks within loops or other functions. (But that is what I need as far as I see.)
I made a snack to give the idea about what I try to achieve here (please note, one of the boxes is able to move another one here): https://snack.expo.dev/@mehmetkaplan/react-native-reanimated-array-animation
But I guess because of the above item 2, the snack does not behave consistent, sometimes the drag does not respond. (The single box version of the snack has a much more smooth response.)
Coming back to the main question. What is the proper way to animate an array of objects with react-native-reanimated
, considering a sub-component is not an option?
Any suggestion is appreciated.