1. 程式人生 > 其它 >swiper載入動態載入網路資料後,不能正常輪播,迴圈;reacrNative中使用react-native-swiper

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的部分