【React Natvie】React-native-swiper的安装和配置【ES6】
react-native-swiper轮播图,是我们开发中特别常见的效果,首先感谢编写react-native-swiper的大神,让我们方便了很多。这个框架主要是用来做轮播图,焦点图等,内置了各种样式的轮播图. github地址: https://github.com/leecade/react-native-swiper
React Native官方文档:https://reactnative.cn/docs/getting-started/
react-native-swiper官方教程:https://github.com/leecade/react-native-swiper
项目地址GitHub地址:https://github.com/zhouwei1994/nativeCase.git
1、react-native-swiper如何安装?
yarn add react-native-swiper
//或者
npm install --save react-native-swiper
2、react-native-swiper导入使用?
import Swiper from 'react-native-swiper';
3、react-native-swiper如何使用?
<Swiper
style={styles.swiperStyle}
// 这个很重要,解决白屏问题
removeClippedSubviews={false}
// 切换时间,单位秒
autoplayTimeout={}
// 是否自动轮播
autoplay={true}
// 如果为true,滚动方向是横向的,如果为false,滚动方向是纵向的,
horizontal={true}
dot={<View style={[styles.dotStyle,styles.dotCommonStyle]}/>}
activeDot={<View style={[styles.activeDotStyle,styles.dotCommonStyle]} />}
>
<Image source={{uri:'image1'}} style={styles.bannerStyle}/>
<Image source={{uri:'image2'}} style={styles.bannerStyle} />
<Image source={{uri:'image3'}} style={styles.bannerStyle} />
<Image source={{uri:'image4'}} style={styles.bannerStyle} />
<Image source={{uri:'image5'}} style={styles.bannerStyle} />
</Swiper>
4、react-native-swiper是否可以自定义活动标识的样式?(默认是个“ . ”)
//通过设置以下两个属性,可以实现Dot的样式自定义。
dot={<View style={[styles.dotStyle,styles.dotCommonStyle]}/>}
activeDot={<View style={[styles.activeDotStyle,styles.dotCommonStyle]} />} dotStyle:{
width:,
backgroundColor:'white',
},
activeDotStyle:{
width:,
backgroundColor: '#fdd000',
},
dotCommonStyle:{
borderRadius: ,
marginLeft:,
height:,
},
5、案例代码:
import React from 'react';
import {
ScrollView,
View,
Text,
Image,
StyleSheet,
} from 'react-native';
let Dimensions = require('Dimensions');
let {width} = Dimensions.get('window').width;
//第三方组件
import Swiper from 'react-native-swiper';
//自定义组件
import NavigatonSearch from './NANavigationSearch'; const ruleItemW = (width - 60) / 2; export default class NAHomeScreen extends React.Component {
static navigationOptions = {
title:'首页',
headerLeft:(
<Image source={{uri:'ic_scan'}} style={{width:22,height:22,marginLeft: 20}}/>
),
headerRight:(
<Image source={{uri:'ic_order'}} style={{width:22,height:22,marginRight: 20}}/>
),
headerTitle:<NavigatonSearch />
}
render() {
return (
<ScrollView style={styles.containerStyle}>
<Swiper
style={styles.swiperStyle}
// 这个很重要,解决白屏问题
removeClippedSubviews={false}
// 切换时间,单位秒
autoplayTimeout={3}
// 是否自动轮播
autoplay={true}
// 如果为true,滚动方向是横向的,如果为false,滚动方向是纵向的,
horizontal={true}
dot={<View style={[styles.dotStyle,styles.dotCommonStyle]}/>}
activeDot={<View style={[styles.activeDotStyle,styles.dotCommonStyle]} />}
>
<Image source={{uri:'image1'}} style={styles.bannerStyle}/>
<Image source={{uri:'image2'}} style={styles.bannerStyle} />
<Image source={{uri:'image3'}} style={styles.bannerStyle} />
<Image source={{uri:'image4'}} style={styles.bannerStyle} />
<Image source={{uri:'image5'}} style={styles.bannerStyle} />
</Swiper> {/*汽车服务分类*/}
<View style={styles.carServiceStyle}>
{this.renderAllService()}
</View> {/*违章查询和车贷计算*/}
<View style={styles.rulesView}>
<Image source={{uri:"bt_violation"}} style={styles.rulesItemStyle}/>
<Image source={{uri:"pic_home_chedai"}} style={styles.rulesItemStyle}/>
</View> {/*抢购广告*/}
<View>
<Image source={{uri:"banner_sale"}} style={styles.hotAdStyle}/>
</View>
</ScrollView>
);
} renderAllService(){
var itemArr = [];
let titleArr = ["汽车用品","洗车卡","汽车保养","汽车资讯"];
let iconArr = ["ic_articles","ic_card","ic_maintain","ic_home_news"];
for (var i = 0; i < titleArr.length ; i++) {
itemArr.push(
<View style={styles.serviceItemStyle}>
<Image source={{uri:iconArr[i]}} style={styles.serviceItemImage}/>
<Text style={styles.serviceItemText}>{titleArr[i]}</Text>
</View>
) }
return itemArr;
}
} const styles = StyleSheet.create({
containerStyle:{
padding: 20,
},
swiperStyle:{
height:200,
},
bannerStyle:{
height:200,
borderRadius: 10,
}, dotStyle:{
width:8,
backgroundColor:'white',
},
activeDotStyle:{
width:16,
backgroundColor: '#fdd000',
},
dotCommonStyle:{
borderRadius: 8,
marginLeft:5,
height:8,
},
carServiceStyle:{
flexDirection: 'row',
justifyContent: 'space-around',
marginTop: 20,
},
serviceItemStyle:{
alignItems: 'center'
},
serviceItemImage:{
width:45,
height:45,
},
serviceItemText:{
marginTop: 11,
fontSize:12,
color:'rgba(51,51,51,1.0)',
},
rulesView:{
flexDirection: 'row',
justifyContent:'space-between',
marginTop:20,
},
rulesItemStyle:{
width:ruleItemW,
height:65,
borderRadius:5,
},
hotAdStyle:{
flex:1,
marginTop:18,
height:69,
} })
6、效果图展示:
【React Natvie】React-native-swiper的安装和配置【ES6】的更多相关文章
- React Native 开发环境安装和配置使用报错: -bash: react-native: command not found
[React Native 开发环境安装和配置:-bash: react-native: command not found 报错: 前提是安装homebrew,node.js ,npm ,watc ...
- React Native for Android on Windows 配置开发安装总结
配置开发安装总结(由于当前react-native更新较快,目前是针对2015年11月底时的reacti-native android for windows版本,有些内容可能过时) 官方的安装指导在 ...
- React 与 React Native 底层共识:React 是什么
此系列文章将整合我的 React 视频教程与 React Native 书籍中的精华部分,给大家介绍 React 与 React Native 结合学习的方法,此小节主要介绍 React 的底层原理与 ...
- 用react-service做状态管理,适用于react、react native
转载自:https://blog.csdn.net/wo_shi_ma_nong/article/details/100713151 . react-service是一个非常简单的用来在react.r ...
- 小谈React、React Native、React Web
React有三个东西,React JS 前端Web框架,React Native 移动终端Hybrid框架,React Web是一个源码转换工具(React Native 转 Web,并之所以特别提出 ...
- React的React Native
React的React Native React无疑是今年最火的前端框架,github上的star直逼30,000,基于React的React Native的star也直逼20,000.有了React ...
- React文档翻译系列(一)安装
原文地址:原文 本系列是针对React文档进行的翻译,因为自己在学习react的时候,最开始通过看博客或者论坛等中文资料,有些内容是零零散散的接收,并没有给自己带来很好的效果,所以后来决定把文档的原文 ...
- React Navigation & React Native & React Native Navigation
React Navigation & React Native & React Native Navigation React Navigation https://facebook. ...
- 一次掌握 React 与 React Native 两个框架
此系列文章将整合我的 React 视频教程与 React Native 书籍中的精华部分,给大家介绍 React 与 React Native 结合学习的方法. 1. 软件开发语言与框架的学习本质 我 ...
随机推荐
- 连接SQL Server数据库语法
下面介绍一下连接Sqlserver数据库.把连接Sqlserver数据库封装为一个方法,以便直接调用,而不需写重复代码. import java.sql.Connection; import java ...
- (转)基于Metronic的Bootstrap开发框架经验总结(2)--列表分页处理和插件JSTree的使用
http://www.cnblogs.com/wuhuacong/p/4759564.html 在上篇<基于Metronic的Bootstrap开发框架经验总结(1)-框架总览及菜单模块的处理& ...
- JavaScript中Null和Undefined的区别
Null: null是js中的关键字,表示空值,null可以看作是object的一个特殊的值,如果一个object值为空,表示这个对象不是有效对象. Undefined: undefined不是js中 ...
- eoLinker上线两周年+ AMS V4.0 发布:全新UI界面,带来领先的API开发管理解决方案!
2018年7月,eoLinker 发布了<eoLinker AMS 2018年年中用户调研问卷>,前后经历一周的时间,共收集到超过1000份有效调查问卷.超过300个有效改进意见. eoL ...
- 为什么多 TCP 连接比单 TCP 连接传输快
转自: 我观察到,客户端机器从单一服务器使用 HTTP 下载一个文件:1. 单连接下载,速度没有达到客户端网络的最大带宽:2. 多连接同时下载,传输速度有极大的提高,带宽被占满. 假设如下前提:1. ...
- 利用vue-gird-layout 制作可定制桌面 (一)
安装 vue-gird-layout https://github.com/jbaysolutions/vue-grid-layout 先跑一遍demo 运行起来. # install with np ...
- java 定时器任务模板
1.该定时任务是基于web.xml的监听机制 listener 来实现的 建立监听类: NFDFlightDataTaskListener.java import javax.servlet.Serv ...
- CentOS7下安装docker(Docker系列1)
CentOS7下安装docker 系统要求 为了安装docker,需要准备 64-bit的CentOS 7 删除非官方的Docker包 yum的仓库中有一个很旧的Docker包, 现在Docker官方 ...
- Git 基础教程 之 Git 安装 (windows)
一,安装Git,访问下面网址进行下载 https://www.git-scm.com/download/ 或者 https://pan.baidu.com/s/19imFBVHA2Yibmw1dyza ...
- VS2015 建立一个C++的MFC简易窗体程序项目
一开始建立的窗体工程都是带很多窗口,而且自己拉到窗体的控件,一调试就看不到了,是因为新建立工程项目时勾选了太多其他的了,这里记录分享一下建立一个单纯的窗体程序项目步骤给有需要的人也可以学习. 第一步: ...