I am using react-spring
lib. in the react-native
application. I have archived most of animation but I can not figure out how to use rotate init.
Here is my current code =>
<Spring
from={ { width: '100%', resizeMode: "contain", rotate: 0 } }
to={ { rotate: 360 } }
loop
config={ { duration: 1500 } }
>
{({ rotate, ...props }) => (
<AnimatedImage source={img} style={ {...props, transform: [{ rotate: `${rotate}deg` }]} } />
)}
</Spring>
Then get a error Like this =>
TypeError: undefined is not a function (near ‘…transform.forEach…’)
If someone can explain how to achieve the rotate animation with react-spring
it would be really helpful.
you can find a simple example here
2
Answers
You can achieve the rotation animation in
@react-spring/native
by using theinterpolations
methods.It is strange that we can not apply rotation directly, but i haven't found any other method other than this one in
@react-spring/native
react-spring/native it’s web based library maybe it’s work but there’s no clear way for it, but on the other hand you can archive this animation using native
Animated
like this:you can check this working example from here.
and here’s a repo on github with a working react native project also from here.
Hope it helps you 😀