首頁  >  文章  >  web前端  >  怎樣使用React Native做出懸浮按鈕元件

怎樣使用React Native做出懸浮按鈕元件

php中世界最好的语言
php中世界最好的语言原創
2018-05-26 16:35:571993瀏覽

這次帶給大家怎樣使用React Native做出懸浮按鈕組件,使用React Native做出懸浮按鈕組件的注意事項有哪些,下面就是實戰案例,一起來看一下。

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,那就不需要這步了。

範例程式碼

<View style={styles.container}>
  <Text style={styles.welcome}>
   悬浮按钮组件示例
  </Text>
  <ActionButton buttonColor="rgba(231,76,60,1)" position=&#39;left&#39; verticalOrientation=&#39;up&#39;>
   <ActionButton.Item buttonColor=&#39;#9b59b6&#39; title="New Task" onPress={() => console.log("notes tapped!")}>
   <Icon name="ios-create-outline" style={styles.actionButtonIcon} />
   </ActionButton.Item>
   <ActionButton.Item buttonColor=&#39;#3498db&#39; title="Notifications" onPress={() => {}}>
   <Icon name="ios-notifications-off" style={styles.actionButtonIcon} />
   </ActionButton.Item>
   <ActionButton.Item buttonColor=&#39;#1abc9c&#39; 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>

#主要參數說明

#ActionButton
  1. size:按鈕的大小,預設為56
  2. active:是否顯示按鈕
  3. position:按鈕的位置,可以為left center right
  4. offsetX:X軸上的偏移位置
  5. offsetY :Y軸上的偏移位置
  6. onPress:點選

    事件
  7. onLongPress:長按事件
  8. buttonText:按鈕標題
  9. verticalOrientation:彈出按鈕的方向,up 或down
  10. renderIcon:可以自訂按鈕顯示的樣式,預設為加號

ActionButton.Item
  1. ##size:按鈕的大小,預設為56
  2. title:按鈕標題
  3. #buttonColor:按鈕顏色
  4. onPress:點擊事件

相信看了本文案例你已經掌握了方法,更多精彩請關注php中文網其它相關文章!

推薦閱讀:

如何部署vue.js專案nginx

#怎麼使用react redux中間件

#怎麼在Vue中使用Sortable

###

以上是怎樣使用React Native做出懸浮按鈕元件的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn