All Projects → lucasferreira → React Native Flash Message

lucasferreira / React Native Flash Message

Licence: mit
React Native flashbar and top notification alert utility

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to React Native Flash Message

Expanding Collection
ExpandingCollection is an animated material design UI card peek/pop controller. iOS library made by @Ramotion
Stars: ✭ 5,456 (+591.51%)
Mutual labels:  component
Arkit
JavaScript architecture diagrams and dependency graphs
Stars: ✭ 671 (-14.96%)
Mutual labels:  component
Vue.d3.tree
Vue component to display tree based on D3.js layout.
Stars: ✭ 726 (-7.98%)
Mutual labels:  component
Polyfill Apcu
This component provides apcu_* functions and the APCUIterator class to users of the legacy APC extension.
Stars: ✭ 629 (-20.28%)
Mutual labels:  component
Insignia
🔖 Customizable tag input. Progressive. No non-sense!
Stars: ✭ 665 (-15.72%)
Mutual labels:  component
Vue Typer
Vue component that simulates a user typing, selecting, and erasing text.
Stars: ✭ 691 (-12.42%)
Mutual labels:  component
React Native Snackbar
🍱 Material Design "Snackbar" component for Android and iOS.
Stars: ✭ 613 (-22.31%)
Mutual labels:  component
Multityperecyclerviewadapter
一个专注于RecyclerView优雅刷新(接管资源和数据源)、高灵活、低耦合、健壮性以及高效性的MVP模式库,支持大多数Adapter
Stars: ✭ 763 (-3.3%)
Mutual labels:  component
Jkanban
Vanilla Javascript plugin for manage kanban boards
Stars: ✭ 664 (-15.84%)
Mutual labels:  component
React Native Star Rating
A React Native component for generating and displaying interactive star ratings
Stars: ✭ 724 (-8.24%)
Mutual labels:  component
React Notification
Provides snackbar notifications for React
Stars: ✭ 652 (-17.36%)
Mutual labels:  component
React Fontawesome
A React Font Awesome component.
Stars: ✭ 662 (-16.1%)
Mutual labels:  component
Polyfill Intl Grapheme
This component provides a partial, native PHP implementation of the Grapheme functions from the Intl extension.
Stars: ✭ 690 (-12.55%)
Mutual labels:  component
Taskscheduler
Provides a .NET wrapper for the Windows Task Scheduler. It aggregates the multiple versions, provides an editor and allows for localization.
Stars: ✭ 628 (-20.41%)
Mutual labels:  component
Translation
The Translation component provides tools to internationalize your application.
Stars: ✭ 6,196 (+685.3%)
Mutual labels:  component
Vue Tabs Component
An easy way to display tabs with Vue
Stars: ✭ 616 (-21.93%)
Mutual labels:  component
Vue Multiselect
Universal select/multiselect/tagging component for Vue.js
Stars: ✭ 5,988 (+658.94%)
Mutual labels:  component
Orbit
React components of open-source Orbit design system by Kiwi.com
Stars: ✭ 774 (-1.9%)
Mutual labels:  component
Reactprimer
React component prototyping tool that generates fully connected class component code.
Stars: ✭ 743 (-5.83%)
Mutual labels:  component
String
Provides an object-oriented API to strings and deals with bytes, UTF-8 code points and grapheme clusters in a unified way.
Stars: ✭ 709 (-10.14%)
Mutual labels:  component

react-native-flash-message

Flash Message it is a React Native module to help you with easily and highly customizable flashbars, top notifications or alerts (with iPhone X, XR, XS and XS Max "notch" support).

Global Demo of Flash Message Component

npm version npm downloads npm licence help this project

Installation

Since the library is a JS-based solution, to install the latest version of react-native-flash-message you only need to run:

npm install --save react-native-flash-message

or

yarn add react-native-flash-message

Try it out

You can try out the Flash Message Playground app to get a tease of the functionalities of this lib.

Basic Usage

The FlashMessage component it's build to a global use, so you have to instance this component once in your main app screen always as a last inserted component:

import React from "react";
import { View } from "react-native";
import FlashMessage from "react-native-flash-message";

export default class App extends React.Component {
  render() {
    return (
      <View style={{ flex: 1 }}>
        <View ref={"otherView1"} />
        <View ref={"otherView2"} />
        <View ref={"otherView3"} />
        {/* GLOBAL FLASH MESSAGE COMPONENT INSTANCE */}
        <FlashMessage position="top" /> {/* <--- here as last component */}
      </View>
    );
  }
}

After that you only need to call showMessage or hideMessage methods from anywhere in your app.

