|
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'; |
| 4 | +import React, {memo, useContext, useEffect, useMemo, useRef, useState} from 'react'; |
5 | 5 | import type {OnyxEntry} from 'react-native-onyx'; |
6 | 6 | import Onyx from 'react-native-onyx'; |
7 | 7 | import ComposeProviders from '@components/ComposeProviders'; |
@@ -105,32 +105,6 @@ function initializePusher() { |
105 | 105 | }).then(() => { |
106 | 106 | User.subscribeToUserEvents(); |
107 | 107 | }); |
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 | | -} |
134 | 108 |
|
135 | 109 | const RootStack = createRootStackNavigator<AuthScreensParamList>(); |
136 | 110 |
|
@@ -199,6 +173,25 @@ function AuthScreens() { |
199 | 173 | const [initialLastUpdateIDAppliedToClient] = useOnyx(ONYXKEYS.ONYX_UPDATES_LAST_UPDATE_ID_APPLIED_TO_CLIENT, {canBeMissing: true}); |
200 | 174 | const [modal] = useOnyx(ONYXKEYS.MODAL, {canBeMissing: true}); |
201 | 175 |
|
| 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 | + |
202 | 195 | // On HybridApp we need to prevent flickering during transition to OldDot |
203 | 196 | const shouldRenderOnboardingExclusivelyOnHybridApp = useMemo(() => { |
204 | 197 | return CONFIG.IS_HYBRID_APP && Navigation.getActiveRoute().includes(ROUTES.ONBOARDING_INTERESTED_FEATURES.route) && isOnboardingCompleted === true; |
|
0 commit comments