我们的应用程序中有一个边缘案例。在呈现 UI 并且用户尝试滚动到它抛出的部分之后scrolltoindex should be used in conjunction with getitemlayout or on scrolltoindex failed
。现在,只有当他在 UI 渲染后立即执行此操作时才会发生这种情况。
_scrollToSection = index => {
setTimeout(() => {
this.list.scrollToLocation({
animated: true,
itemIndex: -1,
sectionIndex: index,
viewPosition: 0
});
}, 150);
};
部分列表渲染:
<SectionList
sections={this.props.sections}
extraData={this.props.subscriber}
ref={ref => {
if (ref) {
this.list = ref;
}
}}
automaticallyAdjustContentInsets={true}
contentInsetAdjustmentBehavior={'automatic'}
windowSize={100}
ListHeaderComponent={this.props.header || null}
ItemSeparatorComponent={() => (
<Separator
style={[mediumStyle.separatorEnd, { backgroundColor: IOS_GREY_02_03 }]}
/>
)}
renderSectionFooter={() => <View style={{ height: 17 }} />}
keyExtractor={(item, index) => index}
removeClippedSubviews={false}
stickySectionHeadersEnabled={true}
renderSectionHeader={({ section }) => (
<SectionTitle title={section.title} theme={this.props.theme} />
)}
renderItem={this._renderItem}
onEndReachedThreshold={0}
onEndReached={() => HapticFeedback.trigger()}
scrollEventThrottle={16}
/>
我试图用谷歌搜索原因,但没有成功地发现只有过时和关闭的问题而没有解决方案。这发生在其他人身上吗?你是怎么修的?
更新:
我们已经提出了一个恒定项目大小的解决方案,该解决方案还考虑了可访问性比例因子。所以我们有一个可以在getItemLayout
. 一切正常,但SectionList
有问题。当我们滚动到较低的部分时,列表本身就很跳跃,没有任何交互。到目前为止,我们最好的解决方案是在本机代码中自己构建节列表并使用它而不是 RN 列表。