react native 第三方组件react-native-swiper 轮播组件
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 轮播组件的更多相关文章
- 【Vue中的swiper轮播组件】
<template> <swiper :options="swiperOption" ref="mySwiper"> <!-- s ...
- vue实例之组件开发:图片轮播组件
一.普通方式: 其中,index是关键. <!DOCTYPE html> <html lang="en"> <head> <meta ch ...
- C-Swipe Mobile 一个适用于Vue2.x的移动端轮播组件
近期在做的一个Vue2项目里需要一个可以滑动的轮播组件,但是又因为现有的传统轮播库功能过于繁琐和笨重.因此自己写了一个针对于Vue2.x的轻型轮播组件. 项目GitHub链接:C-Swipe Mobi ...
- 基于移动端Reactive Native轮播组件的应用与开发详解
总结下这段时间学习reactive native的一些东西,我们来认识一下,被炒得这么火的rn,究竟是个什么东西,以及如何去搭建自己的demo. reactive native是什么 由facebo ...
- 移动端Reactive Native轮播组件
移动端Reactive Native轮播组件 总结下这段时间学习reactive native的一些东西,我们来认识一下,被炒得这么火的rn,究竟是个什么东西,以及如何去搭建自己的demo. reac ...
- 微信小程序_(组件)swiper轮播图
微信小程序swiper轮播图组件官方文档 传送门 Learn: swiper组件 一.swiper组件 indicator-dots:是否显示面板指示点[默认值false] autoplay:是否自动 ...
- 鸿蒙开源第三方件组件——轮播组件Banner
目录: 1.功能展示 2.Sample解析 3.Library解析 4.<鸿蒙开源第三方组件>系列文章合集 前言 基于安卓平台的轮播组件Banner(https://github.com/ ...
- React-Native之轮播组件looped-carousel的介绍与使用
React-Native之轮播组件looped-carousel的介绍与使用 一,关于react-native轮播组件的介绍与对比 1,react-native-swiper在动态使用网页图片,多张图 ...
- vue中引用swiper轮播插件
有时候我们需要在vue中使用轮播组件,如果是在vue组件中引入第三方组件的话,最好通过npm安装,从而进行统一安装包管理. 申明:本文所使用的是vue.2x版本. 通过npm安装插件: npm ins ...
- 使用Swiper轮播插件引起的探索
提到Swiper轮播插件,小伙伴们应该不会感到陌生.以前我主要在移动端上使用,PC端使用较少. 注:这里需要注意的是,在PC端和移动端使用Swiper是不同的 官方给的版本有三个,分别是Swiper2 ...
随机推荐
- JVM 一套卷,助你快速掌握优化法则
一:虚拟机内存图解 JAVA 程序运行与虚拟机之上,运行时需要内存空间.虚拟机执行 JAVA 程序的过程中会把它管理的内存划分为不同的数据区域方便管理. 虚拟机管理内存数据区域划分如下图: 数据区域分 ...
- 基于STM32F4移植W5500官方驱动库ioLibrary_Driver(转)
源: 基于STM32F4移植W5500官方驱动库ioLibrary_Driver 参考: 基于STM32+W5500 的Ethernet和Internet移植 Upgrade W5500 Throug ...
- nginx负载均衡六种策略
Nginx服务器之负载均衡策略(6种) 一.关于Nginx的负载均衡 在服务器集群中,Nginx起到一个代理服务器的角色(即反向代理),为了避免单独一个服务器压力过大,将来自用户的请求转发给不同的 ...
- Golang字符串函数认识(一)
package main import ( "fmt" "strings" "strconv" ) func main(){ //返回字符串 ...
- 使用maven profile实现多环境配置相关打包
项目开发需要有多个环境,一般为开发,测试,预发,正式4个环境,通过maven可以实现按不同环境进行打包部署,命令为: mvn package -P dev 在eclipse中可以右击选项run con ...
- 13:python-ldap
1.1 python-ldap 基本使用 11111111111111111111
- Redhat6.4安装MongoDBv3.6.3
运用后台+配置文件方式启动. 条件 下载mongodb-linux-x86_64-rhel62-3.6.3.tar 官网https://www.mongodb.com/download-center? ...
- vue2.0之Vue Baidu Map 局部注册使用
文档地址:https://dafrok.github.io/vue-baidu-map/#/zh/start/usage 局部注册 <template> <baidu-map id= ...
- Codeforces Round #439 (Div. 2) Problem C (Codeforces 869C) - 组合数学
— This is not playing but duty as allies of justice, Nii-chan! — Not allies but justice itself, Onii ...
- 【Python022--递归】
一.递归 1.写一个求阶乘的函数 --正整数阶乘指从1乘以2乘以3乘以4一直乘到所要求的数 --普通的代码编写方式: def factorial(n): result = n for i ...