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

摘要:
滑动图片的第三方组件:act native wiper。当前版本为1.4.3,不支持Android。index0number最初输入的页面标记为0。

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

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

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

效果图:

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

安装

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

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

2.Custom basic style & content

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

3.Pagination

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

4.Autoplay

PropDefaultTypeDescription
autoplaytruebool设置为true可以使页面自动滑动。
autoplayTimeout2.5number设置每个页面自动滑动停留的时间
autoplayDirectiontruebool圆点的方向允许默认自己控制

5.Control buttons

PropDefaultTypeDescription
showsButtonstruebool是否显示控制箭头按钮
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自定义左箭头按钮样式

免责声明:文章转载自《ReactNative学习-滑动查看图片第三方组件react-native-swiper》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇.NET Mocking Framework对比汇编语言程序设计读书笔记(4)- 程序设计基础之一下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

Html中Input中屏蔽Enter键

直接在html中加入脚本<input onkeydown="if(event.keyCode==13){event.keyCode=0;event.returnValue=false;}">或在js中建立函数 <script type="text/javascript" language="javascript"> function...

你不知道的Console命令

一、显示信息的命令 1: <!DOCTYPE html> 2: <html> 3: <head> 4: <title>常用console命令</title> 5: <meta http-equiv="Content-Type" content="...

PostgreSQL 字符串操作函数 迎客

函数:string || string 说明:String concatenation 字符串连接操作例子:'Post' || 'greSQL' = PostgreSQL 函数:string || non-string or non-string || string说明:String concatenation with one non-string i...

简道云--公式与函数的使用教程

公式与函数 在制作表单时,可以设置控件与控件之间的数据联动关系。给例如编辑完单价和数量后,自动计算总价等这样的业务场景提供了支撑。 公式面板左侧可以选择当前表单控件所对应的值,以及所有表单控件所对应的字段名。被选择后,在公式面板中会以反引号包裹的形式显示。 注意:函数在简道云里的设置是大写,即在运用函数的时候,请用纯大写字母。 表单控件与其返回值的数据类型...

Makefile所有内嵌函数

一、文本处理函数以下是GNU make内嵌的文本(字符串)处理函数。1       $(subst FROM,TO,TEXT)函数名称:字符串替换函数—subst。函数功能:把字串“TEXT”中的“FROM”字符替换为“TO”。返回值:替换后的新字符串。示例:$(subst ee,EE,feet on the street)替换“feet on the s...

图片右上角添加删除

一、css /*图片适用大小*/ img { width:100%; height:100%; } .imgAll li { /*图片容器position: relative属性*/ width:100px; height:100px; bor...