If you don't need a global use for (e.g. will use only in one screen) you can instance your FlashMessage Component with a ref ID (or other capture ref method):

<View style={{ flex: 1 }}>
  <YourMainApp />
  <FlashMessage ref="myLocalFlashMessage" />   {/* <--- here as last component always with `ref` */}
<View>

Show some message

Now that you already instantiated the global FlashMessage component, when you need to show some message in your app you could use the showMessage method in any screen or view. This is a global method that receive a message object with your message detail:

import React from "react";
import { View, Button } from "react-native";

import { showMessage, hideMessage } from "react-native-flash-message";

class MyScreen extends React.Component {
  render() {
    return (
      <View style={{ flex: 1 }}>
        <Button
          onPress={() => {
            /* HERE WE GONE SHOW OUR FIRST MESSAGE */
            showMessage({
              message: "Simple message",
              type: "info",
            });
          }}
          title="Request Details"
          color="#841584"
        />
      </View>
    );
  }
}

The message object obligatorily requires some message attribute. If you need to show a message with two lines (title and more details) you could use message attr for title and description attr for details line:

showMessage({
  message: "Hello World",
  description: "This is our second message",
  type: "success",
});

The type attribute set the type and color of your flash message, default options are "success" (green), "warning" (orange), "danger" (red), "info" (blue) and "default" (gray).

By default all of the messages will be displayed with transitions and with autoHide after 1850 ms enabled. If you need to programmatically hide some message, you can call hideMessage() .

Other message object attributes will be detailed below.

Props

Property Default In Message Object Description
hideOnPress true Yes Controls if the flash message can be closed on press
onPress none Yes onPress callback for flash message press
onLongPress none Yes onLongPress callback for flash message press
animated true Yes Controls if the flash message will be shown with animation or not
animationDuration 225 Yes Animations duration/speed
autoHide true Yes Controls if the flash message can hide itself after some duration time
duration 1850 Yes How many milliseconds the flash message will be shown if the autoHide it's true
hideStatusBar false Yes Controls if the flash message will auto hide the native status bar. Note: Works OK in iOS, not all Android versions support this.
statusBarHeight none Yes Use this prop to set a custom status bar height that will be add in flash message padding top calc
floating false Yes The floating prop unstick the message from the edges and applying some border radius to component
position top Yes The position prop set the position of a flash message. Expected options: "top" (default), "bottom", "center" or a custom object with { top, left, right, bottom } position
icon none Yes The icon prop set the graphical icon of a flash message. Expected options: "none" (default), "auto" (guided by type), "success", "info", "warning", "danger" or a custom object with icon type/name and position (left or right) attributes, e.g.: { icon: "success", position: "right" }
style none Yes Apply a custom style object in flash message container
textStyle none Yes Apply a custom style object in flash message descript/text text label
titleStyle none Yes Apply a custom style object in flash message title text label
titleProps none Yes Set a custom props object in flash message title text label
textProps none Yes Set a custom props object in flash message all text components
renderCustomContent none Yes Render custom JSX below title in flash message.
renderFlashMessageIcon renderFlashMessageIcon Yes Set a custom render function for inside message icons
transitionConfig FlashMessageTransition No Set the transition config function used in shown/hide anim interpolations
canRegisterAsDefault true No Use to handle if the instance can be registed as default/global instance
MessageComponent DefaultFlash No Set the default flash message render component used to show all the messages

Message Object

When you call showMessage method you need pass a message object to show your message. In this call you could pass some custom attributes to customize your message. Most of the FlashMessage Component props can be passed in runtime calls of showMessage. This common props/attributes are identified in Props table as In Message Object.

If you need to customize de background color or text color of your message beyond the default types (success, warning, info and danger) you could use the backgroundColor or/and color attributes in your message object:

showMessage({
  message: "My message title",
  description: "My message description",
  type: "default",
  backgroundColor: "purple", // background color
  color: "#606060", // text color
});

If you need to handle the press/touch event in your message, you could use the onPress attribute to take some action:

showMessage({
  message: "My message title",
  description: "My message description",
  type: "success",
  onPress: () => {
    /* THIS FUNC/CB WILL BE CALLED AFTER MESSAGE PRESS */
  },
});

iPhone X

The main MessageComponent (responsible for render the messages) it's DefaultFlash. This component it's wrapped in other component called FlashMessageWrapper that handles device orientations, statusbar heights and principal wheater or not include the iPhone X "noch" inset padding:

iPhone X

iPhone X Landscape

Documentation

More details and usages will coming soon.

Donation

If this project help you reduce time to develop, you can give me a cup of coffee :)

paypal

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].