github地址:https://github.com/leecade/react-native-swiper

使用方法:安装:npm i react-native-swiper –save

查看模块:npm view react-native-swiper 
删除模块:npm rm react-native-swiper –save (这个添加save会在删除的同时去除package.json中的依赖) 
查看帮助命令:npm help 命令 (例如npm help -i查看i的使用)

基本用法

import React, { Component } from 'react';
import {AppRegistry,StyleSheet,Text,Image,TouchableOpacity,ViewPagerAndroid,Navigator,View} from 'react-native';import Swiper from 'react-native-swiper';class hello extends Component {render() {return (<Swiper style={styles.wrapper} showsButtons={true}><View style={styles.slide1}><Text style={styles.text}>Hello Swiper</Text></View><View style={styles.slide2}><Text style={styles.text}>Beautiful</Text></View><View style={styles.slide3}><Text style={styles.text}>And simple</Text></View></Swiper>);}
}const styles = StyleSheet.create({wrapper: {},slide1: {flex: 1,justifyContent: 'center',alignItems: 'center',backgroundColor: '#9DD6EB',},slide2: {flex: 1,justifyContent: 'center',alignItems: 'center',backgroundColor: '#97CAE5',},slide3: {flex: 1,justifyContent: 'center',alignItems: 'center',backgroundColor: '#92BBD9',},text: {color: '#fff',fontSize: 30,fontWeight: 'bold',}
});AppRegistry.registerComponent('hello', () => hello);

效果:

详细属性

接下来让我们好好探索一下这个框架的基本属性:

基本属性:

Prop Default Type Description
horizontal true boolean 为false提示小圆点在侧面
loop true boolean 设置为false以禁用连续循环模式
index 0 int 默认显示第几页
showsButtons false int 设置为true显示button
autoplay false boolean 设置为true将启用自动播放模式。
下面演示一下下面这些样式的效果 我设置默认选择第二页,显示button,小圆点在最下面,禁用无限循环。
<Swiper style={styles.wrapper} showsButtons={true} horizontal={true} loop={false} index={1}><View style={styles.slide1}><Text style={styles.text}>我是第一页</Text></View><View style={styles.slide2}><Text style={styles.text}>我是第二页</Text></View><View style={styles.slide3}><Text style={styles.text}>我是第三页</Text></View></Swiper>

自定义基本样式

Prop Default Type Description
width -/- number 默认flex:1
height -/- number 默认flex:1
style {…} style 请参阅源中的默认样式。
loadMinimal false boolean 只加载当前索引幻灯片
loadMinimalSize 1 number 请参阅loadMinimal
loadMinimalLoader 《ActivityIndicator/》 element 在未加载幻灯片时显示自定义加载程序
设置宽高为200,200,loadMinimal为true加载当前索引幻灯片。<Swiper style={styles.wrapper}showsButtons={true}horizontal={true} loop={false} index={1}loadMinimal={true}>

可以看出宽高都有了变化 而且只加载了一个
视图,其他的都是空白的
当我们把loadMinimal设置为true同时,loadMinimalSize设置为3这时候就回复正常了,让我们看一下效果:<Swiper style={styles.wrapper}showsButtons={true}horizontal={true} loop={false} index={1}loadMinimal={true}loadMinimalSize={3}>

