gpt4 book ai didi

reactjs - 错误: Attempted to assign to read only property on using Animated react native

转载 作者:行者123 更新时间:2023-12-03 14:00:04 28 4
gpt4 key购买 nike

出于某种原因,我无法看到我的代码做错了什么。我似乎按照文档所示使用动画,但此错误不断出现。代码片段:

import React, {
Component
} from 'react';
import {
StyleSheet,
Image,
Animated,
} from 'react-native'
import Header from './../components/Header'


export default class DrawerShell extends Component {
constructor(props) {
super(props)
this.state = {
showNav: false,
}
this.anim = new Animated.Value(0)
this.openDrawer = this.openDrawer.bind(this)
}
openDrawer() {
let toValue
this.setState({
showNav: !this.state.showNav
}) !this.state.showNav ? toValue = 1 : toValue = 0
Animated.timing( // Animate value over time
this.anim, // The value to drive
{
toValue: 1, // Animate to final value of 1
duration: 300,
}
).start()
}
render() {
let {
showNav
} = this.state
return ( <
Animated.View style = {
[
styles.appContainer,
{
transform: [{
translate: [
this.anim.interpolate({
inputRange: [0, 1],
outputRange: [0, 200],
}),
this.anim.interpolate({
inputRange: [0, 1],
outputRange: [0, 80],
}),
0
]
},
{
scale: this.anim.interpolate({
inputRange: [0, 1],
outputRange: [1, 0.7]
})
}
]
},
]
} >
<
Image source = {
{
uri: "splash_bg"
}
}
style = {
styles.bgImage
} >
<
Header title = "hi there"
onPress = {
this.openDrawer
}
/> <
/Image>
</Animated.View>
);
}
}

enter image description here

最佳答案

可能对来自 Google 的其他人有用。确保您在动画组件(例如 Animated.View)中使用动画值。将 View “升级”为动画时经常被忽视。

关于reactjs - 错误: Attempted to assign to read only property on using Animated react native,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46267729/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com