Skip to content

Commit 1f18a18

Browse files
mateuuszzzzzwar-in
authored andcommitted
Apply prettier & move HybridAppHandler logic to useEffect
1 parent 7c818c4 commit 1f18a18

2 files changed

Lines changed: 18 additions & 17 deletions

File tree

src/App.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ function App({url}: AppProps) {
7777
<StrictModeWrapper>
7878
<SplashScreenStateContextProvider>
7979
<InitialURLContextProvider url={url}>
80-
<HybridAppHandler/>
80+
<HybridAppHandler />
8181
<GestureHandlerRootView style={fill}>
8282
<ComposeProviders
8383
components={[

src/HybridAppHandler.tsx

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,32 @@
1-
import {useContext, useState} from 'react';
21
import HybridAppModule from "@expensify/react-native-hybrid-app/src/index.native";
3-
import Log from './libs/Log';
2+
import {useContext, useEffect} from 'react';
43
import CONFIG from './CONFIG';
54
import CONST from './CONST';
6-
import {signInAfterTransitionFromOldDot} from './libs/actions/Session';
5+
import { signInAfterTransitionFromOldDot } from './libs/actions/Session';
6+
import Log from './libs/Log';
77
import SplashScreenStateContext from './SplashScreenStateContext';
88

9+
910
function HybridAppHandler() {
10-
const [signInHandled, setSignInHandled] = useState(false);
1111
const {setSplashScreenState} = useContext(SplashScreenStateContext);
1212

13-
if (!CONFIG.IS_HYBRID_APP || signInHandled) {
14-
return null;
15-
}
16-
17-
HybridAppModule.getHybridAppSettings().then((hybridAppSettings: string | null) => {
18-
if(!hybridAppSettings) {
19-
// Native method can send non-null value only once per NewDot lifecycle. It prevents issues with multiple initializations during reloads on debug builds.
20-
Log.info('[HybridApp] `getHybridAppSettings` called more than once during single NewDot lifecycle. Skipping initialization.');
13+
useEffect(() => {
14+
if (!CONFIG.IS_HYBRID_APP) {
2115
return;
2216
}
2317

24-
signInAfterTransitionFromOldDot(hybridAppSettings).then(() => {
25-
setSplashScreenState(CONST.BOOT_SPLASH_STATE.READY_TO_BE_HIDDEN);
26-
setSignInHandled(true);
18+
HybridAppModule.getHybridAppSettings().then((hybridAppSettings: string | null) => {
19+
if(!hybridAppSettings) {
20+
// Native method can send non-null value only once per NewDot lifecycle. It prevents issues with multiple initializations during reloads on debug builds.
21+
Log.info('[HybridApp] `getHybridAppSettings` called more than once during single NewDot lifecycle. Skipping initialization.');
22+
return;
23+
}
24+
25+
signInAfterTransitionFromOldDot(hybridAppSettings).then(() => {
26+
setSplashScreenState(CONST.BOOT_SPLASH_STATE.READY_TO_BE_HIDDEN);
27+
});
2728
});
28-
});
29+
}, [setSplashScreenState]);
2930

3031
return null;
3132
}

0 commit comments

Comments
 (0)