All Projects → seniv → React Native Notifier

seniv / React Native Notifier

Licence: mit
Fast and simple in-app notifications for React Native

Programming Languages

typescript
32286 projects

Projects that are alternatives of or similar to React Native Notifier

Fileboy
fileboy,文件变更监听通知工具,使用 Go 编写。Fileboy, File Change Monitoring Notification Tool, written with Go.
Stars: ✭ 345 (-32.62%)
Mutual labels:  notification
Tiramisu
Desktop notifications, the UNIX way
Stars: ✭ 400 (-21.87%)
Mutual labels:  notification
Sppermissions
Ask permissions with ready-use interface. You can check status permission and if it has been requested before. Support SwiftUI.
Stars: ✭ 4,701 (+818.16%)
Mutual labels:  notification
Wxpusher Client
微信消息实时推送服务[WxPusher],可以通过API实时给个人微信推送消息。wechat pusher.
Stars: ✭ 352 (-31.25%)
Mutual labels:  notification
Activity notification
Integrated user activity notifications for Ruby on Rails
Stars: ✭ 383 (-25.2%)
Mutual labels:  notification
Bangumi
💫 An unofficial bgm.tv app client for Android and iOS, built with React Native. 类似专门做ACG的豆瓣, 已适配 iOS/Android, mobile/Pad, light/dark theme, 并加入了很多独有的增强功能
Stars: ✭ 409 (-20.12%)
Mutual labels:  expo
Expo Netflix
Netflix UI Clone with React Native & Expo || web support => https://expo-netflix.vercel.app
Stars: ✭ 297 (-41.99%)
Mutual labels:  expo
Expo Server Sdk Node
Server-side library for working with Expo using Node.js
Stars: ✭ 463 (-9.57%)
Mutual labels:  expo
Firebase Instagram
📸 Instagram clone with Firebase Cloud Firestore, Expo, and React Native 😁😍
Stars: ✭ 389 (-24.02%)
Mutual labels:  expo
React Native Pull Refresh
Custom pull to refresh component for Android
Stars: ✭ 456 (-10.94%)
Mutual labels:  expo
React Native Dating App
Dating app - Exponent and React Native
Stars: ✭ 352 (-31.25%)
Mutual labels:  expo
Qteventbus
iOS事件总线,支持AppDelegate解耦,支持基于响应链的局部总线
Stars: ✭ 365 (-28.71%)
Mutual labels:  notification
React Native Svg Animated Linear Gradient
A wrap SVG component for animated linear gradient
Stars: ✭ 418 (-18.36%)
Mutual labels:  expo
Notifier
Sends notifications via one or more channels (email, SMS, ...).
Stars: ✭ 346 (-32.42%)
Mutual labels:  notification
Monitor Table Change With Sqltabledependency
Get SQL Server notification on record table change
Stars: ✭ 459 (-10.35%)
Mutual labels:  notification
Notifications
NotifyMe enables you to create web notifications pretty easily - "Just Call me and Launch!!"
Stars: ✭ 327 (-36.13%)
Mutual labels:  notification
React Native Version
🔢 Version your React Native or Expo app in a `npm version` fashion.
Stars: ✭ 408 (-20.31%)
Mutual labels:  expo
Exp
Stars: ✭ 475 (-7.23%)
Mutual labels:  expo
React Cool Portal
😎 🍒 React hook for Portals, which renders modals, dropdowns, tooltips etc. to <body> or else.
Stars: ✭ 458 (-10.55%)
Mutual labels:  notification
Expo Three
Utilities for using THREE.js on Expo
Stars: ✭ 432 (-15.62%)
Mutual labels:  expo

react-native-notifier

npm npm bundle size platforms: ios, android, web license MIT

Fast and simple in-app notifications for React Native

Demo of package

Requirements

This library uses react-native-gesture-handler, a perfect library for swipes, and other gesture events.

