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