-
Notifications
You must be signed in to change notification settings - Fork 9
/
App.js
88 lines (81 loc) · 3.38 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
import { BackHandler, Alert, AppRegistry, AppState } from "react-native";
import { NavigationContainer } from "@react-navigation/native";
import { createNativeStackNavigator } from "@react-navigation/native-stack";
import { Provider } from "react-redux";
import { PersistGate } from "redux-persist/integration/react";
import * as React from "react";
import HomeScreen from "./screens/Home";
import FolderBaniScreen from "./screens/FolderBani";
import SettingsScreen from "./screens/Settings";
import EditBaniOrderScreen from "./screens/EditBaniOrder";
import ReminderOptionsScreen from "./screens/ReminderOptions";
import AboutScreen from "./screens/About";
import ReaderScreen from "./screens/Reader";
import BookmarksScreen from "./screens/Bookmarks";
import createStore from "./config/store";
import FirebaseNotification from "./utils/firebaseNotification";
import NotificationsManager from "./utils/notifications";
const Stack = createNativeStackNavigator();
const { store, persistor } = createStore();
export default class App extends React.Component {
componentDidMount() {
this.notificationHandler();
BackHandler.addEventListener("hardwareBackPress", this.handleBackPress);
// AppStateIOS.addEventListener("change", (state) => console.log("AppStateIOS changed to", state));
AppState.addEventListener("change", (state) => {
if (state === "active") {
const notification = new NotificationsManager();
notification.resetBadgeCount();
}
});
}
componentWillUnmount() {
BackHandler.removeEventListener("hardwareBackPress", this.handleBackPress);
}
handleBackPress = () => {
Alert.alert(
"Exit Sundar Gutka",
"Are you sure you want to exit?",
[{ text: "Cancel" }, { text: "Exit", onPress: () => BackHandler.exitApp() }],
{ cancelable: true }
);
return true;
};
notificationHandler = () => {
const firebaseNotifaction = new FirebaseNotification();
firebaseNotifaction.checkPermission();
firebaseNotifaction.backgroundMessageHandler();
firebaseNotifaction.foregroundMessage();
firebaseNotifaction.handleNotification();
const notification = new NotificationsManager();
notification.listenReminders();
// notification.listenReminders();
};
render() {
const notification = new NotificationsManager();
notification.resetBadgeCount();
return (
<Provider store={store}>
<PersistGate loading={null} persistor={persistor}>
<NavigationContainer>
<Stack.Navigator
screenOptions={{
headerShown: false,
}}
>
<Stack.Screen name="Home" component={HomeScreen} />
<Stack.Screen name="FolderBani" component={FolderBaniScreen} />
<Stack.Screen name="Settings" component={SettingsScreen} />
<Stack.Screen name="Reader" component={ReaderScreen} />
<Stack.Screen name="Bookmarks" component={BookmarksScreen} />
<Stack.Screen name="EditBaniOrder" component={EditBaniOrderScreen} />
<Stack.Screen name="ReminderOptions" component={ReminderOptionsScreen} />
<Stack.Screen name="About" component={AboutScreen} />
</Stack.Navigator>
</NavigationContainer>
</PersistGate>
</Provider>
);
}
}
AppRegistry.registerHeadlessTask("RNFirebaseMessagingService", () => this.notificationHandler);