React Native懸浮按鈕組件:react-native-action-button,純JS組件,支持安卓和IOS雙平臺,支持設置子按鈕,支持自定義位置和樣式和圖標。
效果圖
安裝方法
npm i react-native-action-button --save react-native link react-native-vector-icons
因為用到了react-native-vector-icons圖標組件,需要做下link。如果你項目中已經(jīng)使用了react-native-vector-icons,那就不需要這步了。
示例代碼
<View style={styles.container}> <Text style={styles.welcome}> 懸浮按鈕組件示例 </Text> <ActionButton buttonColor="rgba(231,76,60,1)" position='left' verticalOrientation='up'> <ActionButton.Item buttonColor='#9b59b6' title="New Task" onPress={() => console.log("notes tapped!")}> <Icon name="ios-create-outline" style={styles.actionButtonIcon} /> </ActionButton.Item> <ActionButton.Item buttonColor='#3498db' title="Notifications" onPress={() => {}}> <Icon name="ios-notifications-off" style={styles.actionButtonIcon} /> </ActionButton.Item> <ActionButton.Item buttonColor='#1abc9c' onPress={() => {}}> <Icon name="ios-done-all-outline" style={styles.actionButtonIcon} /> </ActionButton.Item> </ActionButton> <ActionButton buttonColor="rgba(231,76,60,1)" onPress={() => { alert('你點了我!')}} renderIcon={() => (<View style={styles.actionButtonView}><Icon name="ios-create-outline" style={styles.actionButtonIcon} /> <Text style={styles.actionButtonText}>新增</Text> </View>)} /> </View>
主要參數(shù)說明
ActionButton
size:按鈕的大小,默認為56
active:是否顯示按鈕
position:按鈕的位置,可以為left center right
offsetX:X軸上的偏移位置
offsetY:Y軸上的偏移位置
onPress:點擊事件
onLongPress:長按事件
buttonText:按鈕標題
verticalOrientation:彈出按鈕的方向,up 或者 down
renderIcon:可以自定義按鈕顯示的樣式,默認是一個加號
ActionButton.Item
size:按鈕的大小,默認為56
title:按鈕標題
buttonColor:按鈕顏色
onPress:點擊事件
相信看了本文案例你已經(jīng)掌握了方法,更多精彩請關注Gxl網(wǎng)其它相關文章!
推薦閱讀:
webpack移動端自動化構建rem步驟詳解
Angular5對組件標簽添加樣式class步驟說明
聲明:本網(wǎng)頁內容旨在傳播知識,若有侵權等問題請及時與本網(wǎng)聯(lián)系,我們將在第一時間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com