Git Product home page Git Product logo

react-native-in-app-notification's Introduction

react-native-in-app-notification npm version

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

Contents

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

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

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
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 four props:

Prop Name Prop Description Data Type
title The title passed to NotificationRef.show String
message The message passed to NotificationRef.show String
onPress The callback passed to NotificationRef.show Function
onClose A function to close the Notification prematurely Function

Usage

Adding react-native-in-app-notification is simple; just import the component and add it to the bottom of your component tree. Then create a ref to the component using ref={(ref) => { this.notification = ref; }} as a prop.

When you want to show the notification, just call .show on the ref you made earlier. .show can take three arguments: title, message and onPress all of which are optional - but 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.

Example

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

class MyApp extends Component {
  render() {
    <View>
      <Text>This is my app</Text>
      <TouchableHighlight
        onPress={this.notification && this.notification.show(
          'You pressed it!',
          'The notification has been triggered',
          () => Alert.alert('Alert', 'You clicked the notification!'),
        )}
      >
        <Text>Click me to trigger a notification</Text>
      </TouchableHighlight>
      <Notification ref={(ref) => { this.notification = ref; }} />
    </View>
  }
}

react-native-in-app-notification's People

Contributors

jwhscholten avatar robcalcroft avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.