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 循环方向控制

react native 第三方组件react-native-swiper 轮播组件的更多相关文章

  1. 【Vue中的swiper轮播组件】

    <template> <swiper :options="swiperOption" ref="mySwiper"> <!-- s ...

  2. vue实例之组件开发:图片轮播组件

    一.普通方式: 其中,index是关键. <!DOCTYPE html> <html lang="en"> <head> <meta ch ...

  3. C-Swipe Mobile 一个适用于Vue2.x的移动端轮播组件

    近期在做的一个Vue2项目里需要一个可以滑动的轮播组件,但是又因为现有的传统轮播库功能过于繁琐和笨重.因此自己写了一个针对于Vue2.x的轻型轮播组件. 项目GitHub链接:C-Swipe Mobi ...

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

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

  5. 移动端Reactive Native轮播组件

    移动端Reactive Native轮播组件 总结下这段时间学习reactive native的一些东西,我们来认识一下,被炒得这么火的rn,究竟是个什么东西,以及如何去搭建自己的demo. reac ...

  6. 微信小程序_(组件)swiper轮播图

    微信小程序swiper轮播图组件官方文档 传送门 Learn: swiper组件 一.swiper组件 indicator-dots:是否显示面板指示点[默认值false] autoplay:是否自动 ...

  7. 鸿蒙开源第三方件组件——轮播组件Banner

    目录: 1.功能展示 2.Sample解析 3.Library解析 4.<鸿蒙开源第三方组件>系列文章合集 前言 基于安卓平台的轮播组件Banner(https://github.com/ ...

  8. React-Native之轮播组件looped-carousel的介绍与使用

    React-Native之轮播组件looped-carousel的介绍与使用 一,关于react-native轮播组件的介绍与对比 1,react-native-swiper在动态使用网页图片,多张图 ...

  9. vue中引用swiper轮播插件

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

  10. 使用Swiper轮播插件引起的探索

    提到Swiper轮播插件,小伙伴们应该不会感到陌生.以前我主要在移动端上使用,PC端使用较少. 注:这里需要注意的是,在PC端和移动端使用Swiper是不同的 官方给的版本有三个,分别是Swiper2 ...

随机推荐

  1. 【JavaScript 6连载】四、apply和call的用法

    <!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...

  2. html5水平方向重力感应

    html5图片随手机重力感应而移动 <!DOCTYPE html> <html lang="zh-cn"><head><meta http ...

  3. arcgis desktop 地理编码服务发布

    1.创建地址定位器 2.创建复合地址定位器 3.鼠标右键,共享为,地理编码服务.

  4. AtCoder Beginner Contest 088 (ABC)

    A - Infinite Coins 题目链接:https://abc088.contest.atcoder.jp/tasks/abc088_a Time limit : 2sec / Memory ...

  5. bc 命令

    bc命令是一种支持任意精度的交互执行的计算器语言.是Linux简单的计算器,能进行进制转换与计算.能转换的进制包括十六进制.十进制.八进制.二进制等.可以使用的运算符号包括(+)加法.(-)减法.(* ...

  6. flask框架----上下文管理

    一.上下文管理相关知识点: a.类似于本地线程 创建Local类: { 线程或协程唯一标识: { 'stack':[request],'xxx':[session,] }, 线程或协程唯一标识: { ...

  7. vue 组件之间 的通信

      组件之间通信: 同级组件之间通信:两个组件定义应用到同一个vue实例之下: <div id="webapp" class="box">    & ...

  8. 报文、http、https的理解

    一.何为报文?     报文是网络中交换与传输的数据单位,即站点一次性要发送的数据块.报文包含了将要发送的完整的数据信息,其长短不一致,长度不限且可变. 二.报文的作用     报文多是多个系统之间需 ...

  9. 原生态JDBC

    原生态JDBC JDBC(Java DataBase Connectivity,java数据库连接)是一种用于执行SQL语句的Java API.JDBC是java访问数据库的标准规范,可以为不同的关系 ...

  10. P3690 【模板】Link Cut Tree (动态树)

    P3690 [模板]Link Cut Tree (动态树) 认父不认子的lct 注意:不 要 把 $fa[x]$和$nrt(x)$ 混 在 一 起 ! #include<cstdio> v ...