2017-04-19 24 views
0

我想在動畫完成時做一些代碼。我該怎麼做? 我的例子:React-native:動畫完成時做一些代碼

showMsg(){ 

      Animated.sequence([ 
       Animated.timing(
        this.state.bottom, 
        { 
         toValue: 0, 
         duration: 500 
        }), 
       Animated.delay(1000), 
       Animated.timing(this.state.bottom, 
        { 
         toValue: -50, 
         duration: 500 
        }), 
      ]).start(); 

    } 

當最後一個動畫結束後我想這樣做代碼:

this.setState({ 
       msg: '', 
      }); 

謝謝。

回答

0

start()方法帶有一個可選函數,當動畫完成(或停止)時調用該函數。所以你可以這樣做:

animations.start(result => { 
    if (result.finished) { 
    this.setState({ msg: 'finished' }); 
    } 
});