forked from KhalisFoundation/sundar-gutka-react
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
100 lines (90 loc) · 3.1 KB
/
Copy pathapp.js
File metadata and controls
100 lines (90 loc) · 3.1 KB
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
import React, { useEffect } from "react";
import { AppState } from "react-native";
import ErrorBoundary from "react-native-error-boundary";
import { SafeAreaProvider } from "react-native-safe-area-context";
import SplashScreen from "react-native-splash-screen";
import Toast from "react-native-toast-message";
import toastConfig from "./src/common/toastConfig";
import { Provider } from "react-redux";
import notifee, { EventType } from "@notifee/react-native";
import { PersistGate } from "redux-persist/integration/react";
import {
createStore,
STRINGS,
logError,
initializeCrashlytics,
FallBack,
resetBadgeCount,
navigateTo,
} from "@common";
import ThemeProvider from "./src/common/context/ThemeProvider";
import { TrackPlayerSetup } from "./src/common/TrackPlayerUtils";
import Navigation from "./src/navigation";
const { store, persistor } = createStore();
/**
* After redux-persist rehydrates the store, sync the localization library
* with the persisted language. Without this, STRINGS stays on the default
* locale (English) because redux-persist's REHYDRATE action does not
* trigger the setLanguage action creator where STRINGS.setLanguage() lives.
*/
const handleBeforeLift = () => {
const { language } = store.getState();
if (language) {
STRINGS.setLanguage(language);
}
};
const App = () => {
useEffect(() => {
// Code to run on component mount
SplashScreen.hide(); // Hide the splash screen once everything is loaded
}, []); // The empty array causes this effect to only run on mount
useEffect(() => {
const runSetup = async () => {
await initializeCrashlytics();
await TrackPlayerSetup();
};
// Guard against OS-initiated background cold starts (service revival, FCM,
// Bluetooth events). startForeground() is blocked in background-restricted
// states on Android 12+, so we must not call setupPlayer() until the app is
// actually in the foreground. On a normal launcher tap AppState is already
// 'active' and we run immediately with no overhead.
if (AppState.currentState !== "active") {
const sub = AppState.addEventListener("change", (state) => {
if (state === "active") {
sub.remove();
runSetup().catch(logError);
}
});
return () => sub.remove();
}
runSetup().catch(logError);
}, []);
useEffect(() => {
const unsubscribe = notifee.onForegroundEvent(async ({ type, detail }) => {
resetBadgeCount();
if (type === EventType.PRESS) {
try {
await navigateTo(detail);
} catch (error) {
logError(error);
}
}
});
return unsubscribe;
}, []);
return (
<Provider store={store}>
<PersistGate loading={null} persistor={persistor} onBeforeLift={handleBeforeLift}>
<ThemeProvider>
<ErrorBoundary onError={logError} FallbackComponent={FallBack}>
<SafeAreaProvider>
<Navigation />
<Toast config={toastConfig} />
</SafeAreaProvider>
</ErrorBoundary>
</ThemeProvider>
</PersistGate>
</Provider>
);
};
export default App;