在使用react-native-swiper时,最好不要放到(FlatList , SectionList,ListView,ScrollView 等)组件中,否则Android 可能不会正常显示图片;

我们只需要在

初始化的时候设置一个属性来控制显示swiper,然后在componentDidMount后,通过setTimeout来改变显示即可:

  • 设置控制显示swiper的属性
constructor(props) {
super(props);
this.state = {
showSwiper: false
};
}
  • 通过setTimeout控制swiper显示出来
componentDidMount(){
setTimeout(()=>{
this.setState({swiperShow:true});
},0)
}
  • 渲染swiper的方法
//渲染swiper
renderSwiper = () => {
if (this.state.showSwiper) {
return (<Swiper
style={styles.wrapper}
showsButtons={false}
key={this.props.banner.length} //需要添加key,否则报错
activeDotColor={"#fff"}
paginationStyle={{bottom: scaleSize(10)}}
autoplay={true}> {
this.props.banner.map((item, index) => {
<View style={styles.slide} key={item.title}>
<Image
style={{
width: width,
height: scaleSize(160),
}}
resizeMode={"cover"}
source={{uri: item.img}}
/>
</View>);
})
}
</Swiper>)
} else {
return (<View style={{height: scaleSize(160)}}/>)
}
}
  • render方法中调用
render() {
return (
<View style={{height: scaleSize(160), width: width}}>
{this.renderSwiper()}
</View>
)
}
  • 结束!

作者:我的昵称好听吗

链接:https://www.jianshu.com/p/61c59346830d

來源:简书

简书著作权归作者所有,任何形式的转载都请联系作者获得授权并注明出处。

最新文章

  1. 解决 WPF AllowsTransparency = true 和 Webbrowser 等控件显示冲突
  2. mongodb 安装后 出现警告:** WARNING: soft rlimits too low. Number of files is 256, should be at least 1000
  3. ASP.NET MVC请求处理管道生命周期的19个关键环节(7-12)
  4. Public and Private Interfaces in ruby
  5. 用 CSS 隐藏页面元素的 5 种方法
  6. NSBundle介绍
  7. js_3_for_if_try
  8. .NET Core 给使用.NET的公司所带来的机遇
  9. enex 转 md 格式的几种方式(免费版/氪金版)
  10. 弹性盒模型flex
  11. H5 30-CSS元素的显示模式
  12. JMeter 中对于Json数据的处理方法
  13. linux 文件打包压缩成.tar.gz
  14. 数据转换bug花了半天时间 Java.math.BigDecimal cannot be cast to java.lang.String
  15. springcloud-01-介绍
  16. Beta发布-----欢迎来怼团队
  17. EL语法 ${person.id} 这里面的id指的是实例对象的成员变量
  18. Fedora8 U盘安装
  19. 小知识积累-linux下一些简单开发配置
  20. IE8下javascript的时间函数Date()不兼容问题,显示NAN【转】

热门文章

  1. C&amp;C控制服务的设计和侦测方法综述——DDoS攻击,上传从宿主机偷窃的到的信息,定时给感染机文件加密勒索等。
  2. hdoj--1312--Red and Black(dfs)
  3. django session深入
  4. Looping and dictionaries
  5. POJ 3013 Dijkstra
  6. 使用python fabric搭建RHEL 7.2大数据基础环境以及部分优化
  7. 继承—people
  8. 文本域内容在div中带换行显示
  9. HDU-1225 Football Score 模拟问题(水题)
  10. 紫书 例题 10-14 UVa 12034(组合数+递推)