0.1.7 • Published 1 year ago

@buildersbank/use-notifications v0.1.7

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

Build Status codecov npm MIT

@buildersbank/use-notification

Wrapping up @react-native-firebase/messaging and @notifee/react-native as a hook for simpler usage.

Install

yarn add @react-native-firebase/messaging @react-native-firebase/app @notifee/react-native @buildersbank/use-notifications

then, navigate to cd ios and run pod install

Usage to configure

import { useNotifications } from '@buildersbank/use-notifications';

const { configureNotifications, getFCMToken } = useNotifications();

const onRegisterNotification = async (token) => {
  console.log('LOG: onRegisterNotification -> token', token);
};

const onReceiveNotification = (notification) => {
  console.log('LOG: onNotification -> notification', notification);
};

const onOpenNotification = (notification) => {
  console.log('LOG: onOpenNotification -> notification', notification);
};

const onTokenRefresh = (token) => {
  console.log('LOG: onTokenRefresh -> token', token);
};

const getFirebaseToken = async () => {
  const fcmToken = await getFCMToken();
  console.log('LOG: getFirebaseToken -> fcmToken', fcmToken);
};

useEffect(() => {
  configureNotifications({
    onRegister: onRegisterNotification,
    onNotification: onReceiveNotification,
    onNotificationOpened: onOpenNotification, // iOS
    onTokenRefresh: onTokenRefresh
  });
}, []);

Usage to display notifications

import { useNotifications } from '@buildersbank/use-notifications';

const { displayNotification } = useNotifications();

useEffect(() => {
  displayNotification({
    title: 'Bem vindo ao App',
    body: 'Faça login para continuar',
  });
}, []);

New Version

0.1.7

1 year ago