147 lines
5.1 KiB
TypeScript
147 lines
5.1 KiB
TypeScript
import React from 'react';
|
|
import {
|
|
AppState,
|
|
KeyboardAvoidingView,
|
|
LogBox,
|
|
Permission,
|
|
PermissionsAndroid,
|
|
Platform,
|
|
StatusBar,
|
|
} from 'react-native';
|
|
import { Provider } from 'react-redux';
|
|
import store, { persistor } from './src/store/store';
|
|
import { PersistGate } from 'redux-persist/integration/react';
|
|
|
|
import { NavigationContainer } from '@react-navigation/native';
|
|
import { navigationRef } from './src/components/utlis/navigationUtlis';
|
|
import FullScreenLoader from './RN-UI-LIB/src/components/FullScreenLoader';
|
|
import ProtectedRouter from './ProtectedRouter';
|
|
import { toastConfigs, ToastContainer, } from './RN-UI-LIB/src/components/toast';
|
|
|
|
import * as Sentry from '@sentry/browser';
|
|
import { ENV, SENTRY_DSN } from './src/constants/config';
|
|
import useNativeButtons from './src/hooks/useNativeButton';
|
|
import { COLORS } from './RN-UI-LIB/src/styles/colors';
|
|
import codePush from 'react-native-code-push';
|
|
import AsyncStorage from '@react-native-async-storage/async-storage';
|
|
import { LocalStorageKeys, PermissionsToCheck } from './src/common/Constants';
|
|
import Permissions from './src/screens/permissions/Permissions';
|
|
import { setJsErrorHandler } from "./src/services/exception-handler.service";
|
|
import { TDocumentObj } from './src/screens/caseDetails/interface';
|
|
import SuspenseLoader from './RN-UI-LIB/src/components/suspense_loader/SuspenseLoader';
|
|
import ForceUninstallScreen from "./src/common/ForceUninstallScreen";
|
|
import ErrorBoundary from "./src/common/ErrorBoundary";
|
|
|
|
Sentry.init({ dsn: SENTRY_DSN });
|
|
|
|
if (ENV !== 'prod') {
|
|
// mockApiServer();
|
|
}
|
|
setJsErrorHandler();
|
|
LogBox.ignoreAllLogs();
|
|
|
|
export let GlobalDocumentMap: Record<string, TDocumentObj> = {};
|
|
|
|
async function checkCodePushAndSync() {
|
|
try {
|
|
await codePush.sync({
|
|
installMode: codePush.InstallMode.IMMEDIATE,
|
|
});
|
|
} catch (error) {
|
|
}
|
|
}
|
|
|
|
function handleAppStateChange(nextAppState: any) {
|
|
if (nextAppState == 'active') {
|
|
checkCodePushAndSync()
|
|
}
|
|
}
|
|
|
|
const askForPermissions = async (
|
|
setPermissions: React.Dispatch<React.SetStateAction<boolean>>,
|
|
) => {
|
|
if (Platform.OS === 'android') {
|
|
PermissionsAndroid.requestMultiple(PermissionsToCheck)
|
|
.then(async result => {
|
|
let isAllPermissionsGranted = true;
|
|
for (const permission in result) {
|
|
if (
|
|
!(
|
|
result?.[permission as Permission] ===
|
|
PermissionsAndroid.RESULTS.GRANTED
|
|
)
|
|
) {
|
|
isAllPermissionsGranted = false;
|
|
break;
|
|
}
|
|
}
|
|
setPermissions(isAllPermissionsGranted);
|
|
})
|
|
.catch(err => {
|
|
setPermissions(false);
|
|
});
|
|
}
|
|
};
|
|
|
|
const App = () => {
|
|
useNativeButtons();
|
|
const [permissions, setPermissions] = React.useState(true);
|
|
const [isGlobalDocumentMapLoaded, setIsGlobalDocumentMapLoaded] = React.useState(false);
|
|
React.useEffect(() => {
|
|
const appStateChange = AppState.addEventListener('change', (change) => { handleAppStateChange(change);askForPermissions(setPermissions); });
|
|
(async () => {
|
|
const data = await AsyncStorage.getItem(
|
|
LocalStorageKeys.GLOBAL_DOCUMENT_MAP,
|
|
);
|
|
if (data) {
|
|
const parsedData = JSON.parse(data);
|
|
GlobalDocumentMap = parsedData;
|
|
}
|
|
setIsGlobalDocumentMapLoaded(true);
|
|
})();
|
|
checkCodePushAndSync();
|
|
return () => {
|
|
appStateChange.remove();
|
|
}
|
|
}, []);
|
|
return (
|
|
<Provider store={store}>
|
|
<PersistGate
|
|
loading={<FullScreenLoader loading />}
|
|
persistor={persistor}>
|
|
<NavigationContainer ref={navigationRef}>
|
|
<StatusBar
|
|
backgroundColor={COLORS.BACKGROUND.INDIGO_DARK}
|
|
/>
|
|
<SuspenseLoader
|
|
fallBack={<FullScreenLoader loading />}
|
|
loading={!isGlobalDocumentMapLoaded}
|
|
children={
|
|
<ErrorBoundary>
|
|
<ForceUninstallScreen>
|
|
{permissions ? (
|
|
<ProtectedRouter />
|
|
) : (
|
|
<Permissions />
|
|
)}
|
|
</ForceUninstallScreen>
|
|
</ErrorBoundary>
|
|
}
|
|
/>
|
|
|
|
</NavigationContainer>
|
|
{
|
|
<KeyboardAvoidingView behavior="position">
|
|
<ToastContainer
|
|
config={toastConfigs}
|
|
position="bottom"
|
|
/>
|
|
</KeyboardAvoidingView>
|
|
}
|
|
</PersistGate>
|
|
</Provider>
|
|
);
|
|
};
|
|
|
|
export default (App);
|