React Native懸浮按鈕組件的示例代碼
React Native懸浮按鈕組件:react-native-action-button,純JS組件,支持安卓和IOS雙平臺(tái),支持設(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ù)說(shuō)明
ActionButton
- size:按鈕的大小,默認(rèn)為56
- active:是否顯示按鈕
- position:按鈕的位置,可以為left center right
- offsetX:X軸上的偏移位置
- offsetY:Y軸上的偏移位置
- onPress:點(diǎn)擊事件
- onLongPress:長(zhǎng)按事件
- buttonText:按鈕標(biāo)題
- verticalOrientation:彈出按鈕的方向,up 或者 down
- renderIcon:可以自定義按鈕顯示的樣式,默認(rèn)是一個(gè)加號(hào)
ActionButton.Item
- size:按鈕的大小,默認(rèn)為56
- title:按鈕標(biāo)題
- buttonColor:按鈕顏色
- onPress:點(diǎn)擊事件
完整示例
完整代碼:GitHub - forrest23/ReactNativeComponents: React Native組件大全
本次示例代碼在 Component10文件夾中。
組件地址
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
Vite+React搭建開發(fā)構(gòu)建環(huán)境實(shí)踐記錄
這篇文章主要介紹了Vite+React搭建開發(fā)構(gòu)建環(huán)境實(shí)踐,本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2022-09-09ReactNative點(diǎn)擊事件.bind(this)操作分析
這篇文章主要為大家介紹了ReactNative點(diǎn)擊事件.bind(this)操作分析,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-11-11React競(jìng)態(tài)條件Race Condition實(shí)例詳解
這篇文章主要為大家介紹了React競(jìng)態(tài)條件Race Condition實(shí)例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-11-11React父組件數(shù)據(jù)實(shí)時(shí)更新了,子組件沒(méi)有更新的問(wèn)題
這篇文章主要介紹了React父組件數(shù)據(jù)實(shí)時(shí)更新了,子組件沒(méi)有更新的問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2024-03-03