就像标题中所说的,我有一个contentContainerStyle
的FlatList在列表底部创建一些空间。当我尝试使用scrollToEnd()
时,列表似乎没有滚动到底部,在这种情况下,列表是contentContainerStyle
创建的多余空间的结尾。我有什么办法可以使列表自动滚动到最后?到目前为止,scrollToEnd()
仅滚动到列表中最后一项附近的某处,而不是最末尾
<FlatList
{..}
contentContainerStyle={{paddingBottom:500}}
{..}
/>
答案 0 :(得分:0)
也许您应该尝试使用“ scrollToIndex()”并传递单位列表中的最后一个索引。 有关方法的文档,请参见此处:https://facebook.github.io/react-native/docs/flatlist#scrolltoindex
例如,您可以执行以下操作:
flatList1.scrollToIndex({
animated: false,
index: this.state.flastListData.length
});
答案 1 :(得分:0)
所以一段时间后,我想出了一个写滚动功能的想法,该功能将内容高度和滚动高度用于在此高度更改时进行滚动。
scrollToBottom() {
const pointToScroll = this.contentHeight - this.scrollViewHeight;
const scrollResponder = this.refs.scrollView.getScrollResponder();
scrollResponder.scrollResponderScrollTo({x: 0, y: pointToScroll, true});
}