|
1 | | -import {useContext, useState} from 'react'; |
2 | 1 | import HybridAppModule from "@expensify/react-native-hybrid-app/src/index.native"; |
3 | | -import Log from './libs/Log'; |
| 2 | +import {useContext, useEffect} from 'react'; |
4 | 3 | import CONFIG from './CONFIG'; |
5 | 4 | import CONST from './CONST'; |
6 | | -import {signInAfterTransitionFromOldDot} from './libs/actions/Session'; |
| 5 | +import { signInAfterTransitionFromOldDot } from './libs/actions/Session'; |
| 6 | +import Log from './libs/Log'; |
7 | 7 | import SplashScreenStateContext from './SplashScreenStateContext'; |
8 | 8 |
|
| 9 | + |
9 | 10 | function HybridAppHandler() { |
10 | | - const [signInHandled, setSignInHandled] = useState(false); |
11 | 11 | const {setSplashScreenState} = useContext(SplashScreenStateContext); |
12 | 12 |
|
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) { |
21 | 15 | return; |
22 | 16 | } |
23 | 17 |
|
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 | + }); |
27 | 28 | }); |
28 | | - }); |
| 29 | + }, [setSplashScreenState]); |
29 | 30 |
|
30 | 31 | return null; |
31 | 32 | } |
|
0 commit comments