ReactNative学习-滑动查看图片第三方组件react-native-swiper

滑动查看图片第三方组件:react-native-swiper,现在的版本为:1.4.3,该版本还不支持Android。

下面介绍的是该组件的一些用法,可能总结的不完整,希望大家一起来共同完善。

官方文档:https://github.com/leecade/react-native-swiper

效果图:

安装

npm install --save react-native-swiper

基础用法

import React, {AppRegistry,Component,StyleSheet,Text,View} from ‘react-native‘;
import Swiper from ‘react-native-swiper‘;
 
class swiper extends Component {
  render() {
     return (
      <Swiper style={styles.wrapper} 
              showsButtons={true}
              index={1}
              loop={false}
              >
        <View style={styles.slide1}>
          <Text style={styles.text}>Hello Swiper</Text>
        </View>
        <View style={styles.slide2}>
          <Text style={styles.text}>Beautiful</Text>
        </View>
        <View style={styles.slide3}>
          <Text style={styles.text}>And simple</Text>
        </View>
      </Swiper>
    )
  }
}
 
var styles = StyleSheet.create({
  wrapper: {
  },
  slide1: {
    flex: 1,
    justifyContent: ‘center‘,
    alignItems: ‘center‘,
    backgroundColor: ‘#9DD6EB‘,
  },
  slide2: {
    flex: 1,
    justifyContent: ‘center‘,
    alignItems: ‘center‘,
    backgroundColor: ‘#97CAE5‘,
  },
  slide3: {
    flex: 1,
    justifyContent: ‘center‘,
    alignItems: ‘center‘,
    backgroundColor: ‘#92BBD9‘,
  },
  text: {
    color: ‘#fff‘,
    fontSize: 30,
    fontWeight: ‘bold‘,
  }
})
 
AppRegistry.registerComponent(‘swiper‘, () => swiper)

这个组件可以应用于各种轮播图,组件内置的设置还是很全面的(除了现在的版本还不兼容Android),用法也不复杂。

  • 组件中使用index属性来标识显示当前的页面,当页面滑动的时候这个index肯定是会变化的,我们想在页面滑动后,还能得到它的index值,可以使用onMomentumScrollEnd={(e, state, context)=>{this.currentIndex=state.index}},函数中得到的currentIndex便是当前页面的index。
  • 测试的这个版本,如果loop设置为true,showsButtons设置也为true,会出现滑动有时不正常的情况,所以我将loop设置为false来解决这个问题了。

属性

这里只是列举了一部分经常使用的属性设置,有许多回调函数的使用方法,我也不是特别熟悉,所以还是不误导大家了,.大家可以上官网上详细的了解。

1.Basic

Prop Default Type Description
horizontal true bool 如果值为true时,那么滚动的内容将是横向排列的,而不是垂直于列中的。
loop true bool 如果设置为false,那么滑动到最后一张时,再次滑动将不会展示第一张图片。
index 0 number 初始进入的页面标识为0的页面。
showsButtons false bool 如果设置为true,那么就可以使控制按钮(即:左右两侧的箭头)可见。
autoplay false bool 设置为true,则页面可以自动跳转。

2.Custom basic style & content

Prop Default Type Description
width - number 如果你没有特殊的设置,就通过flex:1默认为全屏。
height - number 如果你没有特殊的设置,就通过flex:1默认为全屏
style {...} style 设置页面的样式。

3.Pagination

