swiper加载动态加载网络数据后,不能正常轮播,循环;reacrNative中使用react-native-swiper

reacrNative中使用react-native-swiper
swiper加载本地的list数据时,没有问题;
swiper加载动态加载网络数据后,不能正常轮播,循环;
代码如下:


//轮播图
renderImageList() {
let {indexHelpVideoList} = this.state;
return (
<View style={styles.imageListView}>
{indexHelpVideoList && <Swiper
ref={ref => this.imageListSwiper = ref}
loop={true}
autoplay={true}
paginationStyle={{bottom: 4}}
autoplayTimeout={3}
>
{indexHelpVideoList && indexHelpVideoList.map((item, index) => {
return (
<View key={item.id}>
<Image style={styles.ListImage} source={{uri: item.coverImg}}/>
</View>
)
})}
</Swiper>
}
</View>
)
}

//动态加载数据


getHomeInfo = () => {
this.props.fetchRequest(this, '', Url.getHomeInfo(), {}, true, true, true, (data, response) => {
this.setState({
indexHelpVideoList: data.indexHelpVideoList ?? []
})
});

}


解决办法是:在没有获取到动态数据时,不初始化swiper。等获取到数据时,才初始化swiper的部分

 

posted @ 2022-04-20 10:22  文晓豪  阅读(470)  评论(0编辑  收藏  举报