upd: notification
This commit is contained in:
@@ -11,7 +11,7 @@ import { Headers } from "@/constants/Headers";
|
||||
import store from "@/lib/store";
|
||||
import { useAuthSession } from "@/providers/AuthProvider";
|
||||
import messaging from "@react-native-firebase/messaging";
|
||||
import { Redirect, router, Stack } from "expo-router";
|
||||
import { Redirect, router, Stack, usePathname } from "expo-router";
|
||||
import { StatusBar } from 'expo-status-bar';
|
||||
import { useEffect } from "react";
|
||||
import { Text } from "react-native";
|
||||
@@ -19,18 +19,50 @@ import { Easing, Notifier } from 'react-native-notifier';
|
||||
import { Provider } from "react-redux";
|
||||
|
||||
export default function RootLayout() {
|
||||
const pathname = usePathname();
|
||||
|
||||
const handleNotificationPress = (category: any, content: any) => {
|
||||
switch (category) {
|
||||
case 'announcement':
|
||||
router.push(`/announcement/${content}`);
|
||||
break;
|
||||
case 'discussion':
|
||||
router.push(`/discussion/${content}`);
|
||||
break;
|
||||
case 'division':
|
||||
router.push(`/division/${content}`);
|
||||
break;
|
||||
case 'member':
|
||||
router.push(`/member/${content}`);
|
||||
break;
|
||||
case 'project':
|
||||
router.push(`/project/${content}`);
|
||||
break;
|
||||
case 'announcement':
|
||||
router.push(`/announcement/${content}`);
|
||||
break;
|
||||
// Add other cases as needed
|
||||
default:
|
||||
// Handle unknown category
|
||||
console.warn(`Unknown category: ${category}`);
|
||||
}
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
const unsubscribe = messaging().onMessage(async remoteMessage => {
|
||||
console.log('pesan', remoteMessage.data)
|
||||
Notifier.showNotification({
|
||||
title: remoteMessage.notification?.title,
|
||||
description: remoteMessage.notification?.body,
|
||||
duration: 5000,
|
||||
animationDuration: 500,
|
||||
showEasing: Easing.ease,
|
||||
onPress: () => router.push('/notification'),
|
||||
hideOnPress: false,
|
||||
});
|
||||
const category = remoteMessage?.data?.category;
|
||||
const content = remoteMessage?.data?.content;
|
||||
if (category != pathname.substring(1)) {
|
||||
Notifier.showNotification({
|
||||
title: remoteMessage.notification?.title,
|
||||
description: remoteMessage.notification?.body,
|
||||
duration: 3000,
|
||||
animationDuration: 300,
|
||||
showEasing: Easing.ease,
|
||||
onPress: () => handleNotificationPress(category, content),
|
||||
hideOnPress: true,
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
return unsubscribe;
|
||||
@@ -56,9 +88,6 @@ export default function RootLayout() {
|
||||
headerRight: () => <HeaderRightHome />,
|
||||
headerTitleAlign: 'left',
|
||||
headerBackVisible: false,
|
||||
contentStyle:{
|
||||
|
||||
}
|
||||
}} />
|
||||
<Stack.Screen name="feature" options={{ title: 'Fitur' }} />
|
||||
<Stack.Screen name="search" options={{ title: 'Pencarian' }} />
|
||||
@@ -110,7 +139,7 @@ export default function RootLayout() {
|
||||
}}
|
||||
/>
|
||||
</Stack>
|
||||
<StatusBar style="light" translucent={false} backgroundColor="black"/>
|
||||
<StatusBar style="light" translucent={false} backgroundColor="black" />
|
||||
</Provider>
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user