Socket
Socket
Sign inDemoInstall

@gifyourgame/react-native-floating-action

Package Overview
Dependencies
0
Maintainers
3
Versions
2
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @gifyourgame/react-native-floating-action

Simple (FAB) floating action component for react-native


Version published
Weekly downloads
3
increased by200%
Maintainers
3
Created
Weekly downloads
 

Readme

Source

react-native-floating-action

Floating action button for React Native

Expo example

Open the following click on your phone: Expo link

or user your phone and scan the following QR:

Use it on Expo

Example of how Expo looks

Installation

npm i react-native-floating-action --save

or

yarn add react-native-floating-action

Example

Take a look into example/ReactNativeFloatingAction-Expo

To execute the example using Expo run the following command:

yarn run run:example

or open Expo link from your mobile

How to use it

First step: import the component:

import { FloatingAction } from "react-native-floating-action";

Second step: define the buttons

const actions = [
  {
    text: "Accessibility",
    icon: require("./images/ic_accessibility_white.png"),
    name: "bt_accessibility",
    position: 2
  },
  {
    text: "Language",
    icon: require("./images/ic_language_white.png"),
    name: "bt_language",
    position: 1
  },
  {
    text: "Location",
    icon: require("./images/ic_room_white.png"),
    name: "bt_room",
    position: 3
  },
  {
    text: "Video",
    icon: require("./images/ic_videocam_white.png"),
    name: "bt_videocam",
    position: 4
  }
];

Third step: use it

<View style={styles.container}>
  <Text style={styles.example}>Floating Action example</Text>
  <FloatingAction
    actions={actions}
    onPressItem={name => {
      console.log(`selected button: ${name}`);
    }}
  />
</View>

Open and hide it programatically

There are some cases where you want to show or hide the component without pressing the main button:

<FloatingAction
  ref={(ref) => { this.floatingAction = ref; }}
  actions={[...]}
  ...
/>

and then:

this.floatingAction.animateButton();

Configuration

FloatingAction

PropertyTypeDefaultDescription
actionsarray[]Actions to be show once user press the main button
colorstring#1253bcColor of the main button
distanceToEdgenumber or object30Distance from button to edge. Can be a number or { vertical: Number, horizontal: Number } object.
visiblebooleantrueHide or Show the component using an animation
overlayColorstringrgba(68, 68, 68, 0.6)Color of the background overlay
positionstringrightPosition to render the main button and actions, options: (left, right, center)
overrideWithActionstringfalseOverride the main action with the first action inside list actions, will not show other action
floatingIconnodeReactElement
showBackgroundbooleantrueShow or Hide background after open it
openOnMountbooleanfalseOpen component after mounting it, useful on some weird cases like tutorials
actionsPaddingTopBottomnumber8Change distance between actions
iconWidthnumber15Icon width of the main button
iconHeightnumber15Icon height of the main button
iconWeightnumber2Icon weight of the main button
buttonSizenumber56Size of the main button
listenKeyboardbooleanfalseChange position when the keyboard will appear
dismissKeyboardOnPressbooleanfalseDismiss keyboard when user press on the main button
shadowobject{ shadowOpacity: 0.35, shadowOffset: { width: 0, height: 5 }, shadowColor: "#000000", shadowRadius: 3 }Change how we render the shadow of every button, this style will apply to the main button and to every action button
onPressItemfunctionFunction to be call as soon as the user select an option from actions. Will return the name of the action.
onPressMainfunctionFunction to be call as soon as use click main button and will return true or false depeneding of the state.
onPressBackdropfunctionFunction to be call as soon as the backdrop is clicked.
onClosefunctionFunction to be call after set state to false
onOpenfunctionFunction to be call after set state to true
onStateChangefunctionFunction to be call after every state change. Will return state object
animatedbooleantrueEnable the animation

Actions

PropertyTypeDefaultDescription
colorstring#1253bcColor of the action button
iconanyIcon to be rendered inside the action, will accept an URL or React.Image. If we want to send an URL we need to send it in this way: icon: { uri: 'https://imageurl.com' } if we want to send a React.Image we will use it in this way: icon: require('path/image')
namestringName of the icon, this name is used as parameter for onPressItem action
buttonSizenumber40Size of of the action button
textstringText to show near to the button. (Only apply for position = ['left', 'right'])
textStyleobject/array{ fontSize: 12 }Style to update text size
textBackgroundstring#ffffffBackground color for Text container
textColorstring#444444Text color for every action
textElevationnumber5Elevation property (also modifies "shadowOffset" in iOS)
renderfunctionCustom render function for Action. If provided, other properties are not applicable. The provided function should return a React Node
marginnumber8Additional margin for action. This property is useful when we want to override the current margin for example using custom render
sizenumber40Size of of the icon rendered inside the action

TODO

  • first implementation
  • example
  • add colors configurations
  • add more positions like left, center and right
  • support hide or show the component with an animation
  • change plus icon to be customizable
  • use components as icon
  • hide background
  • open on mounting
  • migrate to TypeScript
  • allow user defined animations
  • use crazy animations

Keywords

FAQs

Last updated on 17 Dec 2019

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc