0.1.0 • Published 1 year ago

expo-alerts v0.1.0

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

expo-alerts

Internal notifications module for React Native / Expo. Focused on providing a flexible, cross-platform and easy-to-implement solution for developers looking to add internal notifications to their apps

Example Alert Notification

Customized by propsCustomized by component

Example Toast Notification

Theme Light

|

Installation

- Installing:

yarn add expo-alerts

- Installing dependencies:

  • For Native project:
yarn add expo-alerts

pod install
  • For Expo project:
expo install expo-alerts

Usage

Alert configured by props

import { Alert } from "expo-alerts";
import React, { useState } from "react";
import { Image } from "react-native";

const App = () => {
    // Handler
    const [visible, setVisible] = useState()
    
    // ALert configuration
    const alertConfig = {
        icon: <Image source={...} />,
        title: "Another alert with props",
        body: "This is an alert customized by props.\nAwesome!",
        alertStyle: { radius: 30, padding: 12 },
        actions: {
            direction: "row",
                gap: 5,
                radius: 50,
                buttons: [
                {
                    onPress: () => setVisible(),
                    title: "Aceptar",
                    style: { buttonColor: "#2AAF73", textColor: "white" },
                },
            ],
        },
    };
    
    return (
        <Alert isVisible={isVisible} setVisible={setVisible} {...alertConfig} />
    );
};

export default App;

Alert by user custom component

import { Alert } from "expo-alerts";
import React from "react";
import { Text, View, StyleSheet, Image } from "react-native";

const App = () => {
    // Handler
    const [visible, setVisible] = useState()
    return (
        <Alert isVisible={isVisible} setVisible={setVisible}>
          // Children
        </Alert>
    );
};

Toast Notification

import { Alert } from "expo-alerts";
import React from "react";
import { Text, View, StyleSheet, Image } from "react-native";

const App = () => {
    // Handler
    const [visible, setVisible] = useState()
    
    // Toast configuration
    const configuration = {
        position: "bottom",
        bottomPosition: 20,
        customStyle: {
            titleSize: 16,
            bodySize: 16,
            backgroundColor: "#2AAF73",
            titleColor: "white",
            bodyColor: "white",
        },
        timeout: 3000,
        title: "Timeout Toast",
        body: "This toast will be visible for 3 seconds",
    };
    
    return (
        <Toast
            visible={toast === "Toast"}
            setVisible={setToast}
            config={configuration}
        />
    );
};

Documentation:

Alert Component

Alert component that will show data, actions, images...

NameDescriptionRequiredDefaultType
alertStyleThe custom style for the Alert component.Object
actionsAn array containing information about the Alert's actions.Array
iconThe icon to display in the Alert component.React Node
timeoutThe timeout in milliseconds for the Alert component.Number
onHideThe function to call when the Alert component is hidden.() => {}Function
isVisibleWhether the Alert component is visible or not.Boolean
setVisibleThe function to call to set the visibility of the Alert component.Function
titleThe title text for the Alert component.String
bodyThe body text for the Alert component.String
childrenAny child components to render inside the Alert component.React Node

AlertStyle

NameDescriptionRequiredDefaultType
radiusThe border radius of the Alert component.20Number
bgColorThe background color of the Alert component."white"String
titleColorThe color of the title text in the Alert component."black"String
titleSizeThe font size of the title text in the Alert component.20Number
bodySizeThe font size of the body text in the Alert component.14Number
bodyColorThe color of the body text in the Alert component."black"String
familyThe font family to use for the Alert component.String
paddingThe padding around the Alert component.1Number
widthThe width of the Alert component."100%"String
heightThe height of the Alert component."auto"String
maxWidthThe maximum width of the Alert component.350Number
maxHeightThe maximum height of the Alert component.Number
textAlignThe text alignment in the Alert component."center"String
gapThe gap between the Alert component and its container.20Number

AlertActions

NameDescriptionRequiredDefaultType
directionThe direction of the inline buttons. Either "row" or "column"."row"String
gapThe gap between the inline buttons.5Number
radiusThe radius of the inline buttons.10Number
buttonsAn array containing information about the inline buttons.Array

AlertButtons

NameDescriptionRequiredDefaultType
onPressThe function to call when the button is pressed.() => {}Function
titleThe text to display on the button.""String
styleThe style for the button.{ buttonColor: "", textColor: "" }Object

Toast Component

A Toast component displays a brief message to the user.

NameDescriptionRequiredDefaultType
positionThe position of the Toast component on the screen."top"String
customStyleThe custom style for the Toast component.Object
timeoutThe timeout in milliseconds for the Toast component.falseBoolean or Number
titleThe title text for the Toast component.String
bodyThe body text for the Toast component.String
bottomPositionThe distance in pixels from the bottom of the screen for a bottom-positioned Tost.60Number
topPositionThe distance in pixels from the top of the screen for a top-positioned Toast.60Number
iconThe icon to display in the Toast component.React Node
heightThe height of the Toast component.60Number
actionThe function to call when an action is triggered in the Toast component.() => {}Function

ToastStyle

NameDescriptionRequireDefaultType
titleSizeThe font size of the title text in the Alert.16Number
bodySizeThe font size of the body text in the Alert.16Number
backgroundColorThe background color of the Alert.#2AAF73String
titleColorThe color of the title text in the Alert.whiteString
bodyColorThe color of the body text in the Alert.whiteString

Author

Eloy Gómez García | https://eloygomez.net.com

License

MIT