Add: - service/api-device-token.ts Fix: - app/(application)/(user)/home.tsx - app/(application)/(user)/test-notifications.tsx - app/_layout.tsx - components/_ShareComponent/NotificationInitializer.tsx - context/AuthContext.tsx - hooks/use-foreground-notifications.ts - screens/Home/HeaderBell.tsx - service/api-notifications.ts ### No Issue
27 lines
693 B
TypeScript
27 lines
693 B
TypeScript
import { useEffect } from "react";
|
|
import {
|
|
getMessaging,
|
|
onMessage,
|
|
FirebaseMessagingTypes,
|
|
} from "@react-native-firebase/messaging";
|
|
|
|
// Gunakan tipe resmi dari library
|
|
type RemoteMessage = FirebaseMessagingTypes.RemoteMessage;
|
|
|
|
export function useForegroundNotifications(
|
|
onMessageReceived: (message: RemoteMessage) => void
|
|
) {
|
|
useEffect(() => {
|
|
const messaging = getMessaging();
|
|
|
|
const unsubscribe = onMessage(messaging, (remoteMessage) => {
|
|
console.log(
|
|
"🔔 Notifikasi diterima saat app aktif:",
|
|
JSON.stringify(remoteMessage, null, 2)
|
|
);
|
|
onMessageReceived(remoteMessage);
|
|
});
|
|
|
|
return unsubscribe;
|
|
}, [onMessageReceived]);
|
|
} |