If you are using react-navigation then you already have gesture-handler installed. If you don't, check Getting Started guide to install it: https://software-mansion.github.io/react-native-gesture-handler/docs/getting-started.html

Installation

yarn add react-native-notifier

Or

npm install --save react-native-notifier

Usage

Wrap your app with NotifierWrapper

import { NotifierWrapper } from 'react-native-notifier';

const App = () => (
  <NotifierWrapper>
    <Navigation />
  </NotifierWrapper>
);

Then call Notifier.showNotification() anywhere in code

import { Notifier, Easing } from 'react-native-notifier';

Notifier.showNotification({
  title: 'John Doe',
  description: 'Hello! Can you help me with notifications?',
  duration: 0,
  showAnimationDuration: 800,
  showEasing: Easing.bounce,
  onHidden: () => console.log('Hidden'),
  onPress: () => console.log('Press'),
  hideOnPress: false,
});

Or add NotifierRoot at end of your App.js component. With this approach you can show notification using reference to the NotifierRoot.

Note that NotifierRoot should be the last component to display notifications correctly. Notifier.showNotification is also available.

import { NotifierRoot } from 'react-native-notifier';

function App() {
  const notifierRef = useRef();
  return (
    <>
      <Button
        title="Show Notification"
        onPress={() => notifierRef.current?.showNotification({ title: 'Using refs' })}
      />
      <NotifierRoot ref={notifierRef} />
    </>
  );
}

All props passed to NotifierWrapper or NotifierRoot will be used as default params of showNotification function. This can be useful to set default Component param.

API

showNotification

Notifier.showNotification(params: object);

Show notification with params.

params

Name Type Default Description
title String null Title of notification. Passed to Component.
description String null Description of notification. Passed to Component.
duration Number 3000 Time after notification will disappear. Set to 0 to not hide notification automatically
Component Component NotifierComponents.Notification Component of the notification body. You can use one of the built-in components, or your custom component.
componentProps Object {} Additional props that are passed to Component. See all available props of built-in components in the components section.
queueMode String 'reset' Determines the order in which notifications are shown. Read more in the Queue Mode section.
swipeEnabled Boolean true Can notification be hidden by swiping it out
animationDuration Number 300 How fast notification will appear/disappear
showAnimationDuration Number animationDuration || 300 How fast notification will appear.
hideAnimationDuration Number animationDuration || 300 How fast notification will disappear.
easing Easing null Animation easing. Details: https://reactnative.dev/docs/easing
showEasing Easing easing || null Show Animation easing.
hideEasing Easing easing || null Hide Animation easing.
onStartHiding () => void null Function called when notification started hiding
onHidden () => void null Function called when notification completely hidden
onPress () => void null Function called when user press on notification
hideOnPress Boolean true Should notification hide when user press on it
swipePixelsToClose Number 20 How many pixels user should swipe-up notification to dismiss it
swipeEasing Easing null Animation easing after user finished swiping
swipeAnimationDuration Number 200 How fast should be animation after user finished swiping

hideNotification

Notifier.hideNotification(onHiddenCallback?: (result: Animated.EndResult) => void);

Hide notification and run callback function when notification completely hidden.

clearQueue

Notifier.clearQueue(hideDisplayedNotification?: boolean);

Clear notifications queue and optionally hide currently displayed notification. Might be useful to run after logout, after which queued notifications should not be displayed.

Queue Mode

Queue mode is used to define the order in which the notification appears in case other notifications are being displayed at the moment.

For example, if you have some important information like chat messages and you want the user to see all the notifications, then you can use standby mode. Or if you want to display something like an error message, then you can use reset mode.

By default, reset mode is used, which means every new notification clears the queue and gets displayed immediately.

In most cases, you will probably use only reset or standby modes.

All possible modes: Mode | Effect -----------|--------- reset | Clear notification queue and immediately display the new notification. Used by default. standby | Add notification to the end of the queue. next | Put notification in the first place in the queue. Will be shown right after the current notification disappears. immediate | Similar to next, but also it will hide currently displayed notification.

