2017-02-18 112 views
7

我使用ListView的scrollToEnd,但它不起作用,但它適用於scrollTo。我該怎麼處理呢。React Native ListView scrollToEnd它不起作用

enter image description here

enter image description here

+0

我不相信這會因爲ListView在vie時不需要渲染所有元素w被安裝。也無法知道ListView何時完成渲染所有元素。 AFAIK'scrollToEnd'方法可以和一個按鈕一起使用。 – Eldelshell

+0

您是否收到錯誤或者它沒有做任何事情? – user1221780

+0

另外,Android還是iOS? – user1221780

回答

3

有一種變通方法,它包裝在一個setTimeout像這樣:

componentDidMount() { 
    setTimeout(() => { 
    this.refs.dateList.scrollToEnd(); 
    }, 50); 
} 
+0

This是有效的,但爲什麼 –

+0

對不起,我不記得我在哪裏得到了這個解決方法,但我可以說我已經花了幾個小時掙扎着這個bug ... –

3

試試這個:

<ListView> 
    ref={ (ref) => this.scrollView = ref } 
    onContentSizeChange={() => {   
     this.scrollView.scrollToEnd({ animated: false }) 
    } } > 
</ListView>