如何修复 React Native 中的“transform with key of translatex 必须是数字”错误?

Ami*_*ine 4 animation transform react-native react-native-android

我正在尝试在 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>
Run Code Online (Sandbox Code Playgroud)

我收到此错误 transform with key of translatex must be a number

如果我的变化multiply(scrollX, -1),以scrollX动画逆转,

我该如何解决这个问题?

Sab*_*oly 12

我有这个问题,只是因为我忘了给Animated.View


Ami*_*ine 1

multiply我通过将from的导入更改为react-native-reanimated来修复它Animated