React Native开源广告轮播组件

23 篇文章 0 订阅

[译]React Native开源广告轮播组件(react-native-viewpager)

尊重版权,转载请注明出处

本文来自:江清清的技术专栏-翻译组(http://www.lcode.org)

翻译计划项目:https://github.com/jiangqqlmj/js-coach-cn

开源项目地址:https://github.com/race604/react-native-viewpager

项目介绍

该广告轮播组件(ViewPager)同时兼容Android和iOS平台,该仅仅通过React Native平台JavaScript实现。该组件像ListView一样可以加载上百页数据并且表现性能良好。在Android平台上面除此特性以外,ViewPager还支持自动循环无限轮播功能。

刚创建的React Native技术交流3群(496508742)欢迎各位大牛,React Native技术爱好者加入交流!

运行效果

更多实例点击进入:https://github.com/race604/react-native-viewpager/blob/master/Sample

配置安装

1.组件安装:

?
1
npm install react-native-viewpager --save

2.组件使用方法如下:

?
1
2
3
4
var ViewPager = require( 'react-native-viewpager' );
<ViewPager
     dataSource={ this .state.dataSource}
     renderPage={ this ._renderPage}/>
组件配置
  • dataSource: 配置轮播的数据
  • renderPage: 需要显示的页面
  • autoPlay:设置是否自动轮播
  • isLoop设置是否循环
  • locked设置禁止触摸滚动
  • onChangePage: 页面切换回调
  • renderPageIndicator: 设置页面滚动指示器
页面切换动画配置
  • animation: 进行渲染React Native动画配置
使用实例
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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)
     });
   }}
/>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值