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】的更多相关文章

  1. React Native 开发环境安装和配置使用报错: -bash: react-native: command not found

    [React  Native 开发环境安装和配置:-bash: react-native: command not found 报错: 前提是安装homebrew,node.js ,npm ,watc ...

  2. React Native for Android on Windows 配置开发安装总结

    配置开发安装总结(由于当前react-native更新较快,目前是针对2015年11月底时的reacti-native android for windows版本,有些内容可能过时) 官方的安装指导在 ...

  3. React 与 React Native 底层共识:React 是什么

    此系列文章将整合我的 React 视频教程与 React Native 书籍中的精华部分,给大家介绍 React 与 React Native 结合学习的方法,此小节主要介绍 React 的底层原理与 ...

  4. 用react-service做状态管理,适用于react、react native

    转载自:https://blog.csdn.net/wo_shi_ma_nong/article/details/100713151 . react-service是一个非常简单的用来在react.r ...

  5. 小谈React、React Native、React Web

    React有三个东西,React JS 前端Web框架,React Native 移动终端Hybrid框架,React Web是一个源码转换工具(React Native 转 Web,并之所以特别提出 ...

  6. React的React Native

    React的React Native React无疑是今年最火的前端框架,github上的star直逼30,000,基于React的React Native的star也直逼20,000.有了React ...

  7. React文档翻译系列(一)安装

    原文地址:原文 本系列是针对React文档进行的翻译,因为自己在学习react的时候,最开始通过看博客或者论坛等中文资料,有些内容是零零散散的接收,并没有给自己带来很好的效果,所以后来决定把文档的原文 ...

  8. React Navigation & React Native & React Native Navigation

    React Navigation & React Native & React Native Navigation React Navigation https://facebook. ...

  9. 一次掌握 React 与 React Native 两个框架

    此系列文章将整合我的 React 视频教程与 React Native 书籍中的精华部分,给大家介绍 React 与 React Native 结合学习的方法. 1. 软件开发语言与框架的学习本质 我 ...

随机推荐

  1. R 连接mysql数据库

    一.配置RODBC 1.R下载RODBC包,安装好.2.在http://dev.mysql.com/downloads/connector/odbc下载mySQL ODBC,安装好.3.windows ...

  2. Java_Web之神奇的Ajax

    为什么使用Ajax? 无刷新:不刷新整个页面,只刷新局部 无刷新的好处 提供类似C/S的交互效果,操作更方面 只更新部分页面,有效利用带宽   什么是Ajax?   XMLHttpRequest常用方 ...

  3. MFC 缩放和显示IplImage

    序言:使用OpenCV嵌入MFC的框内,图像大小不能和框大小进行匹配,因此需要缩放,使图像适用于MFC框. 后来找到了一种新的方法,此方案貌似u已经废弃. (1).在MFC中显示图片 void CAv ...

  4. yar 调用rpc方法

    <?php class RpcController extends Yaf_Controller_Abstract { //RPC入口 public function indexAction($ ...

  5. 测试 Zoundry Raven

    安装很方便,看看发布的内容是否好用 但发现从博客上取下来的内容是有问题的,不能正常打开

  6. Linux下文件查找命令find笔记

    在Linux命令下如果需要快速自己系统所需要处理的文件,可以通过find命令快速进行检索. 如果想在某个路径下查找相应的文件可以执行如下命令: find path -name filename # p ...

  7. 51nod1126 求递推序列的第N项【递推】

    有一个序列是这样定义的:f(1) = 1, f(2) = 1, f(n) = (A * f(n - 1) + B * f(n - 2)) mod 7. 给出A,B和N,求f(n)的值. Input 输 ...

  8. firebird的日期型字段

    fb一大特色,日期型字段.dialect3时,对date time datetime是分的很清楚的.它们之间,你必须手把格式设定好,否则会报错.而不是你想象的会自动化:表xxx的date字段yyy,i ...

  9. Spring MVC学习总结(2)——Spring MVC常用注解说明

        使用Spring MVC的注解及其用法和其它相关知识来实现控制器功能. 02     之前在使用Struts2实现MVC的注解时,是借助struts2-convention这个插件,如今我们使 ...

  10. (12)Spring Boot改变JDK编译版本【从零开始学Spring Boot】

    Spring Boot在编译的时候,是有默认JDK版本的,如果我们期望使用我们要的JDK版本的话,那么要怎么配置呢? 这个只需要修改pom.xml文件的<build> -- <plu ...