Newer
Older
import { Linking } from 'react-native';
import UserInactivity from 'react-native-user-inactivity';
import {observer} from "mobx-react";
import {useNavigation} from "@react-navigation/core";
import AgentProvider from '@aries-framework/react-hooks';
import MainStack from './MainStack';
import OnboardingStack from './OnboardingStack';
import {Screens, TabStackParams, TabStacks} from 'src/type/navigators';
import { StackNavigationProp } from '@react-navigation/stack';
import { ro } from 'date-fns/locale';
const navigation = useNavigation<StackNavigationProp<TabStackParams>>();
rootStore.agentStore.createAgent();
rootStore.urlStore.injectNavigation(navigation);
const handleDeepLinking = (url: string) => {
rootStore.urlStore.setDeepLink(url);
if (rootStore.authenticated) {
rootStore.urlStore.processDeepLinkIfAny();
}
};
//if the app is not opened
useEffect(() => {
(async () => {
const initialUrl = await Linking.getInitialURL();
if(initialUrl) {
const supported = await Linking.canOpenURL(initialUrl);
if(supported) {
handleDeepLinking(initialUrl);
}
//if the app is opened in the background
useEffect(() => {
Linking.addEventListener('url', async ({url}) => {
if(url){
const supported = await Linking.canOpenURL(url);
if(supported) {
handleDeepLinking(url);
}
}
});
return () => {
Linking.removeAllListeners('url');
}
}, []);
// Subscribe to events
useEffect(() => {
if (!rootStore.authenticated) return;
return notifee.onForegroundEvent(({ type, detail }) => {
switch (type) {
case EventType.PRESS:
console.log('User pressed notification', detail.notification);
if (detail.notification?.data?.type === 'new-email-received') {
const realmId = detail.notification?.data?.realmId as string;
if (realmId) {
navigation.navigate(TabStacks.EmailStack, {
screen: Screens.EmailDetails,
});
}
}
break;
}
});
}, [rootStore.authenticated]);
useEffect(() => {
if (rootStore.authenticated) {
rootStore.urlStore.processDeepLinkIfAny();
}
}, [rootStore.authenticated]);
return rootStore.agentStore.agentCreated && rootStore.authenticated ? (
onAction={isActive => {
rootStore.setAuthenticated(isActive);
}}
<AgentProvider agent={rootStore.agentStore.agent}>
<MainStack />
</AgentProvider>