|
1 | | -import {useContext, useState} from 'react'; |
2 | | -import type {AppProps} from './App'; |
| 1 | +import HybridAppModule from '@expensify/react-native-hybrid-app'; |
| 2 | +import {useContext, useEffect} from 'react'; |
3 | 3 | import CONFIG from './CONFIG'; |
4 | 4 | import CONST from './CONST'; |
5 | 5 | import {signInAfterTransitionFromOldDot} from './libs/actions/Session'; |
| 6 | +import Log from './libs/Log'; |
6 | 7 | import SplashScreenStateContext from './SplashScreenStateContext'; |
7 | 8 |
|
8 | | -function HybridAppHandler({hybridAppSettings}: AppProps) { |
9 | | - const [signInHandled, setSignInHandled] = useState(false); |
| 9 | +function HybridAppHandler() { |
10 | 10 | const {setSplashScreenState} = useContext(SplashScreenStateContext); |
11 | 11 |
|
12 | | - if (!CONFIG.IS_HYBRID_APP || !hybridAppSettings || signInHandled) { |
13 | | - return null; |
14 | | - } |
| 12 | + useEffect(() => { |
| 13 | + if (!CONFIG.IS_HYBRID_APP) { |
| 14 | + return; |
| 15 | + } |
15 | 16 |
|
16 | | - signInAfterTransitionFromOldDot(hybridAppSettings).then(() => { |
17 | | - setSplashScreenState(CONST.BOOT_SPLASH_STATE.READY_TO_BE_HIDDEN); |
18 | | - setSignInHandled(true); |
19 | | - }); |
| 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.'); |
| 21 | + return; |
| 22 | + } |
| 23 | + |
| 24 | + signInAfterTransitionFromOldDot(hybridAppSettings).then(() => { |
| 25 | + setSplashScreenState(CONST.BOOT_SPLASH_STATE.READY_TO_BE_HIDDEN); |
| 26 | + }); |
| 27 | + }); |
| 28 | + }, [setSplashScreenState]); |
20 | 29 |
|
21 | 30 | return null; |
22 | 31 | } |
|
0 commit comments