0.0.7 • Published 3 years ago

@asaeed14/react-native-toast v0.0.7

Weekly downloads
5
License
MIT
Repository
github
Last release
3 years ago

React Native Toast

React Native JS level toast for both android and IOS which can be called from any component of your app.

Install

npm install @asaeed14/react-native-toast

OR

yarn add @asaeed14/react-native-toast

Example

Top Example Bottom Example

How to Use

Wrap your application entry point with ToastProvider.

import { ToastProvider } from '@asaeed14/react-native-toast';

const App = () => {
  return (
    <ToastProvider
      defaultTheme={{
        message: 'Hello Toast',
        delay: 1000,
        position: 'bottom' | 'top',
        bottomOffset: 20,
        topOffset: 20,
        backgroundColor: 'black' | 'rgba(0, 0, 0, 0.75)',
        textColor: 'white' | 'black',
        type: 'success',
      }}
    >
      <App />
    </ToastProvider>
  );
};

You can use toast.show() from any of your component or screen.

// this is jsut an example you can call from anywhere based on your requirement.
import { useToastContext } from '@asaeed14/react-native-toast';

const LoginScreen = () => {
  const toast = useToastContext();
  useEffect(() => {
    if (login.success) {
      toast.show({
        message: 'Login Successfully',
        delay: 3000,
        position: 'bottom' | 'top',
        bottomOffset: 32,
        topOffest: 32,
        backgroundColor: 'black' | 'rgba(0, 0, 0, 0.75)',
        textColor: 'white' | 'black',
        type: 'success',
      });
    }
  }, [login]);

  return <View />;
};

ToastProvider Props

NameTypeRequireddefaultDescription
defaultThemeobjectfalsedefault PropsYou can provide default theme to make toast consistent to all over the app, default theme props can be replaced by "show" function props

Props

NameTypeRequireddefaultDescription
messagestringfalse"Hello Toast"A message for toast
delaynumberfalse1000Number in miliseconds to delay toast
position'bottom' or 'top'falsebottomPosition to show toast
bottomOffsetnumberfalse32Space from bottom if position is bottom
topOffsetnumberfalse32Space from top if position is top
backgroundColorstringfalse'rgba(0, 0, 0, 0.75)'Background color of toast
textColorstringfalse'#ffffff'Color of toast message
typestringfalse''Right now just "success" type supported. Icon will be shown on the left of message