【发布时间】:2020-12-23 23:47:18
【问题描述】:
我正在尝试在 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,动画就会反转,
我该如何解决这个问题?
【问题讨论】:
-
使用插值,然后使用外推属性,您可以提及字符串以及“0deg”到“360deg”
标签: react-native animation react-native-android transform