我正在尝试在 React Native 中制作翻译动画。
这是我的代码
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>
我收到此错误 transform with key of translatex must be a number
如果我将 multiply(scrollX, -1)
更改为 scrollX
,动画就会反转,我该如何解决这个问题?
最佳答案
我有这个问题,只是因为我忘了给 Animated.View
关于react-native - 如何修复 React Native 中的 "transform with key of translatex must be a number"错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63745653/