使用react-native-animated时获取样式转换属性的类型错误

时间:2019-09-29 06:42:24

标签: typescript react-native react-native-reanimated

我正在使用 “本机”:“ 0.59.10” “ react-native-reanimated”:“ ^ 1.3.0” 带打字稿 我在转换属性时遇到类型错误

zhihu_answer

这是我遇到的错误Type error

3 个答案:

答案 0 :(得分:1)

您只需将react-native-reanimated更新到最新版本(当前为1.13.0),styletransform的问题就会消失。

答案 1 :(得分:0)

我认为这是因为Y没有任何事件。

<Animated.View style={{  transform: [
                { translateX: new Animated.Value(0)},
                { translateY: new Animated.Value(0) },
              ] }} />

答案 2 :(得分:0)

到目前为止,您无法直接在transform属性上传递style。这是react-native-reanimated的错误。请参阅GitHub问题here

解决方案: 但是您可以通过更改代码来解决此问题

const Example = () => {
const { translationX, gestureHandler } = horizontalPanGestureHandler()
const transformStyle = {
     transform: [{ translateX: translationX }]
}
return (
    <View style={styles.container}>
       <PanGestureHandler {...gestureHandler}>
         <Animated.View style={[transformStyle, /** You can add other inline styles here **/{color: 'black'}]} />
      </PanGestureHandler>
    </View>
)}

希望这会有所帮助!