React Native懸浮按鈕組件的示例代碼
React Native懸浮按鈕組件:react-native-action-button,純JS組件,支持安卓和IOS雙平臺,支持設(shè)置子按鈕,支持自定義位置和樣式和圖標(biāo)。
效果圖

安裝方法
npm i react-native-action-button --save react-native link react-native-vector-icons
因?yàn)橛玫搅藃eact-native-vector-icons圖標(biāo)組件,需要做下link。如果你項(xiàng)目中已經(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('你點(diǎn)了我!')}}
renderIcon={() => (<View style={styles.actionButtonView}><Icon name="ios-create-outline" style={styles.actionButtonIcon} />
<Text style={styles.actionButtonText}>新增</Text>
</View>)}
/>
</View>
主要參數(shù)說明
ActionButton
- size:按鈕的大小,默認(rèn)為56
- active:是否顯示按鈕
- position:按鈕的位置,可以為left center right
- offsetX:X軸上的偏移位置
- offsetY:Y軸上的偏移位置
- onPress:點(diǎn)擊事件
- onLongPress:長按事件
- buttonText:按鈕標(biāo)題
- verticalOrientation:彈出按鈕的方向,up 或者 down
- renderIcon:可以自定義按鈕顯示的樣式,默認(rèn)是一個(gè)加號
ActionButton.Item
- size:按鈕的大小,默認(rèn)為56
- title:按鈕標(biāo)題
- buttonColor:按鈕顏色
- onPress:點(diǎn)擊事件
完整示例
完整代碼:GitHub - forrest23/ReactNativeComponents: React Native組件大全
本次示例代碼在 Component10文件夾中。
組件地址
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
詳解基于webpack搭建react運(yùn)行環(huán)境
本篇文章主要介紹了詳解基于webpack搭建react運(yùn)行環(huán)境,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-06-06

