2020-06-16 20:32:30 +00:00
|
|
|
import React, { memo, useEffect } from 'react';
|
|
|
|
import { NotifierRoot, Notifier, Easing } from 'react-native-notifier';
|
|
|
|
|
|
|
|
import NotifierComponent from './NotifierComponent';
|
|
|
|
import EventEmitter from '../../utils/events';
|
|
|
|
import Navigation from '../../lib/Navigation';
|
|
|
|
import { getActiveRoute } from '../../utils/navigation';
|
|
|
|
|
|
|
|
export const INAPP_NOTIFICATION_EMITTER = 'NotificationInApp';
|
|
|
|
|
|
|
|
const InAppNotification = memo(() => {
|
|
|
|
const show = (notification) => {
|
|
|
|
const { payload } = notification;
|
2020-07-02 17:10:11 +00:00
|
|
|
const state = Navigation.navigationRef.current?.getRootState();
|
2020-06-16 20:32:30 +00:00
|
|
|
const route = getActiveRoute(state);
|
|
|
|
if (payload.rid) {
|
2020-07-29 21:04:04 +00:00
|
|
|
if ((route?.name === 'RoomView' && route.params?.rid === payload.rid) || route?.name === 'JitsiMeetView') {
|
2020-06-16 20:32:30 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
Notifier.showNotification({
|
|
|
|
showEasing: Easing.inOut(Easing.quad),
|
|
|
|
Component: NotifierComponent,
|
|
|
|
componentProps: {
|
|
|
|
notification
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
EventEmitter.addEventListener(INAPP_NOTIFICATION_EMITTER, show);
|
|
|
|
return () => {
|
|
|
|
EventEmitter.removeListener(INAPP_NOTIFICATION_EMITTER);
|
|
|
|
};
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
return <NotifierRoot />;
|
|
|
|
});
|
|
|
|
|
|
|
|
export default InAppNotification;
|