Prop Default Type Description
showsPagination true bool 默认值为true,在页面下边显示圆点,以标明当前页面位于第几个。
paginationStyle {...} style 设置页面原点的样式,自定义的样式会和默认样式进行合并。
renderPagination      
dot <View style={{backgroundColor:‘rgba(0,0,0,.2)‘, width: 8, height: 8,borderRadius: 4, marginLeft: 3, marginRight: 3, marginTop: 3, marginBottom: 3,}} /> element 可以自定义不是当前圆点的样式
activeDot <View style={{backgroundColor: ‘#007aff‘, width: 8, height: 8, borderRadius: 4, marginLeft: 3, marginRight: 3, marginTop: 3, marginBottom: 3,}} /> element 可以自定义当前页面圆点的样式

4.Autoplay

Prop Default Type Description
autoplay true bool 设置为true可以使页面自动滑动。
autoplayTimeout 2.5 number 设置每个页面自动滑动停留的时间
autoplayDirection true bool 圆点的方向允许默认自己控制

5.Control buttons

Prop Default Type Description
showsButtons true bool 是否显示控制箭头按钮
buttonWrapperStyle
{position: ‘absolute‘, paddingHorizontal: 15, paddingVertical: 30,  top: 70, left: 0, alignItems:‘flex-start‘}
style 定义默认箭头按钮的样式
nextButton
<Text style={{fontSize:60, color:‘#00a7ec‘, paddingTop:30, paddingBottom:30}}>‹</Text>
element 自定义右箭头按钮样式
prevButton
<Text style={{fontSize:60, color:‘#00a7ec‘, paddingTop:30, paddingBottom:30}}>›</Text>
element 自定义左箭头按钮样式
时间: 2024-08-08 07:17:11

ReactNative学习-滑动查看图片第三方组件react-native-swiper的相关文章

React Native学习-调取摄像头第三方组件:react-native-image-picker

近期做的软件中图片处理是重点,那么自然也就用到了相机照相或者相册选取照片的功能. react-native中有image-picker这个第三方组件,但是0.18.10这个版本还不是太支持iPad. 这个组件同时支持photo和video,也就是照片和视频都可以用这个组件实现. 安装 npm install --save react-native-image-picker 安装过之后要执行rnpm link命令 用法  import ImagePickerManager from 'Native

【REACT NATIVE 系列教程之一】触摸事件的两种形式与四种TOUCHABLE组件详解

本站文章均为 李华明Himi 原创,转载务必在明显处注明: 转载自[黑米GameDev街区] 原文链接: http://www.himigame.com/react-native/2203.html 本文是RN(React Native)系列教程第一篇,当然也要给自己的群做个广告:   React Native @Himi :126100395  刚创建的群,欢迎一起学习.讨论.进步. 本文主要讲解两点: 1.   PanResponder:触摸事件,用以获取用户手指所在屏幕的坐标(x,y)或触

【REACT NATIVE 系列教程之七】统一ANDROID与IOS两个平台的程序入口&&区分平台的组件简介

本站文章均为 李华明Himi 原创,转载务必在明显处注明: 转载自[黑米GameDev街区] 原文链接: http://www.himigame.com/react-native/2260.html       本篇介绍两个细节:       1. 关于如何将index.android.js 与index.ios.js统一管理起来.       2.  Platform 组件的简单介绍与使用   一:将index.android.js 与index.ios.js统一管理起来. 由于React本身

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

[React  Native 开发环境安装和配置:-bash: react-native: command not found 报错: 前提是安装homebrew,node.js ,npm ,watchman,flow都成功.React  Native 开发环境安装和配置 执行react-native init TestProject 命令 创建demo时报错:-bash: react-native: command not found 报错提示:Please include the follo

React Native Android 应用层实战沦陷记

[工匠若水 http://blog.csdn.net/yanbober 未经允许严禁转载,请尊重作者劳动成果.私信联系我] 1 背景 一眨眼又一年快要过去了,原计划今年的最后一个小目标(React Native)看样子要留尾巴到明年了,React Native 想说爱你不容易.怎么评价你呢?应用层 JSX 编写还是很友好的,尼玛框架接入的各种锅却让人痛哭不已,万事开头难,对于 React Native 的接入可以说大量工作可能都需要投入到框架接入中(各种灰度实验的兼容性.各种锅),一旦接入稳定以

React Native 技术 开发跨平台 Native App 初探

转载请注明出处:http://blog.csdn.net/smartbetter/article/details/64190798 我们已经了解像 Titanium 和 PhoneGap 等框架,它们能让开发者用 Web 技术构建移动应用.这是一个优势,支持开发者使用原先网络和移动开发的相关技术.仅如此,相同的代码库经过小幅度的修改便能适用多个平台--这就是著名的一次编写,到处运行.然而,当涉及到构建应用的性能时,这些框架的缺点显露无遗,尽管它们有一些吸引力,但却一直更适用于构建原生应用.Rea

React Native的iOS开发步骤以及崩溃收集

React Native的iOS开发以及崩溃收集 简介 React Native使你能够在Javascript和React的基础上获得完全一致的开发体验,构建世界一流的原生APP. React Native着力于提高多平台开发的开发效率 -- 仅需学习一次,编写任何平台.(Learn once, write anywhere) Facebook已经在多项产品中使用了React Native,并且将持续地投入建设React Native. 准备 安装 iOS只能MAC下开发,需要Xcode; An

React Native基础与入门(二)--初识React Native

React Native组件 React Native是用React Native框架来组建Android和IOS App的技术,那么React Native组件就是React组件.React组件让你将UI分割成独立的.可重用的一些碎片或部分,这些部分都是相互独立的. 创建组件的三种方式 1.ES6创建组件的方式 export default class HelloComponent extends Component { render() { return <Text style={{font

React Native 开发笔记

ReactNativeDemo 学习ReactNative开发,搭建ReactNative第一个项目 React Native 开发笔记 1.安装Homebrew $ /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" 2.安装wget.git.curl工具 //每次执行brew命令时,最好先执行brew update 或者 brew upg