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

@dtrongphuc/react-native-toast-notifications

v3.4.0

Published

[![Version][version-badge]][package] [![MIT License][license-badge]][license]

Downloads

78

Readme

react-native-toast-notifications

Version MIT License

Toast component for React Native, supports Android, IOS and Web

Features

  • Fully Customizable
  • Swipe to close support
  • Smooth animation
  • Fully typed with TypeScript

Demo

react-native-web Demo

Install

Open a Terminal in the project root and run:

yarn add react-native-toast-notifications

Usage

Wrap your app in the ToastProvider, which provides context for the Toast hook.

import { ToastProvider } from 'react-native-toast-notifications'

export default function App() {
  return (
    <ToastProvider>
      <RestOfYourApp />
    <ToastProvider/>
  );
}

Then use hook like this everywhere in your app:

import { useToast } from "react-native-toast-notifications";

const Component = () => {
  const toast = useToast();

  useEffect(() => {
    toast.show("Hello World");
  }, []);
};

Methods

show()

toast.show("Task finished successfully", {
  type: "normal | success | warning | danger | custom",
  placement: "top | bottom",
  duration: 4000,
  offset: 30,
  animationType: "slide-in | zoom-in",
});

update()

let id = toast.show("Loading...");
toast.update(id, "Loading completed", {type: "success"});

hide()

let id = toast.show("Loading...");
toast.hide(id);
// or
toast.hideAll();

Customization

ToastProvider props

There are lots of props to customize your toast or your can use renderToast to implement your own component.

<ToastProvider
    placement="bottom | top"
    duration={5000}
    animationType='slide-in | zoom-in'
    animationDuration={250}
    successColor="green"
    dangerColor="red"
    dangerColor="red"
    warningColor="orange"
    normalColor="gray"
    icon={<Icon />}
    successIcon={<SuccessIcon />}
    dangerIcon={<DangerIcon />}
    warningIcon={<WarningIcon />}
    textStyle={{ fontSize: 20 }}
    offset={50} // offset for both top and bottom toasts
    offsetTop={30}
    offsetBottom={40}
    swipeEnabled={true}
    renderToast={(toastOptions) => JSX.Element} implement custom toast component.
>
...
</>

Custom toast types

You can implement your own custom types or overwrite the existing ones

<ToastProvider
    renderType={{
      custom_type: (toast) => (
        <View style={{padding: 15, backgroundColor: 'grey'}}>
          <Text>{toast.message}</Text>
        </View>
      )
    }}
>
...
</>

// You can pass other data to your custom toast using data property in show method.
toast.show("Show custom toast", {data: { title: 'Toast title' }})

FAQ

- How to call toast outside React components?

To call toasts everywhere (even outside of React components like in redux actions), After you wrapped your app in ToastProvider, You can use the Toast import to call toasts everywhre.

import {Toast} from "react-native-toast-notifications";

// you can call this everywhere
Toast.show('toast message')

- How to show toast inside a Modal?

The Modal component is a native view that sits on top of the rest of react-native application. The only way to put something above it is to put something in the modal itself, or alternately to use a JS only implementation of a Modal.

As a workaround you can put toast inside modal like this:

import Toast from "react-native-toast-notifications";

export Component = () => {
    const toastRef = useRef();
    return (
        <Modal>
            .....
            <Toast ref={toastRef} />
        </Modal>

}

Contributing

Pull request are welcome.

While developing, you can run the example app to test your changes.

Donation

If this project helped you reduce time to develop, you can buy me a cup of coffee :)

Hire

Looking for a React/React-Native Expert? Email at [email protected]

License

MIT