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>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -1,17 +1,23 @@
|
||||
import Styles from "@/constants/Styles";
|
||||
import { Pressable, View } from "react-native";
|
||||
import { Pressable, Text, View } from "react-native";
|
||||
|
||||
type PropsBtnHeader = {
|
||||
onPress: () => void;
|
||||
item: React.ReactNode;
|
||||
valueTop?: boolean;
|
||||
};
|
||||
|
||||
export function ButtonHeader({ onPress, item }: PropsBtnHeader) {
|
||||
export function ButtonHeader({ onPress, item, valueTop }: PropsBtnHeader) {
|
||||
return (
|
||||
<Pressable onPress={() => { onPress() }}>
|
||||
<View style={[Styles.btnIconHeader]}>
|
||||
{item}
|
||||
</View>
|
||||
{
|
||||
valueTop != undefined && valueTop && (
|
||||
<View style={{ position: 'absolute', top: 0, right: 0, backgroundColor: 'red', width: 10, height: 10, borderRadius: 100 }}> </View>
|
||||
)
|
||||
}
|
||||
</Pressable>
|
||||
)
|
||||
}
|
||||
@@ -32,7 +32,6 @@ export async function registerForPushNotificationsAsync() {
|
||||
|
||||
try {
|
||||
const pushTokenString = (await Notifications.getExpoPushTokenAsync({ projectId })).data
|
||||
console.log(pushTokenString)
|
||||
return pushTokenString
|
||||
} catch (error) {
|
||||
throw new Error(`Error getting push token: ${error}`)
|
||||
|
||||
Reference in New Issue
Block a user