I 'm trying to make a translate animation in React Native.
Here is my code
const scrollX = React.useRef(new Animated.Value(0)).current;
<Animated.ScrollView
horizontal
snapToInterval={width}
onScroll={Animated.event(
[{ nativeEvent: { contentOffset: { x: scrollX } } }],
{ useNativeDriver: false }
)}
scrollEventThrottle={16}
></Animated.ScrollView>
<Animated.View style={{ transform: [{ translateX: multiply(scrollX, -1) }] }}>
<Text>Some text</Text>
</Animated.View>
I am getting this error transform with key of translatex must be a number
If I change multiply(scrollX, -1)
to scrollX
the animation is reversed,
How can I fix this issue ?
i had this issue,Just because i forgot to give Animated.View
I fixed it by changing the import of multiply
from react-native-reanimated
to Animated
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With