npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

rn-toaster-stack

v1.1.0

Published

Toaster provider and tools for react native app

Downloads

195

Readme

ReactNative Toaster Skack

Toaster provider and tools for react native app

Git: https://github.com/Basouli/react-native-toaster My Portoflio: www.basilcollette.com

Installation

npm install --save rn-toaster-skack

Imports

Here the list of the modules that could be imported on your react components:

ToastProvider: Provider that handle a toast stack, showing them on screen.

ToastContext: Context that return a function sending a Toast.

Toast: The Toast Class, composing of a type and a message.

ToastTypeEnum: Object containing enum of toast types.

setAnimationDuration: function to set the duration of the toast animation, sliding from the top of the screen.

setDurationToast: function to set the duration of the toast's visibility on screen.

setMaxToastCount: function to set the size of the toast stack.

setToastTemplate: function to set the template of the toast.

setFallback: function to set the function called when max Toast count is reached.

Usage

First import the package on your app entry:

import { ToastProvider } from 'rn-toaster-skack';

Add the ToastProvider tag inside the return of your app entry. It should be enclosing the app jsx to insure a good style management:

return (
    <ToastProvider>
        ...
    </ToastProvider>
);

Minimal module imports needed on a react component:

import { Toast, ToastContext } from 'rn-toaster-skack';

Initialise the context function (Need useContext that could be imported with 'react'):

const addToast = useContext(ToastContext);

In this exemple, the const is named "addToast" because the only value given by the provider is a function, that give the toast to the provider.

Use addToast function whenever inside your component with a parameter Toast object that need a toast type and a message:

addToast(new Toast(ToastTypeEnum.success, 'succeed!'));

The Toast will be sent to provider that will stack it. Provider automatically handle the stack by unstacking and showing toast in order of receipt.

Exemples

Fully exemple of app entry:

import Home from './home.component.jsx';
import { ToastProvider } from 'rn-toaster-skack';
import Constants from 'expo-constants';

export default function App() {

    return (
        <SafeAreaView style={{ flex: 1, backgroundColor: "#232328", paddingTop: Constants.statusBarHeight }}>
            <StatusBar backgroundColor="#fff" animated={true} />

            <View style={{ flex: 1 }}>
                <ToastProvider>
                    <Home/>
                </ToastProvider>
            </View>
        </SafeAreaView>
    );
}

Fully exemple of a component named 'Home' using Toast:

import { useEffect, useContext } from 'react';
import { Toast, ToastContext, ToastTypeEnum } from 'rn-toaster-skack';

export default function Home(props) {

    const addToast = useContext(ToastContext);

    useEffect(() => {
        addToast(new Toast(ToastTypeEnum.info, 'Welcome!'));
    }, []);

    return (
        <View>
            <Text>Home Page With A Welcome Toast</Text>
        </View>
    );
}

Details of package

ToastTypeEnum:

ToastTypeEnum = {
    success: "success",
    info: "info",
    error: "error"
}

Toast:

/**
 * @param {string} type the type of toast, if null set to 'info'.
 * @param {string} message the message showed in toast.
 */
constructor(type, message){
    ...
}

it is advisable to use ToastTypeEnum properties for the first parameter 'type' as bellow :

new Toast(ToastTypeEnum.info, 'my info message')

Default template will apply a special style color to the toast, depending of type value: info: #3BCBEB success: #46C843 error: #CC5656

setAnimationDuration:

/**
 * @param {number} milliseconds : the ammount of milliseconds toast take to slide on screen. Default value 500
 */
setAnimationDuration(milliseconds) {...}

setDurationToast:

/**
 * @param {number} seconds : the ammount of seconds toast is showed. Must be an interger. Default value 3
 */
setDurationToast(seconds) {...}

setMaxToastCount:

/**
 * @param {number} toastAmount : the amount of toast that could be stack at the same time, before calling function fallback(). Default value 10
 */
setMaxToastCount(toastAmount) {...}

setToastTemplate:

/**
 * @param {React element} template : the template used for toast
 */
const template: React.FC<{type: ToastTypeEnum, message: string, translateValue: number}> = (props) => {
    return <Animated.View style={[ToastStyle.toastWrapper, {transform: [{ translateY: props.translateValue }]} ]}>
        <View style={ToastStyle.toast}>
            <Text style={ToastStyle.toastMessage}>{props.message}</Text>
        </View>
    </Animated.View>
};

setToastTemplate(template);

setFallback:

/**
 * @param {function} fallBack : function called when max amout of toast that could be staked is reached
 */
setFallback(fallBack) {...}

setZIndex:

/**
 * @param {number} value : the new value of Toasts zIndex
 */
setZIndex(value) {...}

svg