【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. 软件开发语言与框架的学习本质 我 ...
随机推荐
- js视频学习笔记1
1:数组赋值的个数长度定义无效,第4个存储的数还是能原封不动打印出来. js的数组是内部有一个变量名叫0,它的值是1,有一变量名叫1,它的值是2.是这样表示的 2:js是弱类型语言,没有var标识符, ...
- 启动MyEclipse 出现java.lang.RuntimeException: No application id has been found 解决办法
咋一看,太熟悉了,就去eclipse\links 目录下,发现指定的MyEclipse的路径不对. 突然想起来了,MyEclipse是换地了. MyEclipse里面内置的eclipse找不到MyEc ...
- dpkg:处理软件包 mysql-server-5.5 (--configure)时出错
卸载MySQL重新安装会出现如下问题:出现该问题主要是安装MySQL前需要删除 /var/lib/mysql文件夹以及/etc/mysql文件夹执行命令: sudo rm /var/li ...
- EF6 mysql配置
如何把一个ef项目 从sqlserver改为mysql 首先在引入了ef的层再引入这两个包,注意两个的版本一定要一样,一定要一样,一定要一样,不然就会报错 MySql.Data.Entity目前的最新 ...
- spotlight on mysql 监控
. 安装 下载地址:https://pan.baidu.com/s/1qYi3lec 官网地址——https://www.quest.com/common/registration.aspx?requ ...
- 【剑指Offer】6、旋转数组的最小数字
题目描述: 把一个数组最开始的若干个元素搬到数组的末尾,我们称之为数组的旋转. 输入一个非减排序的数组的一个旋转,输出旋转数组的最小元素. 例如数组{3,4,5,1,2}为{1,2,3,4,5 ...
- C#第十二节课
数组 using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Th ...
- 在LINUX系统上通过LINUX命令安装mysql数据库和JDK环境
此示例通过Winscp工具和Xshell已验证通过 安装示例1: 在Centos6.5上安装JDK-10.0.2版本 检查LINUX系统是否有自带或者安装过的JDK版本:Java -version 查 ...
- salt 根据ip修改主机名
首先定义pillar [root@web1 pillar]# cat hostname.sls ip_hostname: 10.1.1.1: web1 10.1.1.2: web2 10.1.1.3: ...
- vue 2.0 + elementUI 实现面包屑导航栏
Main.js 9种响应式面包屑导航和分步导航指示器UI设计 var routeList = []; router.beforeEach((to, from, next) => { var in ...