【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. 软件开发语言与框架的学习本质 我 ...
随机推荐
- MySQL笔试题搜罗
一.有表如下 +------+---------+--------+ | name | subject | score | +------+---------+--------+ | 张三 | 数学 ...
- XML知识总结
1.XML概念及作用? XML( eXtensible Markup Language,可扩展标记语言)是一种简单的数据存储语言 作用:用来存储和交换数据 无法描述页面的排版和显示形式 2.XML和X ...
- C#抽奖算法
摘自网络 static void Main(string[] args) { //各物品的概率保存在数组里 ]{ 0.5f, 0.5f, , }; //单次测试 //Console.WriteLine ...
- HDU_5810_数学,概率,方差
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5810 大意:将n个球往m个盒子中投,每个球被投入每个盒子的概率相等,求方差. 看题解说,这是二项分布( ...
- Jmeter JSON断言和响应断言的区别是什么?
假设响应数据是{"code":0,"datas":{"informationStatus":1}} 响应断言:"code" ...
- Python字符串格式化--formate()的应用
1.简单运用字符串类型格式化采用format()方法,基本使用格式是:转自 <模板字符串>.format(<逗号分隔的参数>) 调用format()方法后会返回一个新的字符串, ...
- python 疑难杂症
1.getpass模块 :Pycharm不支持getpass模块,使用terminal可运行,但是getpass中文提示显示乱码?
- github+hexo(window10)
一.申请github账户 二.先安装node.js.git 本地: 三.安装hexo(建立静态网页,用Markdown写博客) 1.创建文件地址 在合适的地方新建一个文件夹,用来存放自己的博客文件,比 ...
- buildroot的make menuconfig配置
开始对buildroot 编译 [root@xxxxxx /data/sandbox/open_linux/buildroot] #make -j 20 Your Perl installation ...
- 对 p 开 n 次方 (数学推论)
#include<stdio.h> #include<string.h> #include<algorithm> #include<math.h> us ...