在使用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. HTML5 canvas炫酷棱镜效果的幻灯片特效

    这是一款效果很炫酷华丽的HTML5 canvas带棱镜效果的幻灯片特效. 这个特效在每个幻灯片的前面放置一个图形.并将图形制作为三棱镜效果.它底下的幻灯片图片会被"折射"到棱镜上面 ...

  2. poj3252-Round Number 组合数学

    题目: Round Numbers Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 8492   Accepted: 2963 ...

  3. CMD应用 qtp/winshell/cmd的交互

    =================================================================== '採用windows.shell的 sendkeys 方式: s ...

  4. angularjs 自定义服务

    <!DOCTYPE HTML> <html ng-app="myApp"> <head> <meta http-equiv="C ...

  5. poj_1974,最长回文字串manacher

    时间复杂度为O(n),参考:http://bbs.dlut.edu.cn/bbstcon.php?board=Competition&gid=23474 #include<iostrea ...

  6. Xfce4里添加登录后程序自动运行

    Xfce4里添加登录后程序自动运行 (注意该方法在登录桌面环境后才会自动运行程序. 在XUbuntu下测试过, Ubuntu下应该是类似的) 方法1: 找到这个东西, 自动添加一下 方法2: 在 .c ...

  7. php7安装memcache 和 memcached 扩展

    php7安装memcache 和 memcached 扩展 标签(空格分隔): php memcache和memcached区别 memcache:http://pecl.php.net/packag ...

  8. BZOJ 1336&1337最小圆覆盖

    思路: http://blog.csdn.net/commonc/article/details/52291822 (照着算法步骤写--) 已知三点共圆 求圆心的时候 就设一下圆心坐标(x,y) 解个 ...

  9. coedforces #481Div(3)(ABCDEFG)

    A. Remove Duplicates Petya has an array aconsisting of nintegers. He wants to remove duplicate (equa ...

  10. del_archivelog

    #!/usr/bin/env bash                          #  # INTRO : The script for delete physical standby app ...