簡介:
這個框架主要是用來做輪播圖,焦點圖等,內(nèi)置了各種樣式的輪播圖.
github地址: https://github.com/leecade/react-native-swiper
如何使用
安裝,切換到自己項目的根目錄下,執(zhí)行以下命令:
npm i react-native-swiper --save
導(dǎo)入:
import Swiper from 'react-native-swiper';
常用屬性介紹:
1. Basic
| Prop |
Default |
Type |
Description |
| horizontal |
true |
bool |
如果值為true時,那么滾動的內(nèi)容將是橫向排列的,而不是垂直于列中的。 |
| loop |
true |
bool |
如果設(shè)置為false,那么滑動到最后一張時,再次滑動將不會展示第一張圖片。 |
| index |
0 |
number |
初始進入的頁面標識為0的頁面。 |
| showsButtons |
false |
bool |
如果設(shè)置為true,那么就可以使控制按鈕(即:左右兩側(cè)的箭頭)可見。 |
| autoplay |
false |
bool |
設(shè)置為true,則頁面可以自動跳轉(zhuǎn)。 |
2.Custom basic style & content
| Prop |
Default |
Type |
Description |
| width |
- |
number |
如果你沒有特殊的設(shè)置,就通過flex:1默認為全屏 |
| height |
- |
number |
如果你沒有特殊的設(shè)置,就通過flex:1默認為全屏 |
| style |
{...} |
style |
設(shè)置頁面的樣式。 |
3.Pagination
| Prop |
Default |
Type |
Description |
| showsPagination |
true |
bool |
默認值為true,在頁面下邊顯示圓點,以標明當(dāng)前頁面位于第幾個。 |
| paginationStyle |
{...} |
style |
設(shè)置頁面原點的樣式,自定義的樣式會和默認樣式進行合并。 |
| 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 |
可以自定義不是當(dāng)前圓點的樣。 |
| activeDot |
<View style={{backgroundColor: '#007aff', width: 8, height: 8, borderRadius: 4, marginLeft: 3, marginRight: 3, marginTop: 3, marginBottom: 3,}} /> |
element |
可以自定義當(dāng)前頁面圓點的樣式 |
4. Autoplay
| Prop |
Default |
Type |
Description |
| autoplay |
true |
bool |
設(shè)置為true可以使頁面自動滑動。 |
| autoplayTimeout |
2.5 |
number |
設(shè)置每個頁面自動滑動停留的時間 |
| 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 |
自定義左箭頭按鈕樣式。 |
代碼示例
render(){
return(
<View>
<Swiper height={200} // 指定高度
loop={true} // 是否開啟循環(huán)
showsButtons={true} // 設(shè)置控制按鈕(左右兩側(cè)的箭頭)是否可見
index={0}
autoplay={true} // 是否自動跳轉(zhuǎn)
horizontal={false} // 是否水平滾動
>
// 在這里進行添加組件操作(比如放入圖片和文字)
</Swiper>
</View>
);
}
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。