【问题标题】:React Native Animation undefined is not an object errorReact Native Animation undefined is not an object 错误
【发布时间】:2017-07-29 04:36:13
【问题描述】:

我正在尝试为按下按钮时向右滑动的视图设置动画,我目前有以下代码,但不断得到

undefined is not an object (evaluation this.state.panelPos) 错误。我不明白代码有什么问题。有什么建议吗?

constructor(props){
    super(props)
    this.state = {
        initialLife : 200,
        panelPos: new Animated.Value(0),
    };
};


slideOutPanel(){
Animated.timing( this.state.panelPos,{
            toValue: 300,
            duration: 1000,
        }).start();
};

render(){return(
<View style = {styles.container}>

    <View style = {styles.lContainer}>

        <View style = {styles.playerLife}>

            <View style = {styles.lifeButtonRow}>
                <LifeButton/>
                <LifeButton/>
            </View>
            <View style = {styles.lifeButtonRow}>
                <LifeButton/>
                <LifeButton/>
            </View>     

            <Text>text</Text>
        </View>

        <Animated.View style = {[styles.panel,{transform: [{translateX: this.state.panelPos}]}]}>
            <Image style = {styles.cmd_panel} source={require('image')}/>
        </Animated.View>
    </View>
    <View style = {styles.portrait}>
        <Button title = {'push'} onPress = {this.slideOutPanel}/>
    </View>
</View>);

【问题讨论】:

    标签: reactjs animation react-native css-animations


    【解决方案1】:

    否则一切似乎都是正确的,但 this 的上下文未正确设置为:onPress={this.slideOutPanel}

    要么:onPress={() =&gt; this.slideOutPanel()}

    或:onPress={this.slideOutPanel.bind(this)}

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-02-18
      • 2020-08-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-11-26
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多