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

react-native-paper-toast

v2.0.0

Published

A toast implementation for React Native Paper

Downloads

267

Readme

React Native Paper Toast

🔥 An easy to use toast implementation for React Native Paper 🔥

  • Toast persists accross screen transition. 🚀
  • Easy to use using useToast Hook and doesn't polute markup. 🪝
  • Various toast types including info, warning and error. 👗
  • Written on TypeScript. 🔵
  • Supports Web (react-native-web). 🌞
  • 🔥 NEW: Attach action to toast. 🐍
  • 🔥 NEW: Set toast position (top, middle or bottom(default)). 🪜
  • 🔥 NEW: configure default options appwide! 💦
  • 🔥 NEW: Interactive example added! 🎉

Installation

Install with your favorite package manager.

Using Yarn:

yarn add react-native-paper-toast

Using NPM:

npm i react-native-paper-toast

Now Wrap your component tree with ToastProvider. This should be after SafeAreaProvider & PaperProvider!

// App.tsx
import React from 'react';
import { DefaultTheme, Provider as PaperProvider } from 'react-native-paper';
import { initialWindowMetrics, SafeAreaProvider } from 'react-native-safe-area-context';
import { ToastProvider } from 'react-native-paper-toast';
import Application from './application';

export default function App() {
  return (
    <SafeAreaProvider initialMetrics={initialWindowMetrics}>
      <PaperProvider theme={DefaultTheme}>
        <ToastProvider>
          <Application />
        </ToastProvider>
      </PaperProvider>
    </SafeAreaProvider>
  );
}

Usage

Import the useToast hook from the library. Calling it will return you an object with two functions show and hide to show or hide toast.

import { useToast } from 'react-native-paper-toast';

export const Screen: React.FC<Props> = (props) => {
  const toaster = useToast();

  // You can now toast methods from handler functions, effects or onPress props!

  // Call from handler function
  const handleError = () => toaster.show({ message: 'Invalid Username', type: 'error' });

  // Call from Effects
  useEffect(() => {
    login(username, password).then((v) =>
      toaster.show({ message: 'Login successful', duration: 2000 })
    );
  });

  return (
    <Surface>
      <Button onPress={() => toaster.show({ message: 'Here is a toast for ya!' })}>
        Show Toast
      </Button>
      <Button onPress={toaster.hide}>Hide Toast</Button>
    </Surface>
  );
};

API

type ToastType = 'info' | 'normal' | 'success' | 'warning' | 'error';
type ToastPosition = 'top' | 'bottom' | 'middle';

interface ToastOptions {
   /** The message to show */
  message?: string;
  /** Type of toast */
  type?: ToastType;
  /**  Position of the toast */
  position?: ToastPosition;
  /** Toast duration */
  duration?: number;
  /** Toast Action onPress */
  action?: () => void;
  /** Toast Action Label */
  actionLabel?: string;
  /** Toast Message Style */
  messageStyle: StyleProp<ViewStyle>;
  /** Toast Message Container Style */
  messageContainerStyle: StyleProp<ViewStyle>;
  /** Toast Snackbar Style */
  snackbarStyle: StyleProp<ViewStyle>;
}

interface ToastMethods {
    /** Show a new toast */
    show(options: ToastOptions): void;
    /** Hide toast that are on display */
    hide(): void;
}

interface ToastProviderProps {
    /**
     * App wide default overrides.
     * Use this to set default position or duration of toasts
     *
     * ```tsx
     * <ToastProvider overrides={{ position: 'top', duration: 3000 }}>
     *   <Application />
     * </ToastProvider>
     * ```
     */
    overrides?: ToastOptions;
}

const ToastProvider: React.FC<ToastProviderProps>;

function useToast: () => ToastMethods;

Development

This project integrates with react-native-builder-bob. To get started:

  1. Fork and Clone the repository.
  2. Create your feature branch.
  3. Install dependencies using yarn.
  4. Run example project using yarn example android, yarn example ios or yarn example web.
  5. Make your changes and create a PR!
  6. Thank you.

License

This package is licensed under the MIT License.

Contribution

Any kind of contribution is welcome. Thanks!