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

@thevsstech/react-native-toast

v1.0.3

Published

React Native cross-plateform (iOS/Android) toast notification component highly customizable.

Downloads

6

Readme

React Native Toast

expo supported web supported react native 60+ react native 60+

React Native cross-plateform (iOS/Android) toast notification component highly customizable.

Installation

npm install @thevsstech/react-native-toast

or with yarn

yarn add @thevsstech/react-native-toast

usage

Usage

to use toast first wrap your application or screen with toast like shown before

import Toast from "@thevsstech/react-native-toast";

// app.tsx, index or whatever component is used as initial component

const App = () => <Toast>
    // rest of your application logi
    // <Navigation/>
</Toast>

then you can show toast any where in your app, see Configuration section to see available parameters you can pass into show function


export default function HomeScreen() {
  const showDefault = () => {
    Toast.show({
        message: 'your message comes here'
    });
  };

  return (
    <Toast>
      <View style={styles.container}>
        <Button title={'show'} onPress={showDefault} />
      </View>
    </Toast>
  );
}

message option can be a string or a function that returns a React elements


Toast.show({

        // styles and animatedValue parameters are optional
        // you can use animatedValue to interpolate some animations
        message: (styles, animatedValue) => <View style={{flexDirection: 'row'}}>
            <Icon name={'warning'} size={styles.message.fontSize} color={styles.message.color} />
            <Text style={styles.message}>Your toast message comes here</Text>
        </View>
});

the toast will be automatically hidden after given duration, but if you want the hide it before that you can call hide function


 const hideDefault = () => {
    Toast.hide()
  };

Configuration

| option | description | required | default value | | ------ | ----------- | -------- | ------------- | | duration | Time until the toast gets closed | false | 2000 | | message | message to show in toast, it can be a string or a function that resolves a react element | false | '' | | type | type of toast, available values are default, error, success, warning, info | false | default | | position | position of toast, available values are bottom, top | false | bottom | | animation | animation type of toast, available values are scale, fade, slide-up, slide-bottom, see Animations section custom animations | false | scale | | style | see Styling section to make your custom styles, see Styling section to more details | false | {} | presetStyles | see Styling section to creating custom types as well as styling built-in types | false | {}

you can pass this configurations in show method, or you can specify default configs as <Toast configs={configs}



const configs = {
    duration: 3000,
    position: 'top',
    animation: 'fade'
}

const App = () => <Toast>
    // rest of your application logi
    // <Navigation/>
</Toast>

// other things

Toast.show({
    // this will override configs.duration
    duration: 2000,
    // this will override configs.position
    position: 'bottom',
    message: 'your toast message comes here'
})

Styling

You may use type configuration or you can pass your custom styles in configs as an object with 3 keys, container, message, title, for example below styling will make your toast more like native ToastAndroid

 Toast.show({
      message: 'your toast message comes here',
      style: {
        container: {
          backgroundColor: '#eeeeee',
          paddingVertical: 15,
          bottom: 35,
        },
        message: {
          color: '#000',
          fontSize: 13,
          lineHeight: 12,
        },
      },
    });

Animations

By default rn-toast supports scale, fade, slide-up, slide-bottom animations, but let say if you want to slide-right animation you can make it like this;


  Toast.show({
      message: 'this toast will slide from right',
      // if you pass style a function it will be called with an Animated.Value so you can interpolate it
      style: (animatedValue) => ({
        container: {
          transform: [
            {
              translateX: animatedValue.interpolate({
                inputRange: [0, 1],
                outputRange: [width, 0],
              }),
            },
          ],
        },
      }),
  });

Contributing

See the contributing guide to learn how to contribute to the repository and the development workflow.

License

MIT