0.1.0 • Published 3 years ago

react-native-super-alert v0.1.0

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

Screenshot

React Native Super Alert is a component where you can use various types of alerts and notifications without having to import the library on all screens..

downloads

Installation

npm i react-native-super-alert --save
or
yarn add react-native-super-alert
Load the library in Root file of your application (e.g. app.js)
import SuperAlert from "react-native-super-alert";

export default function App() {
    return (
            <View>
                <AppContainer /> 
                <SuperAlert /> {/* <--- Load Super Alert here */}
            </View>
        );
    }
}

NOTE: This component will replace the default (alert) action from React Native

Usage

Default alert

After import Super alert in Root of application, you can call the component using the code bellow

Default

   // alert('Title of alert', 'Message of alert', { Object props })

Example for default alert without confirm

    alert(
        'Hello!!', // This is a title
        "This is a Super Alert" // This is a alert message
    )

Loading alert from the corners of screen

    alert(
        'Hello!!', // This is a title
        "This is a Super Alert", // This is a alert message
        {
            position: 'top' // top, bottom, left or right,
        }
    )
PropTypeDescriptionDefault
position (Optional)stringUsing alert in corners (Top, Bottom, Left, Right)''

Using confirm and cancel action

Confirm

Example

    alert(
        'Hello!!', // This is a title
        "This is a Super Alert", // This is a alert message
        {
            textConfirm: 'Confirm', // Label of button confirm
            textCancel: 'Cancel', // Label of button cancel
            onConfirm: () => confirmClick(), // Call your confirm function 
            onCancel: () => cancelClick() // Call your cancel function 
        }
    )

Then create the functions to confirm and cancel action

  confirmClick = () => {
    console.log('Confirm Action')
  }

  cancelClick = () => {
    console.log('Cancel Action')
  }

Note: You can use the confirm params in all alert types

Other types

BottomSheet

BottomSheet

    alert(
        'Hello!!', // This is a title
        "This is a Super Alert", // This is a alert message
        {
            type: 'bottomsheet'
        }
    )

Props of BottomSheet

PropTypeDescriptionDefault
bottomSheetHeight (Optional)numberAlert BottomSheet height180

Flash Message

Alt Text

    alert(
        'Title',
        'This is model of default alert, thanks for use the component',
        {
            type: 'flashmessage',
            option: 'danger', // danger | warning | info | success
            timeout: 3
        }
    )

Props of Flash Message

PropTypeDescriptionDefault
flashMessageHeight (Optional)numberFlash Message height110
option (Optional)stringSelect the Color Scheme (danger,warning,info or success)''
timeout (Optional)numberTotal of seconds to close the alert5

Example with React Navigation Component

Alt Text

Global Props

PropTypeDescriptionDefault
Type (Optional)stringSelect the type of alert (alert,bottomsheet,flashmessage)'alert'
useNativeDriver (Optional)booleanUse native driverfalse
textConfirm (Optional)stringButton confirm label'OK'
textCancel (Optional)stringButton cancel label''

Customize de Alerts

You can customize the alert according to your theme

Place your style object in the customStyle props

<SuperAlert customStyle={customStyle} />

Classes of customization

PropDescription
containerCustomize the container style
buttonCancelCustomize the button cancel style
buttonConfirmCustomize the button confirm style
textButtonCancelCustomize the button cancel label style
textButtonConfirmCustomize the button confirm label style
titleCustomize the title text style
messageCustomize the message text style

Example of custom style object

  const customStyle = {
    container: {
      backgroundColor: '#e8e8e8',
      borderRadius: 0,
    },
    buttonCancel: {
      backgroundColor: '#b51919',
      borderRadius: 0,
    },
    buttonConfirm: {
      backgroundColor: '#4490c7',
      borderRadius: 0,
    },
    textButtonCancel: {
        color: '#fff',
        fontWeight: 'bold'
    },
    textButtonConfirm: {
        color: '#fff',
        fontWeight: 'bold'
    },
    title: {
      color: '#003d69',
      fontSize: 15
    },
    message: {
      color: '#4f4f4f',
      fontSize: 12
    }
  }

Example App

You can download example app from Example App this link

Author

By Alan Ribeiro

If you think the project is useful, please donate or give me a star!

paypal

License

MIT