我有一个这样的ScrollView:
<ScrollView>
{this.state.businessMerchants.map(merchant => (
<Business
merchant={merchant}
key={merchant.id}
/>
))}
</ScrollView>通常有2-4个项目。
我想突出当前的最高项目,并让它占用更多的空间(也许10%?)。这个“最重要的项目”将在一个滚动列表中切换。
是否有一种更标准化的方法来做到这一点,或者我必须使用scrollEventThrottle和像这样的自定义函数?
伪码如下:
if((findHeightOfItem + padding) * multiple === itemPos) {
addSizeHere()
}非常好奇什么是最好的/最具表现力的方式,在反应本地人。
发布于 2019-10-02 05:26:01
步骤:
决定每个组件itemHeight
scrolledHeight
Math.floor(scrolledHeight / itemHeight)
handleScroll = (e) => { const currentHeight = e.nativeEvent.contentOffset.y;const currentItemIndex = Math.floor(currentHeight / 100);this.setState({ currentItemIndex });}{this.state.businessMerchants.map(商户,索引) => ( )}
https://stackoverflow.com/questions/58194167
复制相似问题