2016-10-23 48 views
2

我試圖在x:(device.width * 2)處獲得應用程序的初始位置,因爲該應用程序包含3個主要視圖,但似乎沒有即使動畫延遲移動,它也會從左側視圖開始。React-Native .scrollTo與InteractionManager不起作用

componentDidMount() { 
     const offset = window.width * this.props.initialIndex; 
     InteractionManager.runAfterInteractions(() => { 
     this._scrollView.scrollTo({x:offset, animated: false}); 
     }) 
} 
+0

這應該工作,並且不需要InteractionManager。你使用的是什麼版本的React Native? – jmurzy

+0

我使用的是RN 0.35,但我添加了InteractionManager,因爲我閱讀了scrollview有一個佈局動畫,並且我不得不在動畫之後延遲滾動。 –

回答

4

我也試過使用Interaction Manager,但我不知道爲什麼它不起作用;設置超時爲我工作。

setTimeout(() => { 
    this.scrollView.scrollTo(cordenates, animated); 
}, 0);