更新偏移时不会触发React Native Animated Listener

时间:2016-12-19 07:09:53

标签: animation react-native

目前我有一个更新偏移的动画,然后在最后展平它以重置下一个动画。我正在侦听此动画的更新以与另一个动画进行协调,但是当更新偏移时它不会被触发。

imagePosition.addListener(this._animateOther)

我希望在我的对象移动时触发_animateOther。

但是,这不会触发_animateOther。

this.state.imagePosition.setOffset( update )

只有当偏移量合并回值时才会触发_animateOther。

this.state.imagePosition.flattenOffset()

这是一个错误,有没有办法听取偏移更新?

1 个答案:

答案 0 :(得分:0)

您的_animateOther只能在更新值时触发,而不是偏移。您应该尝试 setValue 而不是setOffset。

flattenOffset将偏移值合并到基值中,并将偏移重置为零。内部代码如下所示:

flattenOffset() {
    this._value += this._offset;
    this._offset = 0;
}

它会更新动画值,即触发_animateOther的原因。