0.0.1-beta.1 • Published 3 months ago

@janiscommerce/app-push-notification v0.0.1-beta.1

Weekly downloads
-
License
ISC
Repository
github
Last release
3 months ago

@janiscommerce/app-push-notification

janis-logo

Library for receiving notifications issued from firebase/janis.

PeerDependencies installation:

In order to receive notifications it is necessary to include the dependency

    npm install @react-native-firebase/messaging

Installation:

    npm install @janis-commerce/app-push-notification

What is received from firebase?

What is received is an object called RemoteMessage, which contains the data emitted from Firebase and is what triggers the notification listeners. Inside remoteMessage you get the notifications object that contains the information that we could use to render a component with the application in the foreground

For more information about this, read https://rnfirebase.io/reference/messaging/remotemessage

This library provides the following components and methods:

Functions

useNotification() ⇒ object

is a hook, which returns the elements contained within the notifications context. Returns an object containing: | name | description | |----------|----------| | deviceToken | is the token linked to the device, which we use to subscribe it to notifications. |

Kind: global function
Example

import {useNotification} from '@janiscommerce/app-push-notification'

const {} = useNotification()

NotificationProvider(children, foregroundCallback, backgroundCallback, config, events, environment) ⇒ null | React.element

It is the main component of the package, it is a HOC that is responsible for handling the logic of subscribing to notifications and receiving messages from the Firebase console. The HOC contains listeners to listen to notifications in the foreground and background, so (unless we cancel the subscription), we will receive notifications from the app even when it is closed.

Kind: global function
Throws:

  • null when not receive a children argument
ParamTypeDescription
childrenReact.elementComponent that will be rendered within the HOC, and about which the notification will be displayed
foregroundCallbackfunctionfunction that will be executed when a foreground notification is received.
backgroundCallbackfunctionfunction that will be executed when a background notification is received.
configobjectIt is an object that contains the user's data, which will be used to subscribe the user to notifications.
config.appNamestringname of the aplication
config.accessTokenstringaccessToken provided by janis
config.clientstringclient provided by janis
eventsArray.<string>is an array that will contain the events to which the user wants to subscribe
environmentstringThe environment is necessary for the API that we are going to use to subscribe the device to notifications.

Example

import NotificationProvider from '@janiscommerce/app-push-notification'


//...

const foregroundCallback = (remoteMessage) => console.log('a new FCM:',remoteMessage)
const backgrounCallback = (remoteMessage) => {
 console.log('a new FCM was received in background', remoteMessage)
}

return (
 <NotificationProvider 
   foregroundCallback={foregroundCallback}
   backgroundCallback={backgroundCallback}
   config={client:'fizzmod', accessToken:'access_token_push', appName:'janisAppName'}
   events={['Notification','events','janis']}
   environment='beta'
   >
   <MyComponent/>
 </NotificationProvider>
)