1.8.9 • Published 11 months ago

react-native-toast-factory v1.8.9

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

react-native-toast-factory

npm version npm downloads Build Status Platforms Issues Expo

Versión: v1.8.8

Descripción

🏭react-native-toast-factory is a Toast notification library for React Native applications. It provides an easy and customizable way to display brief, non-intrusive messages in your app. The library supports various types of messages, such as errors and successes, with simple customization options to fit your app's design.

Features

  • 🎉Toast Notifications: Display messages on the screen in a non-intrusive way.
  • Toast Types: Supports notification types, such as errors and success.
  • Flexible Configuration: Customize the colors, size, and styles of the toasts.
  • Easy Integration: Install and use in your project with ease.
  • Contexto Global con Zustand🌐: Use Zustand to manage the global state of the toasts!.
  • Animations with react-native-reanimated: Integrate smooth animations for a better user experience.
  • Multiple Toast Themes🌙: Supports differents toast themes, including dark mode and custom styles.

Installation

To install the library, run the following command:

npm install react-native-toast-factory

Ejemplo de Uso

  1. Configurar el Toast Provider (Toaster):

    make sure to add the Toaster at the entry point of your application so that toast can be rendered there:

    import React from 'react';
    import { View, Text } from 'react-native';
    
    import { Toaster } from 'react-native-toast-factory'; // Ensure you import the Toaster component
    
    const App = () => (
    
        <View style={{ flex: 1 }}>
          <Toaster /> {/* Add the Toaster at the top of your app */}
          <Text>My App</Text>
          {/* Other components */}
        </View>
    
    );
    
    export default App;
  2. Display a Toast:

    Use the methods toast.success, toast.error, toast.info, toast.warning, and toast.loading to display toasts from anywhere in your application.

    These methods allow you to show messages with different types of notifications and customizable settings. Below is an example:

     import React from 'react';
     import { Button, View } from 'react-native';
     import { toast } from 'react-native-toast-factory';
     
     const ExampleComponent = () => {
       const showSuccessToast = () => {
         toast.success('Operation completed successfully.', {
           title: 'Success', // Toast title (optional)
           position: 'top-right', // Toast position (optional)
           duration: 4000, // Toast duration in milliseconds (optional)
           progress: true, // Show progress indicator (optional)
           border: true, // Show a border around the toast (optional)
           styles: {
             backgroundColor: '#28a745', // Custom background color
             borderColor: '#155724', // Custom border color
             titleColor: '#fff', // Custom title color
             textColor: '#ddd', // Custom text color
             progressColor: '#ffc107', // Custom progress indicator color
           },
         });
       };
       toast.success("Thanks for visiting us!", { toastStyle: 'dark', icon: '🚀'})
     
       const showErrorToast = () => {
         toast.error('There was a problem with the operation.', {
           title: 'Error',
           position: 'center',
           duration: 2500,
           icon: '🚫', // Custom icon (emoji)
           styles: {
             backgroundColor: '#dc3545', // Custom background color
             borderColor: '#721c24', // Custom border color
             titleColor: '#fff', // Custom title color
             textColor: '#f8d7da', // Custom text color
           },
         });
       };
     
       // Real-world example
       const sendData = () => {
         toast.loading("Loading...", {
           id: "loadData",
           duration: 2000,
           position: top, // Persistent state if loading changes to success
           toastStyle: "dark", // This prop is also persistent
           icon: '⏳', // Custom icon (emoji)
         });
         try {
           const { success, message } = axios.post('https://....');
           if (success) { 
             toast.info(message, { id: 'loadData', title: 'Success!' }); // Inherits position and toastStyle
           } else {
             // toast ...
           }
         } catch(error) {
             // toast ...
         }
       };
       
       return (
         <View>
           <Button title="Show Success" onPress={showSuccessToast} />
           <Button title="Show Error" onPress={showErrorToast} />
         </View>
       );
     };
     
     export default ExampleComponent;

Prop Properties

PropertyTypeDescription
idnumber (optional)Unique identifier for the toast.
titlestring (optional)Title of the toast.
durationnumber (optional)Duration of the toast in milliseconds.
position'top' - 'bottom' - 'center' - 'top-left' - 'top-right' - 'bottom-left' - 'bottom-right' (optional)Screen position where the toast will appear.
toastStyle'primary' - 'secondary' - 'primaryDark' - 'dark' (optional)Style of the toast.
animationType'fade' - 'slide' - 'bounce' (optional)Type of toast animation.
animationInDurationnumber (optional)Duration of the animation in milliseconds.
animationOutDurationnumber (optional)Duration of the animation in milliseconds.
progressboolean (optional)Indicates if the progress bar is displayed.
iconstring (optional)Emoji or character to display as an icon in the toast.
borderboolean (optional)Indicates if a border is displayed around the toast.
inheritStylesboolean (optional)Indicates if styles from the toast with the same id are inherited.

Custom Style Properties

PropertyTypeDescription
titleColorstring (optional)Color of the toast title.
textColorstring (optional)Color of the toast text.
titleSizenumber (optional)Font size of the toast title.
textSizenumber (optional)Font size of the toast text.
backgroundColorstring (optional)Background color of the toast.
borderRadiusnumber (optional)Border radius of the toast corners.
borderColorstring (optional)Border color of the toast.
iconSizenumber (optional)Size of the icon within the toast.
iconStyle'solid' - 'outline' - 'default' (optional)Style of the icon in the toast.
loadingColorstring (optional)Color of the loading indicator if a loading toast is shown.
progressColorstring (optional)Color of the toast progress bar.
widthnumber (optional)Custom width of the toast.
opacitynumber (optional)Indicates the opacity of the background.
heightnumber (optional)Custom height of the toast.
topnumber (optional)Custom top position of the toast on the screen.
bottomnumber (optional)Custom bottom position of the toast on the screen.
leftnumber (optional)Custom left position of the toast on the screen.
rightnumber (optional)Custom right position of the toast on the screen.
1.8.9

11 months ago

1.8.8

11 months ago