本文原創首發於公衆號:ReactNative開發圈,轉載需註明出處。react
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。若是你項目中已經使用了react-native-vector-icons,那就不須要這步了。ios
<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>
size:按鈕的大小,默認爲56
active:是否顯示按鈕
position:按鈕的位置,能夠爲left center right
offsetX:X軸上的偏移位置
offsetY:Y軸上的偏移位置
onPress:點擊事件
onLongPress:長按事件
buttonText:按鈕標題
verticalOrientation:彈出按鈕的方向,up 或者 down
renderIcon:能夠自定義按鈕顯示的樣式,默認是一個加號git
size:按鈕的大小,默認爲56
title:按鈕標題
buttonColor:按鈕顏色
onPress:點擊事件github
完整代碼:GitHub - forrest23/ReactNativeComponents: React Native組件大全,介紹React Native經常使用組件的使用方法和使用示例
本次示例代碼在 Component10文件夾中。請不要吝嗇大家的Star!npm
GitHub - mastermoo/react-native-action-button: customizable multi-action-button component for react-nativereact-native
微信不讓跳轉外鏈,能夠點擊查看原文來查看外鏈GitHub內容。微信
歡迎關注個人微信公衆號:ReactNative開發圈app