当我在ScrollView
中单击Item时,我希望将父position
滚动到该项position
。
由于实际数据长度灵活,不能静态计算高度。
<ScrollView>
<View style={{height:300}}>
<Text>Test</Text>
</View>
<FlatList
scrollEnabled={false}
data={[1,2,3,4,5,6,7,8,9,10]}
renderItem={renderItem}
/>
</ScrollView>
ScrollToIndex
在FlatList
中不能使用,因为scrollEnabled
是false
。我想使用父ScrollTo
的ScrollView
。
但onLayout
用于renderItem
,y
为0。所以我不知道确切的位置。
我怎样才能得到我想要的价值?
发布于 2019-07-18 04:45:19
首先,不要在ScrollView中使用ScrollView,在FlatList中使用ListHeaderComponent支柱
参考资料:https://facebook.github.io/react-native/docs/flatlist#listheadercomponent
https://stackoverflow.com/questions/57091774
复制相似问题