0.0.3 • Published 3 months ago

@bayudev/react-native-floating-button v0.0.3

Weekly downloads
-
License
MIT
Repository
github
Last release
3 months ago

REACT NATIVE FLOATING BUTTON

A component Floating Button built with Reanimated v3+ and React Native Gesture handler V2+

Getting Started

To use the FloatingButton component, you first need to install the package via npm or yarn. Run either of the following commands:

npm install @bayudev/react-native-floating-button
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:

import { FloatingButton } from '@bayudev/react-native-floating-button';
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<FloatingButtonMethods>(null);

  useEffect(() => {
    setTimeout(() => {
      floatingButtonRef.current?.show();
    }, 1000);
  }, []);

  return (
    <GestureHandlerRootView style={{ flex: 1 }}>
      <View>
        <StatusBar style="auto" />
        
        <FloatingButton
          ref={floatingButtonRef}
          borderRadiusContent={50}
          heightContent={90}
          widthContent={90}
          maxLeft={10}
          maxRight={300}
          maxHeight={150}
          minHeight={80}
        >
          <View
            style={{
              width: 85,
              height: 85,
              borderRadius: 2,
              borderWidth: 1,
              borderColor: "#dedede",
              alignItems: "center",
              justifyContent: "center",
            }}
          >
            <View>
              <Pressable
                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);
                }}
              >
                <Text>X</Text>
              </Pressable>
              <Image
                source={require("./assets/giftbox2.gif")}
                style={{
                  width: 80,
                  height: 80,
                }}
              />
            </View>
          </View>
        </FloatingButton>
      </View>
    </GestureHandlerRootView>
  );
}

Properties

PropertyTypeDefaultRequiredDescription
refStringnulltrueusing useRef for manage BottomSheet component for show or hide
widthContentNumber100truewidth of FloatingButton
heightContentNumber100trueheight of FloatingButton
borderRadiusContentNumber50falseborder radius of FloatingButton
maxLeftNumber10falsemaximum left content of FloatingButton
maxRightNumberwidth screen - (width screen / 2.8)falsemaximum right content of FloatingButton
minHeightNumberwidth screen / 2.8falseminimum height content of FloatingButton
maxHeightNumber50falsemaximum height content of FloatingButton
childrenReactNodenull or undefinedtruePut your any component here

Author

License

The library is licensed under the MIT License.

0.0.3

3 months ago

0.0.2

3 months ago

0.0.1

3 months ago