|
1 | 1 | import type {RouteProp} from '@react-navigation/native'; |
2 | 2 | import {useNavigation} from '@react-navigation/native'; |
3 | 3 | 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'; |
7 | 5 | import ComposeProviders from '@components/ComposeProviders'; |
8 | 6 | import DelegateNoAccessModalProvider from '@components/DelegateNoAccessModalProvider'; |
9 | 7 | import FullScreenLoadingIndicator from '@components/FullscreenLoadingIndicator'; |
@@ -106,31 +104,6 @@ function initializePusher() { |
106 | 104 | User.subscribeToUserEvents(); |
107 | 105 | }); |
108 | 106 | } |
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 | | -} |
134 | 107 |
|
135 | 108 | const RootStack = createRootStackNavigator<AuthScreensParamList>(); |
136 | 109 |
|
@@ -199,6 +172,24 @@ function AuthScreens() { |
199 | 172 | const [initialLastUpdateIDAppliedToClient] = useOnyx(ONYXKEYS.ONYX_UPDATES_LAST_UPDATE_ID_APPLIED_TO_CLIENT, {canBeMissing: true}); |
200 | 173 | const [modal] = useOnyx(ONYXKEYS.MODAL, {canBeMissing: true}); |
201 | 174 |
|
| 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 | + |
202 | 193 | // On HybridApp we need to prevent flickering during transition to OldDot |
203 | 194 | const shouldRenderOnboardingExclusivelyOnHybridApp = useMemo(() => { |
204 | 195 | return CONFIG.IS_HYBRID_APP && Navigation.getActiveRoute().includes(ROUTES.ONBOARDING_INTERESTED_FEATURES.route) && isOnboardingCompleted === true; |
|
0 commit comments