React-Native學習--輪播圖第三方組件-react-native-swiper

轉(zhuǎn)載:React-Native學習--輪播圖第三方組件-react-native-swiper

一.通過npm安裝React-native-swiper

$ npm install react-native-swiper --save
$ npm i react-timer-mixin --save

二.在項目中導入

import Swiper from 'react-native-swiper';

三.使用
  return(  
      <View>  
        <Swiper height={200}  
                loop={true}  
                // showsButtons={true}  
                index={0}  
                autoplay={true}  
                horizontal={false}  
                >  
             {this.renderImg()}  
輪播圖的元素可以是任意空間 這里添加一組圖片+文字(Text)會依次顯示<span style="white-space:pre">    </span>  
         </Swiper>  
      </View>  
  
  );  
}  
renderImg(){  
        var imageViews=[];  
        for(var i=0;i<images.length;i++){  
            imageViews.push(  
                <Image  
                    key={i}  
                    style={{flex:1}}  
                    source={{uri:images[i]}}  
                    />  
            );  
        }  
        imageViews.push(<Text>lalala</Text>);  
        return imageViews;  
    }  
四.相關屬性說明
1.Basic
Prop Default Type Description
horizontal true bool 如果值為true時,那么滾動的內(nèi)容將是橫向排列的,而不是垂直于列中的。
loop true bool 如果設置為false,那么滑動到最后一張時,再次滑動將不會展示第一張圖片。
index 0 number 初始進入的頁面標識為0的頁面。
showsButtons false bool 如果設置為true,那么就可以使控制按鈕(即:左右兩側(cè)的箭頭)可見。
autoplay false bool 設置為true,則頁面可以自動跳轉(zhuǎn)。
2.Custom basic style & content
Prop Default Type Description
width - number 如果你沒有特殊的設置,就通過flex:1默認為全屏。
height - number 如果你沒有特殊的設置,就通過flex:1默認為全屏。
style {...} style 設置頁面的樣式。
3.Pagination
Prop Default Type Description
showsPagination true bool 默認值為true,在頁面下邊顯示圓點,以標明當前頁面位于第幾個。
paginationStyle {...} style 設置頁面原點的樣式,自定義的樣式會和默認樣式進行合并。
renderPagination
dot <View style={{backgroundColor:'rgba(0,0,0,.2)', width: 8, height: 8,borderRadius: 4, marginLeft: 3, marginRight: 3, marginTop: 3, marginBottom: 3,}} /> element 可以自定義不是當前圓點的樣式
activeDot <View style={{backgroundColor: '#007aff', width: 8, height: 8, borderRadius: 4, marginLeft: 3, marginRight: 3, marginTop: 3, marginBottom: 3,}} /> element 可以自定義當前頁面圓點的樣式
4.Autoplay
Prop Default Type Description
autoplay true bool 設置為true可以使頁面自動滑動。
autoplayTimeout 2.5 number 設置每個頁面自動滑動停留的時間
autoplayDirection true bool 圓點的方向允許默認自己控制
5.Control buttons
Prop Default Type Description
showsButtons true bool 是否顯示控制箭頭按鈕
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 自定義左箭頭按鈕樣式
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容