Components

Currently, there are 2 components out of the box. If none of them fits your needs, then you can easily create your Custom Component.

NotifierComponents.Notification

Demo of Notification component

Perfect for something like chat messages and notifications like "Someone left a comment". This component is used by default.

import { Notifier, NotifierComponents } from 'react-native-notifier';

Notifier.showNotification({
  title: 'Check this image!',
  description: 'Cool, right?',
  Component: NotifierComponents.Notification,
  componentProps: {
    imageSource: require('./react.jpg'),
  },
});

Available params: Name | Type | Default | Description -----------------------------------|------------|--------------|------------- title | String | null | Title of notification. description | String | null | Description of notification. componentProps.titleStyle | TextStyle | null | The style to use for rendering title. componentProps.descriptionStyle | TextStyle | null | The style to use for rendering description. componentProps.imageSource | Object | null | Passed to <Image /> as source param. componentProps.imageStyle | ImageStyle | null | The style to use for rendering image. componentProps.containerStyle | ViewStyle | null | The style to use for notification container. componentProps.ContainerComponent | Component | SafeAreaView | A container of the component. Set it in case you use different SafeAreaView than the standard componentProps.maxTitleLines | number | null | The maximum number of lines to use for rendering title. componentProps.maxDescriptionLines | number | null | The maximum number of lines to use for rendering description.

NotifierComponents.Alert

Demo of Alert component

Perfect to use as a system alerts, like "Something went wrong" or "Operation was succeed".

import { Notifier, NotifierComponents } from 'react-native-notifier';

Notifier.showNotification({
  title: 'The request was failed',
  description: 'Check your internet connection, please',
  Component: NotifierComponents.Alert,
  componentProps: {
    alertType: 'error',
  },
});

Available params: Name | Type | Default | Description -----------------------------------|-----------|--------------|------------- title | String | null | Title of notification. description | String | null | Description of notification. componentProps.titleStyle | TextStyle | null | The style to use for rendering title. componentProps.descriptionStyle | TextStyle | null | The style to use for rendering description. componentProps.alertType | String | 'success' | Background color will be changed depending on the type. Available values: error(red), success(green), warn(orange) and info(blue). componentProps.backgroundColor | String | null | While the background of the alert depends on alertType, you can also set the other color you want. componentProps.textColor | String | 'white' | Color of title and description. componentProps.ContainerComponent | Component | SafeAreaView | A container of the component. Set it in case you use different SafeAreaView than the standard componentProps.maxTitleLines | number | null | The maximum number of lines to use for rendering title. componentProps.maxDescriptionLines | number | null | The maximum number of lines to use for rendering description.

Custom Component

To customize look of the notification you can pass your own Component to showNotification function.

This makes customization much simpler than passing "style" params. With custom components you can make notification look exactly like you want.

This component will receive props title, description and anything else that you pass to componentProps object when calling showNotification.

Example

import React from 'react';
import { StyleSheet, View, Text, SafeAreaView } from 'react-native';

const styles = StyleSheet.create({
  safeArea: {
    backgroundColor: 'orange',
  },
  container: {
    padding: 20,
  },
  title: { color: 'white', fontWeight: 'bold' },
  description: { color: 'white' },
});

const CustomComponent = ({ title, description }) => (
  <SafeAreaView style={styles.safeArea}>
    <View style={styles.container}>
      <Text style={styles.title}>{title}</Text>
      <Text style={styles.description}>{description}</Text>
    </View>
  </SafeAreaView>
);

// ...

// Then show notification with the component

Notifier.showNotification({
  title: 'Custom',
  description: 'Example of custom component',
  Component: CustomComponent,
});

Demo of custom component

Using with react-native-navigation

If you are using react-native-navigation, this issue might be helpful to use notifier with native-navigation: https://github.com/seniv/react-native-notifier/issues/16

If you have any solutions or improvements in how to use notifier with native-navigation, then feel free to write comments in that thread!

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].