1. 程式人生 > >react-native-viewpager 輪播圖

react-native-viewpager 輪播圖

"react-native": "0.40.0"

import React from 'react'

import {

    StyleSheet,

    Dimensions,

    View,

    Button,

    Image,

    Text

} from 'react-native';

var ViewPager = require('react-native-viewpager');

var deviceWidth = Dimensions.get('window').width;

//本地圖片

const IMGS = [

              require('../assets/selector_ok.png'),

              require('../assets/selectBack.png'),

              require('../assets/selector_cancle.png')

              ]

//網路圖片

var NetIMGS = [
  'https://images.unsplash.com/photo-1441742917377-57f78ee0e582?h=1024',
  'https://images.unsplash.com/photo-1441716844725-09cedc13a4e7?h=1024',
  'https://images.unsplash.com/photo-1441448770220-76743f9e6af6?h=1024',
  'https://images.unsplash.com/photo-1441260038675-7329ab4cc264?h=1024',
  'https://images.unsplash.com/photo-1441126270775-739547c8680c?h=1024',
  'https://images.unsplash.com/photo-1440964829947-ca3277bd37f8?h=1024',
  'https://images.unsplash.com/photo-1440847899694-90043f91c7f9?h=1024'
];

class ImagePager extends React.Component {

    constructor(props) {

        super(props);

        var dataSource = new ViewPager.DataSource({

            pageHasChanged: (p1, p2) => p1 !== p2,

        });

        this.state = {

            dataSource: dataSource.cloneWithPages(NetIMGS)

        }

    }

    _renderPage(data, pageID) {

        return (

                <Image

                    source={data}

                    style={styles.page}

                />

                );

    }

    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'

                                 },

                                 });

export default ImagePager;



相關推薦

react-native-viewpager

"react-native": "0.40.0"import React from 'react'import {    StyleSheet,    Dimensions,    View,    Button,    Image,    Text} from 'react

React-Native學習--第三方元件-react-native-swiper

一.通過npm安裝react-native-swiper $ npm install react-native-swiper --save $ npm i react-timer-mixin --save 二.在專案中匯入 import Swiper from

RN開發快速切換底部導航時react-native-swiper元件白屏

目前react-native平臺最好用的輪播圖元件:react-native-swiper 最近在專案迭代開發測試中發現一個問題,就是在快速切換APP底部tab導航欄時,整合的輪播圖元件react-native-swiper會白屏,無法顯示圖片 如下圖所示: 通過查詢react-native-swiper的

react native學習筆記11——react-native-swiper

react native swiper可以實現廣告輪播圖和應用引導頁的效果。 安裝 react-native-swiper是第三方元件,通過nmp來安裝。在專案的根目錄下,通過輸入 npm install react-native-swiper --s

ViewPager

.activity_main.xml <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"

側拉+TabLayout切換fragment+Viewpager小圓點和圖片上顯示標題+多條目+上拉載入+下拉重新整理

1.MainActivity主頁面 package com.example.zonghelianxi01; import android.annotation.SuppressLint; import android.support.annotation.Nullable; impor

ViewPager Banner方式實現

1.提取的基類 package com.example.viewpager_demo; import android.os.Bundle; import android.support.annotation.Nullable; import android.support.v7.app

ViewPager Handler方式實現

1.提取的基類BaseActivity package com.example.viewpager_demo; import android.os.Bundle; import android.support.annotation.Nullable; import android.su

ViewPager 功能齊全

/*寫VIewPager的佈局 <android.support.v4.view.ViewPager         android:id="@+id/viewpager_vp"         android:l

Android viewpager

主要注意的點 自動輪播+手動+home鍵之後頁面onResume接著輪播+下拉重新整理輪播圖一起重新整理 下拉重新整理的時候遇到了bug:下拉重新整理之後不再自動,小白點也不動,圖片也不輪播了 修復:需要重新設定recycleview的adapter,因為輪播圖

TabLayout、 DrawerLayout側拉、Viewpager:動態標題、view生成小圓點

package liyuanqi.bwie.com.chouti; import android.support.design.widget.TabLayout; import android.support.v4.app.Fragment; import an

TabLayout + ViewPager (雙層巢狀),側拉展示條目(頭像加listview,點選頭像可切換)PullToRefreshListView重新整理載入

模組簡介: 1.底部:TabLayout + ViewPager輪播圖 2.主頁面可測拉 展示頭像,可選擇系統相簿,切換圖片(二級取樣) 3.TabLayout + ViewPager巢狀TabLayout + ViewPager以展示 正在上映 和 *

ViewPager:自動無限,手指長按停止,實現點選事件(實用版)

此Demo是自定義的viewpager,實現功能如下:無限自動輪播,pager點選事件處理,手指長按停止自動輪播,手指擡起恢復自動輪播; 幾乎可以滿足目前專案中的要求;大家可以直接使用; 整個Demo分兩大類,一個是自定義的ViewPager,一個是MainActivi

viewpager的實現(簡潔易懂)

在做這個效果的時候,我第一時間看了網上的輪播方式,發現問題很多,有的人在程式碼裡大量的判斷手動滑動和自動滑動的狀態改變,有的人的輪播是定義了一個很大的Int值,通過順序播放相同的圖片來實現的偽輪播,看過這些程式碼感覺並不滿意,所以嘗試自己實現。 在輪播更新UI

ViewPager自動無限迴圈滑動,手指按住停止滑動

ViewPager輪播圖是很常見的功能了,但是專案總是用到,總結下加強記憶. 以下用到的都是再我公司的專案中抽取出來的 1,首先是adapter 這裡有兩點: a,getCount()的返回值是Integer.MAX_VALUE; b,instantiateItem使用到

ViewPager ,新增指示點

重要的地方都加了註釋, public class MyViewpagerFragment extends Activity { private ViewPager mViewPager; private List<View>

android viewpager 點選事件失效

給ViewPager子控制元件新增點選事件無效。 需要新增ontouch監聽才可以,但是子控制元件新增ontouch事件返回false的話,只會響應down事件,所以要在viewpager新增ontouch事件,並且判斷移動距離,避免拖動viewpager失效 OnTouc

ViewPager 不斷切換出現的bug

10-18 09:55:10.600: I/Choreographer(13774): Skipped 89 frames!  The application may be doing too much work on its main thread.10-18 09:55

初學:react-native

mysl AR paginati opacity tin stat scrip eight res 參考資料:http://reactscript.com/react-native-card-carousel-component/ import React, {Compon

react-native ——react-native-swiper使用

react-native-swiper的github地址 使用說明: 1. 先安裝React-native-swiper <Swiper style={styles.swiper} height={200} horizontal={true} paginationSty