本文基于React Native 0.52react
Demo上传到Git了,有须要能够看看,写了新内容会上传的(Git地址)git
1、总览程序员
轮播图几乎是必备的效果,这里选择 react-native-swiper 来实现,效果以下图:
2、实现轮播图效果github
一、经过npm安装react-native-swipernpm
`npm install react-native-swiper --save`
二、在recommend.js引入react-native-swiperreact-native
`import Swiper from` `'react-native-swiper'``;`
三、用 react-native-swiper 能够很容易的实现轮播的效果app
showButtons —— 是否显示左右翻页按钮
autoPlay —— 是否自动播放
paginationStyle —— 包含小点点的容器的样式,这里用来调整位置
dotStyle —— 小点点的样式
activeDotStyle —— 当前被激活的小点点的样式学习
<Swiper` style={styles.wrapper}` height={width*40/75}` showsButtons={``false``}` autoplay={``true``}` paginationStyle={styles.paginationStyle}` dotStyle={styles.dotStyle}` activeDotStyle={styles.activeDotStyle}` >` <Image source={require(``'../../img/1.jpg'``)} style={styles.bannerImg} />` <Image source={require(``'../../img/2.jpg'``)} style={styles.bannerImg} />` <Image source={require(``'../../img/3.jpg'``)} style={styles.bannerImg} />` <Image source={require(``'../../img/4.jpg'``)} style={styles.bannerImg} />` <Image source={require(``'../../img/3.jpg'``)} style={styles.bannerImg} />` </Swiper>`
样式:flex
const styles = StyleSheet.create({` container: {` flex:` `1``,` alignItems:` `'center'``,` backgroundColor:` `'#fff'``,` },` bannerImg: {` height``: width*``40``/``75``,` width``: width,` },` wrapper: {` width``: width,` },` paginationStyle: {` bottom``:` `6``,` },` dotStyle: {` width``:` `22``,` height``:` `3``,` backgroundColor:``'#fff'``,` opacity:` `0.4``,` borderRadius:` `0``,` },` activeDotStyle: {` width``:` `22``,` height``:` `3``,` backgroundColor:``'#fff'``,` borderRadius:` `0``,` },` });`
3、解决不显示问题ui
轮播图放在APP的首页,一样有不显示的问题,解决办法和上一篇的办法几乎同样,能够看一下上一篇或是完整代码,这里就再也不赘述。
这里和上一篇相比有两处不同,须要说一下。
一、真正调用接口加载图片的时候,不会出现一开始图片不显示的问题。
二、在状态为false的时候,先显示第一张图片
if` `(``this``.state.swiperShow) {` return` `(` <Swiper >` …………略` </Swiper>` )` }` `else` `{` return` `(` <View style={{ height: width*40/75 }}>` <Image source={require(``'../../img/1.jpg'``)} style={styles.bannerImg} />` </View>` );` }`
为了学习工做与休闲娱乐互不冲突,现新建圈【码农茶水铺】用于程序员生活,爱好,交友,求职招聘,吐槽等话题交流,但愿各位大神工做之余到茶水铺来喝茶聊天。群号:582735936