πŸš€ Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more β†’
Socket
DemoInstallSign in
Socket

react-native-lq-toast

Package Overview
Dependencies
Maintainers
0
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-native-lq-toast

A customizable toast component for React Native.

1.0.19
latest
Source
npm
Version published
Weekly downloads
2
100%
Maintainers
0
Weekly downloads
Β 
Created
Source

react-native-lq-toast

A lightweight and customizable toast notification library for React Native. It supports animations, different toast variants, and allows users to pass a custom component for the toast design.

πŸŽ₯ Demo

Here’s how the toast appears from the top and bottom:

Top Toast, 'Bottom Toast

πŸ“¦ Installation

npm install react-native-lq-toast

or using Yarn:

yarn add react-native-lq-toast

πŸš€ Usage

1⃣ Wrap Your App with ToastProvider

To use the toast system, wrap your app with the ToastProvider.

import React from "react";
import { ToastProvider } from "react-native-lq-toast";
import HomeScreen from "./HomeScreen";

const App = () => {
    return (
        <ToastProvider position="top" animationType="slide">
            <HomeScreen />
        </ToastProvider>
    );
};

export default App;

2⃣ Use useToast() Hook to Show Toasts

Inside any component, you can use the useToast hook to show or hide toasts.

import React from "react";
import { View, Button } from "react-native";
import { useToast } from "react-native-lq-toast";

const HomeScreen = () => {
    const { showToast } = useToast();

    return (
        <View>
            <Button
                title="Show Success Toast"
                onPress={() =>
                    showToast({
                        title: "Success",
                        description: "Your action was successful!",
                        variant: "success",
                    })
                }
            />

            <Button
                title="Show Error Toast"
                onPress={() =>
                    showToast({
                        title: "Error",
                        description: "Something went wrong.",
                        variant: "error",
                    })
                }
            />
        </View>
    );
};

export default HomeScreen;

3⃣ Customize Toast Position and Animation

By default, the toast appears at the top of the screen with a slide animation, but you can customize both:

<ToastProvider position="bottom" animationType="fade">
    <HomeScreen />
</ToastProvider>

4⃣ Passing a Custom Toast Component

You can pass a custom component for the toast UI while still using the built-in animation:

const CustomToast = ({ title, description, onDismiss }) => {
    return (
        <View
            style={{ backgroundColor: "black", padding: 10, borderRadius: 5 }}
        >
            <Text style={{ color: "white", fontWeight: "bold" }}>{title}</Text>
            <Text style={{ color: "white" }}>{description}</Text>
            <Button title="Close" onPress={onDismiss} />
        </View>
    );
};

<ToastProvider
    position="top"
    animationType="slide"
    customComponent={() => (
        <CustomToast
            title="Custom Title"
            description="Custom Description"
            onDismiss={() => console.log("closed")}
        />
    )}
>
    <HomeScreen />
</ToastProvider>;

5⃣ Setting Toast Duration and Offsets

You can control how long the toast remains visible using the duration prop in both ToastProvider and showToast. Additionally, you can adjust the toast's position using offsetTop and offsetBottom.

<ToastProvider
    position="top"
    animationType="fade"
    duration={4000}
    offsetTop={60}
    offsetBottom={100}
>
    <HomeScreen />
</ToastProvider>
showToast({
    title: "Info",
    description: "This message will disappear in 5 seconds.",
    variant: "warning",
    duration: 4000,
});

What’s Improved?

βœ… Toast moves above the keyboard when position="bottom"
βœ… Uses Keyboard.addListener() to track the keyboard height dynamically
βœ… Keeps original offsetTop and offsetBottom behavior intact
βœ… Supports animationType prop: "slide" and "fade"

🎨 Toast Variants

VariantIconDefault Background
successβœ…#EFFAF6
error❌#FDEDF0
warning⚠️#FFF4E5

πŸ›  API Reference

ToastProvider Props

PropTypeDefaultDescription
position'top' | 'center' | 'bottom''top'Position of the toast.
animationType'slide' | 'fade''slide'Animation type for toast appearance.
customToastComponentReactNodenullCustom toast component.
durationnumber4000msDuration before toast disappears (ms).
offsetTopnumber60Offset from the top when position is "top".
offsetBottomnumber100Offset from the bottom when position is "bottom".

useToast() Methods

MethodArgumentsDescription
showToast{ title: string, description?: string, variant?: 'success' | 'error' | 'warning', animationType?: 'slide' | 'fade', duration?: number, offsetTop?: number, offsetBottom?: number }Displays a toast.
hideToast()Hides the current toast.

This makes sure the toast never overlaps the keyboard when appearing at the bottom! πŸš€

πŸ“ License

This project is licensed under the MIT License.

Now you're all set to use react-native-lq-toast in your project! πŸš€πŸ”₯

Keywords

react-native

FAQs

Package last updated on 25 Feb 2025

Did you know?

Socket

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