**A component Floating Button built with Reanimated v3+ and React Native Gesture handler V2+**
npm install @bayudev/react-native-floating-buttonsh
npm install @bayudev/react-native-floating-button@0.0.4
`
`sh
yarn add @bayudev/react-native-floating-button@0.0.4
`
EXPO SDK >= 53 and React Native <= 0.79.x, install with version 2.0.0
`sh
npm install @bayudev/react-native-floating-button@2.0.0
`
`sh
yarn add @bayudev/react-native-floating-button@2.0.0
`
Getting Started
To use the FloatingButton component, you first need to install the package via npm or yarn. Run either of the following commands:
`sh
npm install @bayudev/react-native-floating-button
`
`sh
yarn add @bayudev/react-native-floating-button
`
🚨 🚨 Please note that this library is built with React Native Reanimated v3 and uses React Native Gesture Handler. If you haven't installed Reanimated and Gesture Handler yet, please follow the installation instructions for Reanimated and Gesture Handler.
Usage
First, import the FloatingButton component from the @bayudev/react-native-floating-button library:
`javascript
import { FloatingButton } from '@bayudev/react-native-floating-button';
`
`javascript
import { StatusBar } from "expo-status-bar";
import { Image, Pressable, StyleSheet, Text, View } from "react-native";
import { useEffect, useRef, useState } from "react";
// import here
import {
FloatingButton,
FloatingButtonMethods,
} from "@bayudev/react-native-floating-button";
import { GestureHandlerRootView } from "react-native-gesture-handler";
export default function App() {
// add ref to call methods [show or hide]
const floatingButtonRef = useRef(null);
useEffect(() => {
setTimeout(() => {
floatingButtonRef.current?.show();
}, 1000);
}, []);
return (
ref={floatingButtonRef}
borderRadiusContent={50}
heightContent={90}
widthContent={90}
maxLeft={10}
maxRight={300}
maxHeight={150}
minHeight={80}
>
style={{
width: 85,
height: 85,
borderRadius: 2,
borderWidth: 1,
borderColor: "#dedede",
alignItems: "center",
justifyContent: "center",
}}
>
style={{
alignItems: "center",
justifyContent: "center",
width: 25,
height: 25,
position: "absolute",
zIndex: 99,
top: -10,
right: 0,
borderWidth: 2,
borderColor: "blue",
borderRadius: 50,
}}
onPress={() => {
floatingButtonRef.current?.hide();
setTimeout(() => {
floatingButtonRef.current?.show();
}, 3000);
}}
>
X
source={require("./assets/giftbox2.gif")}
style={{
width: 80,
height: 80,
}}
/>
);
}
`
Properties
| Property | Type | Default | Required | Description |
| -------------------- | ----------- | --------------------- | -------- | -------------------------------------------------------------------------------------|
| ref | String | null | true | using useRef for manage BottomSheet component for show or hide |
| widthContent | Number | 100 | true | width of FloatingButton |
| heightContent | Number | 100 | true | height of FloatingButton |
| borderRadiusContent | Number | 50 | false | border radius of FloatingButton |
| maxLeft | Number | 10 | false | maximum left content of FloatingButton |
| maxRight | Number | width screen - (width screen / 2.8) | false | maximum right content of FloatingButton |
| minHeight | Number | width screen / 2.8 | false | minimum height content of FloatingButton |
| maxHeight | Number | 50 | false | maximum height content of FloatingButton` |
|