upd: push notification on background

Deskripsi:
- on klik pada background notification
- hide and show notificationn foreground

No Issues
This commit is contained in:
2025-08-07 16:25:45 +08:00
parent 9cb848ddd2
commit 7555ece0fa
6 changed files with 49 additions and 35 deletions

View File

@@ -25,10 +25,12 @@ export default function RootLayout() {
const { token, decryptToken, isLoading } = useAuthSession()
const pathname = usePathname()
async function handleReadNotification(id: string, category: string, idContent: string) {
async function handleReadNotification(id: string, category: string, idContent: string, title: string) {
try {
const hasil = await decryptToken(String(token?.current))
const response = await apiReadOneNotification({ user: hasil, id: id })
if (title != "Komentar Baru") {
const hasil = await decryptToken(String(token?.current))
const response = await apiReadOneNotification({ user: hasil, id: id })
}
pushToPage(category, idContent)
} catch (error) {
console.error(error)
@@ -53,26 +55,27 @@ export default function RootLayout() {
const id = remoteMessage?.data?.id;
const category = remoteMessage?.data?.category;
const content = remoteMessage?.data?.content;
if (
remoteMessage.notification != undefined &&
remoteMessage.notification.title != undefined &&
remoteMessage.notification.body != undefined &&
pathname != `/${category}/${content}`
) {
Notifier.showNotification({
title: remoteMessage.notification?.title,
description: remoteMessage.notification?.body,
duration: 3000,
animationDuration: 300,
showEasing: Easing.ease,
onPress: () => handleReadNotification(String(id), String(category), String(content)),
hideOnPress: true,
});
const title = remoteMessage?.notification?.title;
if (remoteMessage.notification != undefined && remoteMessage.notification.title != undefined && remoteMessage.notification.body != undefined) {
if (category == 'discussion-general' && pathname == '/discussion/' + content) {
return null
} else if (pathname != `/${category}/${content}`) {
Notifier.showNotification({
title: title,
description: remoteMessage.notification?.body,
duration: 3000,
animationDuration: 300,
showEasing: Easing.ease,
onPress: () => handleReadNotification(String(id), String(category), String(content), String(title)),
hideOnPress: true,
});
}
}
});
return unsubscribe;
}, []);
}, [pathname]);
if (isLoading) {

View File

@@ -4,9 +4,9 @@ import { Stack } from 'expo-router';
import * as SplashScreen from 'expo-splash-screen';
import { StatusBar } from 'expo-status-bar';
import { useEffect } from 'react';
import 'react-native-reanimated';
import { NotifierWrapper } from 'react-native-notifier';
import { GestureHandlerRootView } from 'react-native-gesture-handler';
import { NotifierWrapper } from 'react-native-notifier';
import 'react-native-reanimated';
// Prevent the splash screen from auto-hiding before asset loading is complete.
SplashScreen.preventAutoHideAsync();