【React Native开发】
来源:互联网 发布:godaddy虚拟主机 java 编辑:程序博客网 时间:2024/05/17 08:44
首先,需要组件的配置安装:
导入组件:
import ViewPager from 'react-native-viewpager'组件的配置:
dataSource:数据源
renderPager:渲染页面,页面显示的内容
isLoop:是否循环显示
autoPlay:是否自动轮播
locked:设置禁止触摸滚动
onChangePager:页面切换时的回调函数
renderPagerIndicator:渲染指示器
animation:渲染页面时的动画
案例操作:
import React,{Component} from 'react'import { StyleSheet, View, Text, Image, Dimensions, Animated, } from 'react-native'import ViewPager from 'react-native-viewpager'const width = Dimensions.get('window').widthconst height = Dimensions.get('window').heightconst IMG = [require('./images/ic_anhui_huangshan.jpg'), require('./images/ic_beijing_gugong.jpg'), require('./images/ic_guangdong_guangzhou.jpg'), require('./images/ic_guangxi_guizhou.jpg')];export default class Root extends Component{ constructor(props){ super(props) const dataSource = new ViewPager.DataSource({pageHasChanged:(p1,p2) => p1 != p2}) this.state = { dataSource:dataSource.cloneWithPages(IMG) } } _renderPager(data,pageID){ return ( <Image style={styles.imageStyle} source={data}> </Image> ) } render(){ return ( <View style={styles.container}> <ViewPager style={styles.pagerStyle} dataSource={this.state.dataSource} renderPage={this._renderPager} isLoop={true} autoPlay={true} animation = {(animatedValue, toValue, gestureState) => { 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) }); }}> </ViewPager> </View> ) }}const styles = StyleSheet.create({ container:{ flex:1 }, pagerStyle:{ height:height/3, width:width, }, imageStyle:{ flex:1, height: height/3, resizeMode: 'stretch' },})运行结果:
0 0
- React Native开发
- React Native 开发笔记
- React-Native开发app
- react-native开发快捷键
- React Native开发(一)
- React Native开发小结
- React Native开发(二)
- React Native开发(一)
- React Native 开发
- 【React Native开发】
- 【React Native开发】
- 【React Native开发】
- 【React Native开发】
- 【React Native开发】
- 【React Native开发】
- React Native开发APP
- vscode react native 开发
- 【React Native开发】
- 将二叉查找树转换成双链表
- LintCode 克隆二叉树
- 关于诊断网络问题
- L1-030. 一帮一 java
- "as" in Swift
- 【React Native开发】
- socket 简单理解
- js中如何通过单击事件获取当前对象,并传递当前对象到函数中?
- 【LeetCode】 61. Rotate List C语言
- Matlab 图像压缩编码—代码内容
- 逆向打印、销毁、查找结点之递归实现
- h5 移动端适配3中方式
- c++中的栈、stack的初步应用
- jeecg框架中时间控件时分秒的显示