在使用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

來源:简书

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

react-native-swiper苹果正常显示,Android不显示的更多相关文章

  1. WEB通知和React Native之即时通讯(iOS Android)

    WEB通知和React Native之即时通讯(iOS Android) 一,需求分析 1.1,允许服务器主动发送信息给客户端,客户端能监听到并且能接收. 1.2,为了方便同一个系统内的用户可以指定某 ...

  2. React Native之(支持iOS与Android)自定义单选按钮(RadioGroup,RadioButton)

    React Native之(支持iOS与Android)自定义单选按钮(RadioGroup,RadioButton) 一,需求与简单介绍 在开发项目时发现RN没有给提供RadioButton和Rad ...

  3. React Native之通知栏消息提示(android)

    React Native之通知栏消息提示(android) 一,需求分析与概述 1.1,推送作为手机应用的基本功能,是手机应用的重要部分,如果自己实现一套推送系统费时费力,所以大部分的应用都会选择使用 ...

  4. React Native之微信分享(iOS Android)

    React Native之微信分享(iOS Android) 在使用React Native开发项目的时候,基本都会使用到微信好友或者微信朋友圈分享功能吧,那么今天我就带大家实现以下RN微信好友以及朋 ...

  5. React Native 真机调试(iOS / Android)

    React Native 真机调试(iOS / Android) https://reactnative.dev/docs/running-on-device https://developer.ap ...

  6. 30天React Native从零到IOS/Android双平台发布总结

    前言 本人有近十年的技术背景,除了APP开发之外对后端.前端等都比较熟悉,近期做一个APP项目需要IOS.Android两个平台都需要,只能硬着头皮上.其实很早就想开发APP也很早就接触Android ...

  7. React Native 组建之IOS和Android通用抽屉

    /** * Sample React Native App * https://github.com/facebook/react-native * @flow *npm:https://www.np ...

  8. react native报错处理com.android.build.api.transform.TransformException: com.android.builder.dexing.DexArchiveBuilderException: com.android.builder.dexing.DexArchiveBuilderException: Failed to process

    背景:最近准备在使用react-native开发的app中接入友盟,来进行用户行为统计,分享,授权登录等操作. 在使用的过程中,遇到了一些错误信息,在此记录一下. 在修改android目录下的buil ...

  9. React native 环境搭建遇到问题解决(android)

    新建项目 react-native init TestApp 运行项目 react-native run-android 不好意思,错误马上就到了 问题一 通常遇到这个错误之后,系统会给出这个具体详情 ...

  10. React Native踩坑之启动android模拟器失败

    报错 Could not install the app on the device, read the error above for details.Make sure you have an A ...

随机推荐

  1. Hadoop - YARN NodeManager 剖析

    一 概述         NodeManager是执行在单个节点上的代理,它管理Hadoop集群中单个计算节点,功能包含与ResourceManager保持通信,管理Container的生命周期.监控 ...

  2. leetcode——Insertion Sort List 对链表进行插入排序(AC)

    Sort a linked list using insertion sort. class Solution { public: ListNode *insertionSortList(ListNo ...

  3. struts2入门(搭建环境、配置、示例)

    转自:https://blog.csdn.net/u012862311/article/details/53412716 1.下载Struts2的jar包 下载地址:http://archive.ap ...

  4. windows下python3 使用cx_Oracle,xlrd插件进行excel数据清洗录入

    我们在做数据分析,清洗的过程中,很多时候会面对各种各样的数据源,要针对不同的数据源进行清洗,入库的工作.当然python这个语言,我比较喜欢,开发效率高,基本上怎么写都能运行,而且安装配置简单,基本上 ...

  5. Adobe CC update (Windows/Mac OS) 独立升级包下载

    Windows 版 xiaogezi.cn Photoshop CC 下载 Download 大小 Size 日期 Date 文档 Notes Adobe Photoshop 14.2.1 Updat ...

  6. Spring深入浅出(四)AOP面向切面

    面向切面编程--AOP AOP(Aspect Oriented Programming),程序员称之为面向切面编程,是Spring框架除了IOC之外的另一个核心概念. AOP是对OOP(面向对象编程) ...

  7. vue 中使用querySelect 封装的万能选择器

    function query (el) { if (typeof el === 'string') { var selector = el; el = document.querySelector(e ...

  8. 什么是Node.js?

     Node.js是一个基于Chrome JavaScript运行时建立的平台, 用于方便地搭建响应速度快.易于扩展的网络应用.Node.js 使用事件驱动, 非阻塞I/O 模型而得以轻量和高效,非常适 ...

  9. caffe(6) Blob,Layer,Net 以及对应配置文件的编写

    深度网络(net)是一个组合模型,它由许多相互连接的层(layers)组合而成.Caffe就是组建深度网络的这样一种工具,它按照一定的策略,一层一层的搭建出自己的模型.它将所有的信息数据定义为blob ...

  10. ArchLinux 设置时间同步和硬件时间同步错误 No usable clock interface found

    笔记本不知道怎么了,总是时间对不上 硬件时间也设置不了,只能时间同步了 手动时间同步 ntpdate即可,ntp服务器在这里用这两个就好了 cn.ntp.org.cn 或 edu.ntp.org.cn ...