Prop Default Type Description
showsPagination true boolean 设置为true可使分页可见
paginationStyle {…} style 自定义样式将与默认样式合并
renderPagination -/- function 通过三个参数(index, total, context)确定如何渲染
dot 《View style={{backgroundColor:’rgba(0,0,0,.2)’, width: 8, height: 8,borderRadius: 4, marginLeft: 3, marginRight: 3, marginTop: 3, marginBottom: 3,}} /》 element 允许自定义点元素
activeDot 《View style={{backgroundColor: ‘#007aff’, width: 8, height: 8, borderRadius: 4, marginLeft: 3, marginRight: 3, marginTop: 3, marginBottom: 3,}} /》 element 允许自定义active-dot元素

接下来让我们看一个分页的demo: 
先看一下效果:

修改小圆尖头样式

/*** Sample React Native App* https://github.com/facebook/react-native*/import React, { Component } from 'react';
import {AppRegistry,StyleSheet,Text,Image,TouchableOpacity,ViewPagerAndroid,Navigator,View,Dimensions} from 'react-native';import Swiper from 'react-native-swiper';const { width } = Dimensions.get('window')class hello extends Component {render() {return (<View><Swiper style={styles.wrapper} height={200} horizontal={true} autoplay={true}><View style={styles.slide1}><Text style={styles.text}>第一页</Text></View><View style={styles.slide2}><Text style={styles.text}>第二页</Text></View><View style={styles.slide3}><Text style={styles.text}>第三页</Text></View></Swiper><Swiper style={styles.wrapper} height={240}dot={<View style={{backgroundColor: 'rgba(0,0,0,.2)', width: 5, height: 5, borderRadius: 4, marginLeft: 3, marginRight: 3, marginTop: 3, marginBottom: 3}} />}activeDot={<View style={{backgroundColor: '#000', width: 8, height: 8, borderRadius: 4, marginLeft: 3, marginRight: 3, marginTop: 3, marginBottom: 3}} />}paginationStyle={{bottom: -23, left: null, right: 10}} loop><View style={styles.slide} title={<Text numberOfLines={1}>Aussie tourist dies at Bali hotel</Text>}><Image resizeMode='stretch' style={styles.image} source={require('./imgs/1.jpg')} /></View><View style={styles.slide} title={<Text numberOfLines={1}>Big lie behind Nine’s new show</Text>}><Image resizeMode='stretch' style={styles.image} source={require('./imgs/2.jpg')} /></View><View style={styles.slide} title={<Text numberOfLines={1}>Why Stone split from Garfield</Text>}><Image resizeMode='stretch' style={styles.image} source={require('./imgs/3.jpg')} /></View><View style={styles.slide} title={<Text numberOfLines={1}>Learn from Kim K to land that job</Text>}><Image resizeMode='stretch' style={styles.image} source={require('./imgs/4.jpg')} /></View></Swiper></View>);}
}const styles = StyleSheet.create({wrapper: {},slide: {flex: 1,justifyContent: 'center',backgroundColor: 'transparent'},slide1: {flex: 1,justifyContent: 'center',alignItems: 'center',backgroundColor: '#9DD6EB'},slide2: {flex: 1,justifyContent: 'center',alignItems: 'center',backgroundColor: '#97CAE5'},slide3: {flex: 1,justifyContent: 'center',alignItems: 'center',backgroundColor: '#92BBD9'},text: {color: '#fff',fontSize: 30,fontWeight: 'bold'},image: {width,flex: 1}
});
AppRegistry.registerComponent('hello', () => hello);

Autoplay自动换图

Prop Default Type Description
autoplay true boolean 设置为true将启用自动播放模式
autoplayTimeout 2.5 number 延迟时间(秒
autoplayDirection true boolean 循环方向控制

转载于:https://www.cnblogs.com/allenxieyusheng/p/6836228.html

react native 第三方组件react-native-swiper 轮播组件相关推荐

  1. 基于移动端Reactive Native轮播组件的应用与开发详解

    总结下这段时间学习reactive native的一些东西,我们来认识一下,被炒得这么火的rn,究竟是个什么东西,以及如何去搭建自己的demo. reactive  native是什么 由facebo ...

  2. 【Flutter】Banner 轮播组件 ( flutter_swiper 插件 | Swiper 组件 )

    文章目录 一.flutter_swiper 插件 二.Swiper 组件使用 三.完整代码示例 四.相关资源 一.flutter_swiper 插件 到 https://pub.dev/package ...

  3. 造轮子之图片轮播组件(swiper)

    图片轮播是种很常见的场景和功能,一般移动网站首页的轮播 banner,商品详情页的商品图片等位置都会用到此功能 像这种常用的场景功能肯定是有人早就写好插件了的,所以遇到这种场景,一般都遵循以下三步: ...

  4. 微信小程序---swiper轮播图组件

    微信小程序-swiper轮播图组件 在components中新建文件夹swiper components/swiper/swiper.wxml <!--components/swiper/swi ...

  5. 微信小程序vue轮播图_微信小程序使用swiper组件实现类3D轮播图

    Swiper是纯javascript打造的滑动特效插件,面向手机.平板电脑等移动终端. Swiper能实现触屏焦点图.触屏Tab切换.触屏多图切换等常用效果. Swiper开源.免费.稳定.使用简单. ...

  6. 响应式轮播_角度2的响应式轮播组件

    响应式轮播 Update (March 22, 2016): Provided a Demo Link which is available on PlunkerUpdate (March 21, 2 ...

  7. vue中引用swiper轮播插件

    有时候我们需要在vue中使用轮播组件,如果是在vue组件中引入第三方组件的话,最好通过npm安装,从而进行统一安装包管理. 申明:本文所使用的是vue.2x版本. 通过npm安装插件: npm ins ...

  8. 七、微信小程序-快速回顾 ( swiper 轮播图、scroll-view 可滚动视图区域 )

    文章目录 一.swiper 轮播图 1.1. swiper 基本使用 1.2. 调整轮播图和图片的大小 二.scroll-view 可滚动视图区域 一.swiper 轮播图 轮播图是项目中最常见的功能 ...

  9. Vue实现仿音乐播放器6-实现新歌速递与swiper轮播图切换

    前言 前面在首页已经完成今日推荐以及访问百度API获取数据,现在继续来完善home主页. 效果 新歌速递 swiper实现轮播图 实现 实现新歌速递 在components下新建新歌速递组件News_ ...

  10. Vue项目中获取数据后使用swiper轮播,无法轮播且 autoplay 和 loop 失效问题!

    Vue项目中获取数据后使用swiper轮播,无法轮播且 autoplay 和 loop 失效问题! 问题表现:轮播组件显示第一张图,可拖动但无法切换到下一张图.但是F12控制台切换屏幕后能正常轮播但无 ...

最新文章

  1. 人工智能技术进阶路线
  2. 来自ERP的product属性修改
  3. Linux 命令之 ls -- 列出指定目录下的内容
  4. 时间格式转换y-m-d
  5. 【BZOJ1026】windy数,数位DP
  6. PHP编译参数 --prefix=/usr/local/php 的“深远”影响
  7. 关于微信开发与微信支付更新
  8. php 发送网络命令,linux命令经典用法与配置收录
  9. Linux strace命令 一
  10. ASP.NET中缓存(cache)的控制方法
  11. 智能家居通信协议科普,什么户型选择什么产品一文看懂
  12. Unity3D 制作绿草地,草坪,模型表面生成草地,草地效果Shader实现 草着色器 Brute Force - Grass Shader
  13. 推荐几款免费的MacOS/MacBook pro/MacBook air读取NTFS格式磁盘软件(完全免费)
  14. PC屏幕颜色识别实现鼠标自动点击
  15. 在electron应用中检测网络
  16. 启动两个80线的速腾雷达
  17. golang入门实战(二)
  18. 不同厂家ARM芯片的比较
  19. 安装abuntu时候联想拯救者R7000P怎么进入bios
  20. 异步IO爬虫 - asyncio、aiohttp

热门文章

  1. 数据库管理工具DBeaverEE 22 for Mac企业版
  2. 如何将PDF转换为DOCX?
  3. 如何在苹果Mac上的分屏浏览视图中使用 App?
  4. AirServer for mac如何实现无线投屏
  5. RazorSQL for Mac:查看和编辑二进制数据和图像
  6. 专注技术,回归本质,这就是太平洋未来科技的创新之处...
  7. SQL Server 2017 安装过程中的一点说明(有点意思)
  8. 二手房六大产权问题最关键
  9. InnoDB与Myisam的六大区别
  10. HTTP1.1之后的长连接和WebSocket的长连接之间的区别