Skip to content

Commit d44598e

Browse files
authored
Merge pull request Expensify#72077 from DylanDylann/refactor-600
[New PR] Remove Onyx.connect() in src/libs/Navigation/AppNavigator/AuthScreens.tsx
2 parents 968f7a2 + d65ed98 commit d44598e

1 file changed

Lines changed: 19 additions & 28 deletions

File tree

src/libs/Navigation/AppNavigator/AuthScreens.tsx

Lines changed: 19 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
import type {RouteProp} from '@react-navigation/native';
22
import {useNavigation} from '@react-navigation/native';
33
import type {StackCardInterpolationProps} from '@react-navigation/stack';
4-
import React, {memo, useContext, useEffect, useMemo, useState} from 'react';
5-
import type {OnyxEntry} from 'react-native-onyx';
6-
import Onyx from 'react-native-onyx';
4+
import React, {memo, useContext, useEffect, useMemo, useRef, useState} from 'react';
75
import ComposeProviders from '@components/ComposeProviders';
86
import DelegateNoAccessModalProvider from '@components/DelegateNoAccessModalProvider';
97
import FullScreenLoadingIndicator from '@components/FullscreenLoadingIndicator';
@@ -106,31 +104,6 @@ function initializePusher() {
106104
User.subscribeToUserEvents();
107105
});
108106
}
109-
let lastUpdateIDAppliedToClient: OnyxEntry<number>;
110-
let isLoadingApp = false;
111-
112-
Onyx.connect({
113-
key: ONYXKEYS.ONYX_UPDATES_LAST_UPDATE_ID_APPLIED_TO_CLIENT,
114-
callback: (value) => {
115-
lastUpdateIDAppliedToClient = value;
116-
},
117-
});
118-
119-
Onyx.connect({
120-
key: ONYXKEYS.IS_LOADING_APP,
121-
callback: (value) => {
122-
isLoadingApp = !!value;
123-
},
124-
});
125-
126-
function handleNetworkReconnect() {
127-
if (isLoadingApp) {
128-
App.openApp();
129-
} else {
130-
Log.info('[handleNetworkReconnect] Sending ReconnectApp');
131-
App.reconnectApp(lastUpdateIDAppliedToClient);
132-
}
133-
}
134107

135108
const RootStack = createRootStackNavigator<AuthScreensParamList>();
136109

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

175+
const [lastUpdateIDAppliedToClient] = useOnyx(ONYXKEYS.ONYX_UPDATES_LAST_UPDATE_ID_APPLIED_TO_CLIENT, {canBeMissing: true});
176+
const [isLoadingApp] = useOnyx(ONYXKEYS.IS_LOADING_APP, {canBeMissing: true});
177+
const lastUpdateIDAppliedToClientRef = useRef(lastUpdateIDAppliedToClient);
178+
const isLoadingAppRef = useRef(isLoadingApp);
179+
// eslint-disable-next-line react-compiler/react-compiler
180+
lastUpdateIDAppliedToClientRef.current = lastUpdateIDAppliedToClient;
181+
// eslint-disable-next-line react-compiler/react-compiler
182+
isLoadingAppRef.current = isLoadingApp;
183+
184+
const handleNetworkReconnect = () => {
185+
if (isLoadingAppRef.current) {
186+
App.openApp();
187+
} else {
188+
Log.info('[handleNetworkReconnect] Sending ReconnectApp');
189+
App.reconnectApp(lastUpdateIDAppliedToClientRef.current);
190+
}
191+
};
192+
202193
// On HybridApp we need to prevent flickering during transition to OldDot
203194
const shouldRenderOnboardingExclusivelyOnHybridApp = useMemo(() => {
204195
return CONFIG.IS_HYBRID_APP && Navigation.getActiveRoute().includes(ROUTES.ONBOARDING_INTERESTED_FEATURES.route) && isOnboardingCompleted === true;

0 commit comments

Comments
 (0)