-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.js
131 lines (118 loc) · 4.23 KB
/
App.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
import React, { useRef, useEffect } from "react";
import { StyleSheet, Text, View, Vibration, LogBox } from "react-native";
import { NavigationContainer } from "@react-navigation/native";
import Main from "./Navigators/Main";
import Toast from "react-native-toast-message";
import store from "./Redux/store";
import { Provider } from "react-redux";
import { useFonts } from "expo-font";
import { toastConfig } from "./Shared/config";
import * as Notification from "expo-notifications";
import { navigationRef, isReadyRef } from "./RootNavigation";
// import * as Notifications from "expo-notifications";
import { Notifications } from "expo";
LogBox.ignoreAllLogs(true);
// import { navigationRef } from "./app/navigation/rootNavigation";
export default function App() {
// const navigationRef = React.createRef();
const responseListener = useRef();
const notificationListener = useRef();
const [loaded] = useFonts({
"EBGaramond-Bold": require("./assets/fonts/EBGaramond-ExtraBold.ttf"),
"EBGaramond-Regular": require("./assets/fonts/EBGaramond-Regular.ttf"),
"EBGaramond-Italic": require("./assets/fonts/EBGaramond-Italic.ttf"),
});
Notification.setNotificationHandler({
handleNotification: async () => ({
shouldShowAlert: true,
shouldPlaySound: false,
shouldSetBadge: false,
}),
});
console.error("HANDLING", isReadyRef.current, navigationRef.current);
const handleNotification = (notification) => {
Vibration.vibrate();
const { data } = notification;
// A simple example of passing data as the value
// of the screen you want the user to be navigated to
// when they click on a notification
// console.error("BACKEND", data, navigationRef.current?.getCurrentRoute());
// console.error(data.property, !navigationRef.current?.getCurrentRoute());
if (data?.property) {
// navigationRef.current?.navigate("Notifications", data);
// NEW
(async function schedulePushNotification() {
Notification.setNotificationHandler({
handleNotification: async () => ({
shouldShowAlert: true,
shouldPlaySound: false,
shouldSetBadge: false,
}),
});
const indentifier = await Notification.scheduleNotificationAsync({
content: {
title: "ICONIC properties",
body: "One of your subscribed location got new property ️🔥",
data: data,
},
trigger: { seconds: 2 },
});
// await Notification.cancelScheduledNotificationAsync(indentifier);
})();
responseListener.current =
Notification.addNotificationResponseReceivedListener((response) => {
console.error(
"REALESTATE",
response.notification.request.content.data,
navigationRef.current?.getCurrentRoute(),
navigationRef.current
);
// ZAHRA
// route you want to navigate to
console.log(
"TRY---------------------------------",
data,
navigationRef.current
);
navigationRef.current?.navigate("PropertiesPosts", {
id: data?.property,
});
});
}
};
React.useEffect(() => {
return () => {
isReadyRef.current = false;
};
}, []);
useEffect(() => {
// notificationListener.current =
// Notification.addNotificationReceivedListener(handleNotification);
// responseListener.current =
// Notification.addNotificationResponseReceivedListener(handleNotification);
const subscribe = Notifications.addListener(handleNotification);
return () => {
subscribe.remove();
// Notification.removeNotificationSubscription(notificationListener.current);
// Notification.removeNotificationSubscription(responseListener.current);
};
}, []);
if (!loaded) {
return null;
}
return (
<Provider store={store}>
<NavigationContainer
ref={navigationRef}
onReady={() => {
isReadyRef.current = true;
}}
>
{/* <DrawerNavigator /> */}
<Main />
<Toast config={toastConfig} ref={(ref) => Toast.setRef(ref)} />
</NavigationContainer>
</Provider>
);
}
const styles = StyleSheet.create({});