React-Native之轮播组件looped-carousel的介绍与使用
React-Native之轮播组件looped-carousel的介绍与使用
一,关于react-native轮播组件的介绍与对比
1,react-native-swiper在动态使用网页图片,多张图片时iOS上总是只显示第一张,Android正常显示,支持加载json数组数据。
2,react-native-viewpager,因为轮播时,下面的圆点有时显示会有误,加载上百页数据并且表现性能良好。在Android平台上面除此特性以外,ViewPager还支持自动循环无限轮播功能,类似与listview,需构建DataSource对象。
3,新的组件 react-native-looped-carousel ,整体看起来还不错(支持iOS Android),但是不支持加载json数组数据,只支持限制数组数据,而且在动态从数据库获取的数据时,如果数据还没获取完就渲染react-native-looped-carousel组件会报错:

二,react-native-looped-carousel的介绍
1,安装:
npm install react-native-looped-carousel --save
2,属性
| Name | propType | default value | description |
|---|---|---|---|
| autoplay | boolean | true | 是否自动轮播 |
| delay | number | 4000 | 多少毫秒切换一次 |
| currentPage | number | 0 | 设置初始页 |
| pageStyle | style | null | 页面的样式 |
| contentContainerStyle | style | null | contentContainerStyle for the scrollView |
| onAnimateNextPage | func | null | 切换轮播图时的回调方法 |
| swipe | bool | true | 是否允许手势滑动也换页面 |
| 分页 | --- | --- | --- |
| pageInfo | boolean | false | 是否在底部显示当前页面下标 / 页面个数 |
| pageInfoBackgroundColor | string | 'rgba(0, 0, 0, 0.25)' | 分页的背景色 |
| pageInfoBottomContainerStyle | style | null | pageInfo容器的样式 |
| pageInfoTextStyle | style | null | pageInfo中的文本样式 |
| pageInfoTextSeparator | string | ' / ' | 在 当前页面下标 和 页面个数之间的分隔符 |
| 小圆点 | --- | --- | --- |
| bullets | bool | false | 是否在轮播的底部显示小圆点 |
| bulletStyle | style | null | bullet(小圆点)的样式 |
| bulletsContainerStyle | style | null | style for the bullets container |
| chosenBulletStyle | stlye | null | bullet的容器的样式 |
| 导航箭头 | --- | --- | --- |
| arrows | bool | false | 是否显示轮播的导航箭头 |
| arrowsStyle | style | null | 导航箭头的样式 |
| arrowsContainerStyle | style | null | 导航箭头的容器样式 |
| leftArrowText | string / element | 'Left' | 左箭头的文字或图片 |
| rightArrowText | string / element | 'Right' | label / icon for right navigation arrow |
三,react-native-looped-carousel的使用实例
1,官网使用实例:
import React, { Component } from 'react';
import {
Text,
View,
Dimensions,
} from 'react-native';
import Carousel from 'react-native-looped-carousel';
const { width, height } = Dimensions.get('window');
export default class CarouselExample extends Component {
constructor(props) {
super(props);
this.state = {
size: { width, height },
};
}
_onLayoutDidChange = (e) => {
const layout = e.nativeEvent.layout;
this.setState({ size: { width: layout.width, height: layout.height } });
}
render() {
return (
<View style={{ flex: 1 }} onLayout={this._onLayoutDidChange}>
<Carousel
delay={2000}
style={this.state.size}
autoplay
pageInfo
onAnimateNextPage={(p) => console.log(p)}
>
<View style={[{ backgroundColor: '#BADA55' }, this.state.size]}><Text>1</Text></View>
<View style={[{ backgroundColor: 'red' }, this.state.size]}><Text>2</Text></View>
<View style={[{ backgroundColor: 'blue' }, this.state.size]}><Text>3</Text></View>
</Carousel>
</View>
);
}
}
2,我的使用实例:
<Carousel
delay={4000} //自动切换的延迟 (毫秒)
style={{ height: Boxheight, width: AppSetting.ScreenWidth, backgroundColor: AppSetting.BLACK }} //样式
autoplay //自动轮播
pageInfo={false} //在底部显示当前页面下标 / 页面个数
swiper //允许手势滑动
bullets={true} //显示小圆点
bulletStyle={{ //未选中的圆点样式
backgroundColor: 'rgba(255,255,255,0.4)',
width: 12,
height: 12,
borderRadius: 50,
borderColor:'rgba(255,255,255,0.4)',
// marginLeft: 10,
// marginRight: 9,
// marginTop: 6,
// marginBottom: 9,
margin:6
}} //未选中时小圆点的样式
chosenBulletStyle={{ //选中的圆点样式
backgroundColor: AppSetting.MAIN_COLOR,
width: 16,
height: 16,
borderRadius: 50,
// marginLeft: 10,
// marginRight: 9,
// marginTop: 9,
// marginBottom: 9,
margin:6
}}//选中时小圆点的样式
>
{React.Children.map(self.state.dataImageSource, (child, index) => {
return (
<View>
<TouchableOpacity
// key={index}
style={styles.img}
activeOpacity={1}
//onPress={() => { Actions.AnnouncementDetails({ model: child }) }}
onPress={() => { this.openAnnouncementData(child) }}
>
<Image
source={{ uri: child }}
style={styles.img}
resizeMode='stretch' />
</TouchableOpacity>
</View>
)
})} </Carousel>
self.setState({
announcementData: [
{
id: 1,
title: 'React Native之TextInput的介绍与使用(富文本封装与使用实例,常用输入框封装与使用实例)',
imageurl: 'http://www.baidu.com/images/banner1.png',
url: 'https://www.cnblogs.com/jackson-zhangjiang/p/9524842.html'
},
{
id: 3,
title: 'React Native之FlatList的介绍与使用实例',
imageurl: 'http://www.baidu.com/images/banner2.png',
url: 'https://www.cnblogs.com/jackson-zhangjiang/p/9523927.html'
},
{
id: 4,
title: '将数字转换成千分位表示',
imageurl: 'http://pic.58pic.com/58pic/10/97/02/30a58PICH7N.jpg',
url: 'https://www.cnblogs.com/jackson-zhangjiang/p/9454362.html'
},
],
dataImageSource: [
'http://www.baidu.com/images/banner1.png',
'http://www.baidu.com/baidufiles/banner/images/2018/08/07/QQ%E5%9B%BE%E7%89%8720180807164315.jpg',
'http://www.baidu.com/images/banner2.png',
'http://pic.58pic.com/58pic/10/97/02/30a58PICH7N.jpg',
],
isStartRendering:true
})
当数据加载完成后,再渲染界面:
{this.state.isStartRendering?this.SowingMap():null}
React-Native之轮播组件looped-carousel的介绍与使用的更多相关文章
- React Native 之轮播图swiper组件
注释:swiper组件是第三方组件 所以在使用之前应该先在命令行安装,然后将第三方的模块引入(第三方模块地址:https://github.com/leecade/react-native-swipe ...
- 基于移动端Reactive Native轮播组件的应用与开发详解
总结下这段时间学习reactive native的一些东西,我们来认识一下,被炒得这么火的rn,究竟是个什么东西,以及如何去搭建自己的demo. reactive native是什么 由facebo ...
- 移动端Reactive Native轮播组件
移动端Reactive Native轮播组件 总结下这段时间学习reactive native的一些东西,我们来认识一下,被炒得这么火的rn,究竟是个什么东西,以及如何去搭建自己的demo. reac ...
- 一分钟搞定AlloyTouch图片轮播组件
轮播图也涉及到触摸和触摸反馈,同时,AlloyTouch可以把惯性运动打开或者关闭,并且设置min和max为运动区域,超出会自动回弹. 除了一般的竖向滚动,AlloyTouch也可以支持横向滚动,甚至 ...
- bootstrap轮播组件之“如何关闭自动轮播”
在一个页面里使用多个bootstrap轮播组件的时候,如果还让所有轮播图都自动轮播的话,整个画面都在动,会给用户一种很不好的体验感受.所以,需要关闭轮播图的自动轮播. 关闭方法:去除如下属性即可: d ...
- Omi-touch实战 移动端图片轮播组件的封装
pc端的轮播,移动端的轮播都很常见.一年前,我还为手机端没有左滑,右滑事件从而封装了一个swipe库,可以自定义超过多少滑动时间就不触发,也可以设置滑动多少距离才触发,这一个功能的代码就达到400多行 ...
- bootstrap轮播组件,大屏幕图片居中效果
在慕课网学习bootstrap轮播组件的时候,了解到轮播的图片都放在了类名为item下的img中 视频中老师对图片自适应采用给图片img设置width=100%完成,然而这样自适应处理图片在不同屏幕中 ...
- 轮播组件iceSlider
~~~~作为编写组件的一个参考吧,在js输出组件样式的问题上 探讨一下 尽量简化组件的调用 function iceSlider(element,options) { /* 功能:广告翻转切换控制 参 ...
- C-Swipe Mobile 一个适用于Vue2.x的移动端轮播组件
近期在做的一个Vue2项目里需要一个可以滑动的轮播组件,但是又因为现有的传统轮播库功能过于繁琐和笨重.因此自己写了一个针对于Vue2.x的轻型轮播组件. 项目GitHub链接:C-Swipe Mobi ...
随机推荐
- KFCM算法的matlab程序(用FCM初始化聚类中心)
KFCM算法的matlab程序(用FCM初始化聚类中心) 在“聚类——KFCM”这篇文章中已经介绍了KFCM算法,现在用matlab程序对iris数据库进行实现,用FCM初始化聚类中心,并求其准确度与 ...
- 《Java大学教程》--第1章 步入Java世界
1.2 软件:用于计算机执行的指令的集合称之为程序(program).单个程序或者一组程序称之为软件(software)1.3 编译:计算机的语言称为机器码(machine code).用编译器(co ...
- JS页面打印
平常浏览网页和文档的时候,随处可见打印两个字,有时候不小心点到或者快捷键触发到,就会弹出一个打印的页面,上边显示的打印机是GoldGrid Virtual Printer,这是计算机的虚拟打印机,打印 ...
- 三、安装cmake,安装resin ,tars服务,mysql 安装介绍,安装jdk,安装maven,c++ 开发环境安装
三.安装cmake,安装resin 2018年07月01日 21:32:05 youz1976 阅读数:308 开发环境说明: centos7.2 ,最低配置:1核cpu,2G内存,1M带宽 1. ...
- 【2017山东day7】养猫
[2017山东day7]养猫 Description 你养了一只猫,为了让它快乐地成长,你需要合理地安排它每天的作息时间.假设一天分为$ n \(个时刻,猫在每个时刻要么是吃东西,要么是睡觉.在第\) ...
- 缓存数据库Memcache
为什么用缓存数据库 MySQL:将数据存储在磁盘上,数据写入读取相对较慢 Memcached:将数据存在内存中的数据库,数据读写都快,但是数据容易丢失 数据存储,数据仓库选择MySQL这种磁盘的数据库 ...
- UVA1533-Moving Pegs(BFS+状态压缩)
Problem UVA1533-Moving Pegs Accept:106 Submit:375 Time Limit: 3000 mSec Problem Description Input ...
- SpringBoot注册登录(三):注册--验证账号密码是否符合格式及后台完成注册功能
SpringBoot注册登录(一):User表的设计点击打开链接SpringBoot注册登录(二):注册---验证码kaptcha的实现点击打开链接 SpringBoot注册登录(三):注册 ...
- Y7000 (1)安装ubuntu1604遇到的问题
1安装系统 分区的时候 /boot 不再是引导分区 换成 “为系统bois保留的分区” 这个分区取代 /boot 2第一次进系统没有图形界面 在刚开机 ubuntu系统时 按e 在splash后面空 ...
- 03 python 初学(字符格式化输出)
#_author: lily #_date: 2018/12/16 name = input("your name: ") age = input("your age: ...