将react-native-swiper设置loop=true后,发现重新渲染的时候出现bug

本文介绍了解决React Native Swiper组件在特定条件下运行不正确的问题。通过修改源代码中的componentWillReceiveProps方法并提供了一个替代方案来解决autoplay属性导致的问题。此外还提供了一种在组件更新后自动滚动到初始位置的方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

解决:

You should find this in .../node_modules/react-native-swiper/src/index.js

componentWillReceiveProps (nextProps) {
    if (!nextProps.autoplay && this.autoplayTimer) clearTimeout(this.autoplayTimer)
    this.setState(this.initState(nextProps, this.props.index !== nextProps.index))
}

plz remove this and try again, it will be run correctly.

 

原帖:https://github.com/leecade/react-native-swiper/issues/731

 

 

我的方法:渲染更新后设置滑动到0

        

                                 <Swiper  

                                ref="scrollView"

                                loop = {true}

                                horizontal={true}

                                showsHorizontalScrollIndicator={false}

                                pagingEnabled={true}

                                >

                                      {this.state.TestPromotionData.map((key, i) => this.renderPromotion(key, i))}

                                </Swiper>





             componentDidUpdate() {

   
                     var ScrollView = this.refs.scrollView;

                    ScrollView.scrollBy(0, false)

           }

 

推荐改用:https://github.com/rilyu/teaset

 

 

 

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值