2017-07-28 33 views
0

我试图动画视图时按下按钮向右滑动,我现在有下面的代码,但不断收到阵营本土动画不确定是不是一个对象错误

不确定是不是一个对象(评估此。 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>); 

回答

1

否则,一切似乎是正确的,但背景下,这个没有正确的参数设置:onPress={this.slideOutPanel}

或者:onPress={() => this.slideOutPanel()}

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

+0

当然是谢谢 – user3074140

相关问题