• Stars
    star
    270
  • Rank 152,189 (Top 3 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 7 years ago
  • Updated about 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

๐Ÿ”” Customisable in-app notification component for React Native

react-native-in-app-notification npm version

๐Ÿ”” Customisable in-app notification component for React Native

Contents

  1. UI
  2. Install
  3. Versions
  4. Props
  5. Usage

UI

The basic look of react-native-in-app-notification:

A GIF showing what react-native-in-app-notification can do

What you can make react-native-in-app-notification do with a customised component:

A GIF showing what react-native-in-app-notification can do

Install

yarn add react-native-in-app-notification

OR

npm install react-native-in-app-notification --save

Android

For Android you need to add the VIBRATE permission to your app AndroidManifest.xml

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="your.app.package.name">

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>

    <!-- Required by react-native-in-app-notification -->
    <uses-permission android:name="android.permission.VIBRATE" />

    ...
</manifest>

Versions

version RN
>=3.0.0 >= 0.54.0
<3.0.0 >= 0.43.4

Props

Prop Name Prop Description Data Type Required Default
closeInterval How long the notification stays visible Number No 4000
openCloseDuration The length of the open / close animation Number No 200
height The height of the Notification component Number No 80
backgroundColour The background colour of the Notification component String No white
iconApp App Icon ImageSourcePropType No null
notificationBodyComponent See below about NotificationBody React Node or Function Recommended ./DefaultNotificationBody

NotificationBody

The notification body is what is rendered inside the main Notification component and gives you the ability to customise how the notification looks. You can use the default notification body component in ./DefaultNotificationBody.js as inspiration and guidance.

Your notificationBodyComponent component is given five props:

Prop Name Prop Description Data Type Default
title The title passed to NotificationRef.show String ''
message The message passed to NotificationRef.show String ''
onPress The callback passed to NotificationRef.show Function null
icon Icon for notification passed to NotificationRef.show ImageSourcePropType null
vibrate Vibrate on show notification passed to NotificationRef.show Boolean true
additionalProps Any additional props passed to NotificationBodyComponent Object null

Usage

Adding react-native-in-app-notification is simple; Just wrap you main App component with the InAppNotificationProvider component exported from this module.

import { InAppNotificationProvider } from 'react-native-in-app-notification';

import App from './App.js';

class AppWithNotifications extends Component {
  render() {
    return (
      <InAppNotificationProvider>
        <App />
      </InAppNotificationProvider>
    );
  }
}

When you want to show the notification, just wrap the component which needs to display a notification with the withInAppNotification HOC and call the .showNotification methods from its props.

.showNotification can take four arguments (all of which are optional):

  • title
  • message
  • onPress
  • additionalProps

N.B: you should probably include at least one of title or message!

onPress doesn't need to be used for passive notifications and you can use onClose in your NotificationBody component to allow your users to close the notification.

additionalProps can be used to pass arbitory props to NotificationBody component. Can be accessed in NotificationBody component via props.additionalProps.

import React, { Component } from 'react';
import { View, Text, TouchableHighlight } from 'react-native';
import { withInAppNotification } from 'react-native-in-app-notification';

class MyApp extends Component {
  render() {
    return (
      <View>
        <Text>This is my app</Text>
        <TouchableHighlight
          onPress={() => {
            this.props.showNotification({
              title: 'You pressed it!',
              message: 'The notification has been triggered',
              onPress: () => Alert.alert('Alert', 'You clicked the notification!'),
              additionalProps: { type: 'error' },
            });
          }}
        >
          <Text>Click me to trigger a notification</Text>
        </TouchableHighlight>
      </View>
    );
  }
}

export default withInAppNotification(MyApp);

More Repositories

1

monzoweb

๐Ÿ’ฐ View your Monzo account from your browser and view all your transactions on an interactive map!
JavaScript
79
star
2

react-native-fade-in-view

๐ŸŽญ A simple and lightweight RN component that fades in its children
JavaScript
47
star
3

react-native-multiselect

โ˜‘๏ธ A simple RN component that allows row selection
JavaScript
19
star
4

react-use-infinite-loader

โ™พ๏ธ ๐Ÿ“ƒ โณ Super lightweight infinite loading hook for React apps
JavaScript
16
star
5

react-use-lazy-load-image

๐ŸŒ… โšก Add image lazy loading to your React app with ease
JavaScript
15
star
6

soundcloudr

๐Ÿ”‰ A node soundcloud downloader module
JavaScript
11
star
7

plex-webhook-recently-added

๐Ÿ”— Runs webhooks with recently added items from your Plex server
JavaScript
8
star
8

react-use-input

๐ŸŽฃ A hook whose setter can be directly given to HTML inputs
JavaScript
6
star
9

react-native-lightbox-zoom

๐Ÿ’ก ๐Ÿ”ณ ๐Ÿ”ญ React Native lightbox with pinch to zoom, pan, caption support and swipe to dismiss
JavaScript
3
star
10

reflect

๐Ÿ‘“
JavaScript
2
star
11

jquery-loadmask-plus

:shipit: A fork of jquery-loadmask which intends to modernise the look and feel of the original plugin by way of CSS updates and improved API usage.
JavaScript
2
star
12

roller-skating-ml

Python
1
star
13

dad

๐Ÿ‘จ A website for my granddad's son.
1
star
14

robcalcroft.com

โœ๏ธ ๐Ÿ“˜ My blog and homepage
CSS
1
star
15

robofive

An API for an Arduino using NodeJS & Johnny Five
JavaScript
1
star
16

cage

๐ŸŽƒ Cage-ify your life
JavaScript
1
star
17

watertracker

Track how many glasses of water you drink during the day
JavaScript
1
star
18

backchat

๐Ÿ‘‚ Backchat is a small Node.js proxy utility for recording HTTP traffic and replaying it when the same request is made in the future.
JavaScript
1
star