Skip to content

Commit e990f51

Browse files
committed
remove connect method
1 parent c3f1cc2 commit e990f51

1 file changed

Lines changed: 20 additions & 27 deletions

File tree

src/libs/Navigation/AppNavigator/AuthScreens.tsx

Lines changed: 20 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +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';
4+
import React, {memo, useContext, useEffect, useMemo, useRef, useState} from 'react';
55
import type {OnyxEntry} from 'react-native-onyx';
66
import Onyx from 'react-native-onyx';
77
import ComposeProviders from '@components/ComposeProviders';
@@ -105,32 +105,6 @@ function initializePusher() {
105105
}).then(() => {
106106
User.subscribeToUserEvents();
107107
});
108-
}
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-
}
134108

135109
const RootStack = createRootStackNavigator<AuthScreensParamList>();
136110

@@ -199,6 +173,25 @@ function AuthScreens() {
199173
const [initialLastUpdateIDAppliedToClient] = useOnyx(ONYXKEYS.ONYX_UPDATES_LAST_UPDATE_ID_APPLIED_TO_CLIENT, {canBeMissing: true});
200174
const [modal] = useOnyx(ONYXKEYS.MODAL, {canBeMissing: true});
201175

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

0 commit comments

Comments
 (0)