ReactNative学习十二-React-Native-Viewpager
来源:互联网 发布:福建知鱼科技有限公司 编辑:程序博客网 时间:2024/05/01 00:35
1.项目地址
https://github.com/race604/react-native-viewpager
2.Usage
- Run
npm install react-native-viewpager --save
- Code like this:
var ViewPager = require('react-native-viewpager');<ViewPager dataSource={this.state.dataSource} renderPage={this._renderPage}/>
More configuration
dataSource
: this is require to provide pages data,renderPage
: this is require to render page view,autoPlay
:true
to turn page automatically,isLoop
:true
to run in infinite scroll mode,locked
:true
to disable touch scroll,onChangePage
: page change callback,renderPageIndicator
: render custom ViewPager indicator.
Page Transition Animation Controls
animation
: function that returns a React Native Animated configuration.
Example:
var ViewPager = require('react-native-viewpager');<ViewPager dataSource={this.state.dataSource} renderPage={this._renderPage} animation = {(animatedValue, toValue, gestureState) => { // Use the horizontal velocity of the swipe gesture // to affect the length of the transition so the faster you swipe // the faster the pages will transition var velocity = Math.abs(gestureState.vx); var baseDuration = 300; var duration = (velocity > 1) ? 1/velocity * baseDuration : baseDuration; return Animated.timing(animatedValue, { toValue: toValue, duration: duration, easing: Easing.out(Easing.exp) }); }}/>
3.效果图
4.实例代码
'use strict';import React, { Component, View, Image, Dimensions, StyleSheet} from 'react-native';import ViewPager from 'react-native-viewpager';var deviceWidth = Dimensions.get('window').width;const BANNER_IMGS = [ require('./images/banner/1.jpg'), require('./images/banner/2.jpg'), require('./images/banner/3.jpg'), require('./images/banner/4.jpg')];export default class MyViewPager extends React.Component { constructor(props) { super(props); // 用于构建DataSource对象 var dataSource = new ViewPager.DataSource({ pageHasChanged: (p1, p2) => p1 !== p2, }); // 实际的DataSources存放在state中 this.state = { dataSource: dataSource.cloneWithPages(BANNER_IMGS) } } _renderPage(data, pageID) { return ( <Image source={data} style={styles.page}/> ); } /** dataSource: 提供页面数据, renderPage: 用于渲染页面视图, autoPlay: 为true 将自动播放, isLoop: 为true支持循环播放, locked: 为true禁止触摸滚动, onChangePage: 页面变化的回调, renderPageIndicator: 渲染自定义的 ViewPager indicator. */ render() { return ( <View style={styles.container}> <ViewPager style={{height:130}} dataSource={this.state.dataSource} renderPage={this._renderPage} isLoop={true} autoPlay={true}/> </View> ); }}const styles = StyleSheet.create({ container: { flex: 1, flexDirection: 'row', alignItems: 'flex-start', paddingTop:5, paddingLeft:5, backgroundColor:'#999999', paddingRight:5, paddingBottom:5, }, page: { width: deviceWidth,//设备宽(只是一种实现,此处多余) flex: 1, height: 130, resizeMode: 'stretch' },});
0 0
- ReactNative学习十二-React-Native-Viewpager
- 【ReactNative】react-native 布局
- 【ReactNative】react-native 布局
- 【深入学习ReactNative】React Native简介和概述
- ReactNative学习——react-native版本升级
- ReactNative学习——react-native版本升级
- ReactNative学习第三天 UI篇 React-native-Swiper
- ReactNative系列之十二图标组件react-native-vector-icons的使用
- (十二)React-Native-生命周期详解
- react-native-viewpager踩坑记
- React Native 学习笔记十二(嵌入原生应用 甚是坑啊)
- React Native 入门(十二)
- 【ReactNative】react native 中es6语法解析
- 《React-Native系列》36、 ReactNative地图组件
- ReactNative教程 — Hello React Native
- 《React-Native系列》36、 ReactNative地图组件
- ReactNative组件-react-native-scrollable-tab-view
- 《ReactNative》之sqlite(react-native-sqlite-storage)
- 【poj 1699】Best Sequence 题意&题解&代码(C++)
- cocos2d-js:调用scheduleUpdate()不执行update()方法的解决办法
- 使用OpenCV实现分水岭算法
- 有趣的有趣的家庭菜园
- Extjs6问题——grid不显示数据
- ReactNative学习十二-React-Native-Viewpager
- IOS设计模式-单例模式
- Android IntentService完全解析 当Service遇到Handler
- How to delete PACKAGE from HANA studio
- 经过static修饰过变量与不被static修饰的变量在运算中初始值的变化关系
- python学习2
- Windows 环境下Apache HTTP Server 2.2的安装和使用apache转发weblogic集群
- 冒泡排序
- 内容:.content和.scroll-content