Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 19 additions & 28 deletions src/libs/Navigation/AppNavigator/AuthScreens.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import type {RouteProp} from '@react-navigation/native';
import {useNavigation} from '@react-navigation/native';
import type {StackCardInterpolationProps} from '@react-navigation/stack';
import React, {memo, useContext, useEffect, useMemo, useState} from 'react';
import type {OnyxEntry} from 'react-native-onyx';
import Onyx from 'react-native-onyx';
import React, {memo, useContext, useEffect, useMemo, useRef, useState} from 'react';
import ComposeProviders from '@components/ComposeProviders';
import DelegateNoAccessModalProvider from '@components/DelegateNoAccessModalProvider';
import FullScreenLoadingIndicator from '@components/FullscreenLoadingIndicator';
Expand Down Expand Up @@ -106,31 +104,6 @@ function initializePusher() {
User.subscribeToUserEvents();
});
}
let lastUpdateIDAppliedToClient: OnyxEntry<number>;
let isLoadingApp = false;

Onyx.connect({
key: ONYXKEYS.ONYX_UPDATES_LAST_UPDATE_ID_APPLIED_TO_CLIENT,
callback: (value) => {
lastUpdateIDAppliedToClient = value;
},
});

Onyx.connect({
key: ONYXKEYS.IS_LOADING_APP,
callback: (value) => {
isLoadingApp = !!value;
},
});

function handleNetworkReconnect() {
if (isLoadingApp) {
App.openApp();
} else {
Log.info('[handleNetworkReconnect] Sending ReconnectApp');
App.reconnectApp(lastUpdateIDAppliedToClient);
}
}

const RootStack = createRootStackNavigator<AuthScreensParamList>();

Expand Down Expand Up @@ -199,6 +172,24 @@ function AuthScreens() {
const [initialLastUpdateIDAppliedToClient] = useOnyx(ONYXKEYS.ONYX_UPDATES_LAST_UPDATE_ID_APPLIED_TO_CLIENT, {canBeMissing: true});
const [modal] = useOnyx(ONYXKEYS.MODAL, {canBeMissing: true});

const [lastUpdateIDAppliedToClient] = useOnyx(ONYXKEYS.ONYX_UPDATES_LAST_UPDATE_ID_APPLIED_TO_CLIENT, {canBeMissing: true});
const [isLoadingApp] = useOnyx(ONYXKEYS.IS_LOADING_APP, {canBeMissing: true});
const lastUpdateIDAppliedToClientRef = useRef(lastUpdateIDAppliedToClient);
const isLoadingAppRef = useRef(isLoadingApp);
// eslint-disable-next-line react-compiler/react-compiler
lastUpdateIDAppliedToClientRef.current = lastUpdateIDAppliedToClient;
// eslint-disable-next-line react-compiler/react-compiler
isLoadingAppRef.current = isLoadingApp;

const handleNetworkReconnect = () => {
if (isLoadingAppRef.current) {
App.openApp();
} else {
Log.info('[handleNetworkReconnect] Sending ReconnectApp');
App.reconnectApp(lastUpdateIDAppliedToClientRef.current);
}
};

// On HybridApp we need to prevent flickering during transition to OldDot
const shouldRenderOnboardingExclusivelyOnHybridApp = useMemo(() => {
return CONFIG.IS_HYBRID_APP && Navigation.getActiveRoute().includes(ROUTES.ONBOARDING_INTERESTED_FEATURES.route) && isOnboardingCompleted === true;
Expand Down
Loading