0.2.0 • Published 3 years ago

@dozgrou/react-native-toastr v0.2.0

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

React Native Toastr

React Native Toastr is strongly inspired by the toastr package.

Installation

yarn add @dozgrou/react-native-toastr

or

npm install @dozgrou/react-native-toastr

Example App

To run the example application, simply clone the repository and then theses commands

cd example
npm install
npm run android OR npm run ios

Usage

First, wrap your entire application with ToastrProvider component.

import React from 'react';
import {ToastrProvider} from '@dozgrou/react-native-toastr'

class App extends React.Component {
    render() {
        return (
            <ToastrProvider>
                // App
            </ToastrProvider>
        );
    }
};

And then use the withToastr function to access the toastr api.

import React from 'react';
import {Text, TouchableOpacity} from 'react-native';
import {withToastr} from '@dozgrou/react-native-toastr';

class Button extends React.Component {
    handlePress() {
        this.props.toastr.success('Awesome notification', {
            dismissable: false,
        });
    }
	
    render() {
        return (
            <TouchableOpacity
                onPress={() => this.handlePress()}>
                <Text>Click me</Text>
            </TouchableOpacity>
        );
    }
}

//Use the function withToastr to get access to toastr props
//in any component
export default withToastr(Button)

Custom component

import React from 'react'
import {Text, TouchableOpacity, View} from 'react-native';
import {withToastr} from '@dozgrou/react-native-toastr';

const CustomComponent = ({onRemove}) => {
  return (
    <TouchableOpacity onPress={onRemove}>
      <View>
        <Text>Awesome custom component</Text>
      </View>
    </TouchableOpacity>
  )
};

const Button = () => {
  return (
    <TouchableOpacity onPress={toastr.custom(({...config}) => <CustomComponent {...config} />)}>
      <View>Click me</View>
    </TouchableOpacity>
  );
};

export default withToastr(Button);

Methods

Method nameArgumentsNotes
successtext: string, config?: ToastrConfigShow a success message (Green)
dangertext: string, config?: ToastrConfigShow a danger message (Red)
warningtext: string, config?: ToastrConfigShow a warning message (Yellow)
infotext: string, config?: ToastrConfigShow an info message (Blue)
customcomponent: Function(onRemove: Function), config?: ToastrConfigShow a custom component

Toastr config

TypeDefaultNotes
timeoutbooleantrueSet to false to disable the timeout
timeoutDurationnumber5000The timeout duration in ms
dismissablebooleantrueSet to false to disable click to remove
progressBarbooleantrueSet to false to deactivate the progress bar
duplicatebooleantrueSet to false to not display duplicates toastr

License

MIT