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 ...
随机推荐
- [转载]web安全之token
参考:http://blog.csdn.net/sum_rain/article/details/37085771 Token,就是令牌,最大的特点就是随机性,不可预测.一般黑客或软件无法猜测出来. ...
- 自学Java第一周的总结
在第一周里我花费了不少时间配置jdk的环境变量,并学习了有关java的基本知识,了解了Java中的变量.数据类型以及运算符.我知道了什么是变量并且如何去定义变量,也学会了如何去使用运算符以及对数据类型 ...
- 使用GoldenGate初始化的两种方式
在使用OGG开始增量数据的实时复制之前,一般需要对当前的存量数据进行初始化,如果是同构数据库,则可以使用数据库自带的工具完成,比如Oracle DB中的rman, expdp/impdp等. 其实og ...
- C++形参中const char * 与 char * 的区别
在函数调用时,我们经常看见一个函数的接受参数为(const char *); 例如strlen()函数,它的定义为: size_t strlen( const char *str); 那么将形参设置为 ...
- 一个用python简单的封装了aria2的jsonrpc中adduri的脚本
aria2是一个十分牛逼的下载神器,有时候项目需要一个很牛逼的下载中间件的话,aria2是一个不错的选择.其中支持jsonrpc和websocket的特性尤其诱人.但是python用起来还是有点不爽, ...
- amoeba_mysql 读写分离
环境 amoeba需要java环境,配置:略. MySQL主从配置:略. 基本架构 MySQL主:192.168.31.140 MySQL从:192.168.31.150 MySQL代理:192.16 ...
- hihocoder [Offer收割]编程练习赛14
A.小Hi和小Ho的礼物 谜之第1题,明明是第1题AC率比C还要低.题目是求在n个不同重量袋子选4袋,2袋给A,2袋给B,使2人获得重量相同,求问方案数. 我也是一脸懵b...o(n2)暴力枚举发现把 ...
- P1383 高级打字机
P1383 高级打字机 主席树 一发主席树解决. 插入操作十分显然. 撤销操作复制前面的版本就行. 询问操作十分显然. #include<iostream> #include<cst ...
- Iris Classification on PyTorch
Iris Classification on PyTorch code # -*- coding:utf8 -*- from sklearn.datasets import load_iris fro ...
- nginx负载均衡fair方式分发
fair采用的不是内建负载均衡使用的轮换的均衡算法,而是可以根据页面大小.加载时间长短智能的进行负载均衡. 这算是没有安装fair的情况 [root@localhost sbin]# ./nginx ...