我有兩個問題,當使用FlatList(這兩個工作與ListView)。使用FlatList和scrollToEnd
我有一個通過顯示屬性中顯示的每個項目,然後在我的FlatList檢查,像這樣的列表:
<FlatList
ref='flatList'
data={this.state.dataSource}
enableEmptySections
renderItem={({item}) => item.display && <Text>{item.text}</Text>} />
當我改變顯示屬性,但是,它沒有顯示。這在ListView安裝中運行良好。
我的第二個問題是scrollToEnd在scrollToEnd函數內的「this._listref」上觸發了一個未定義的錯誤。我沒有傳遞任何參數。
setTimeout(this.refs.flatList.scrollToEnd, 0)
我的問題是,我該如何更新我的陣列中的數據的列表,在列表中的變化,第二個問題是,我該如何解決scrollToEnd錯誤?
更新1:(數據刪除,不需要了)
更新2:問題一解決,列表需要 「而額外」 比較,看它是否更新。固定版本:
<FlatList
ref='flatList'
data={this.state.dataSource}
extraData={this.state}
enableEmptySections
renderItem={({item}) => item.display && <Text>{item.text}</Text>} />
這有點複雜,但我相信extraData的作用是比較數據集中是否有任何更新。如果是這樣,重新渲染。這個問題解決了。
「未定義不是(評價 'this._listRef')的對象」 還是不固定
更新3:滾動功能工作IF截取的setTimeoutfunction外
更新4 :
設置初始數據陣列
this.state = {
dataSource: pageService(state.params.page),
cursor: 0
}
設置顯示爲真:
renderNextModule() {
let newCursor = this.state.cursor
if (newCursor < this.state.dataSource.length-1) {
newCursor++
let newSource = this.state.dataSource
newSource[newCursor].display = true
this.setState({
dataSource: newSource,
cursor: newCursor
})
}
}
FlatList中的淺平等決定不重繪?我會 – Organiccat
第一個問題解決了我的數據的部分更新,更新 – Organiccat
再次更新,這似乎是具體到把它在一個包裝「的setTimeout」功能 – Organiccat