<ViewPagerAndroid
style={{flex: 1}}
initialPage={0}
peekEnabled={true}
ref={viewPager => {
this.viewPager = viewPager
}}
onPageSelected={(e) => this.bindOnPageSelected(e)}
>
<View style={styles.productsContainer}>
<Swiper
index={0}
loop={false}
renderPagination={renderPagination}
>
<Image style={styles.imgStyle} source={ImageStore.commonPic.defaultGood}/>
<Image style={styles.imgStyle} source={ImageStore.commonPic.defaultGood}/>
<Image style={styles.imgStyle} source={ImageStore.commonPic.defaultGood}/>
</Swiper>
</View>
<View style={styles.detailsContainer}>
...
</View>
</ViewPagerAndroid>
如果直接包裹Swiper组件渲染时图片不会显示:
解决办法:添加定时器
constructor(props) {
super(props);
this.state = {
swiperShow: false
};
}
componentDidMount() {
setTimeout(() => {
this.setState({
swiperShow: true
});
}, 0)
}
render(){
return(
<View>
{this.state.swiperShow && <SwiperImage/>}
<View/>
)
}