1
1
import { Audio } from 'expo-av' ;
2
- import React , { useCallback , useEffect , useLayoutEffect , useMemo , useRef , useState } from 'react' ;
2
+ import React , { useCallback , useContext , useEffect , useLayoutEffect , useMemo , useRef , useState } from 'react' ;
3
3
import type { NativeEventSubscription } from 'react-native' ;
4
4
import { AppState , Linking , NativeModules , Platform } from 'react-native' ;
5
5
import type { OnyxEntry } from 'react-native-onyx' ;
@@ -20,8 +20,8 @@ import {updateLastRoute} from './libs/actions/App';
20
20
import * as EmojiPickerAction from './libs/actions/EmojiPickerAction' ;
21
21
import * as Report from './libs/actions/Report' ;
22
22
import * as User from './libs/actions/User' ;
23
+ import { handleHybridAppOnboarding } from './libs/actions/Welcome' ;
23
24
import * as ActiveClientManager from './libs/ActiveClientManager' ;
24
- import BootSplash from './libs/BootSplash' ;
25
25
import FS from './libs/Fullstory' ;
26
26
import * as Growl from './libs/Growl' ;
27
27
import Log from './libs/Log' ;
@@ -42,6 +42,7 @@ import PopoverReportActionContextMenu from './pages/home/report/ContextMenu/Popo
42
42
import * as ReportActionContextMenu from './pages/home/report/ContextMenu/ReportActionContextMenu' ;
43
43
import type { Route } from './ROUTES' ;
44
44
import ROUTES from './ROUTES' ;
45
+ import SplashScreenStateContext from './SplashScreenStateContext' ;
45
46
import type { ScreenShareRequest } from './types/onyx' ;
46
47
47
48
Onyx . registerLogger ( ( { level, message} ) => {
@@ -80,13 +81,6 @@ type ExpensifyOnyxProps = {
80
81
81
82
type ExpensifyProps = ExpensifyOnyxProps ;
82
83
83
- // HybridApp needs access to SetStateAction in order to properly hide SplashScreen when React Native was booted before.
84
- type SplashScreenHiddenContextType = { isSplashHidden ?: boolean ; setIsSplashHidden : React . Dispatch < React . SetStateAction < boolean > > } ;
85
-
86
- const SplashScreenHiddenContext = React . createContext < SplashScreenHiddenContextType > ( {
87
- setIsSplashHidden : ( ) => { } ,
88
- } ) ;
89
-
90
84
function Expensify ( {
91
85
isCheckingPublicRoom = true ,
92
86
updateAvailable,
@@ -99,12 +93,13 @@ function Expensify({
99
93
const appStateChangeListener = useRef < NativeEventSubscription | null > ( null ) ;
100
94
const [ isNavigationReady , setIsNavigationReady ] = useState ( false ) ;
101
95
const [ isOnyxMigrated , setIsOnyxMigrated ] = useState ( false ) ;
102
- const [ isSplashHidden , setIsSplashHidden ] = useState ( false ) ;
96
+ const { splashScreenState , setSplashScreenState } = useContext ( SplashScreenStateContext ) ;
103
97
const [ hasAttemptedToOpenPublicRoom , setAttemptedToOpenPublicRoom ] = useState ( false ) ;
104
98
const { translate} = useLocalize ( ) ;
105
99
const [ account ] = useOnyx ( ONYXKEYS . ACCOUNT ) ;
106
100
const [ session ] = useOnyx ( ONYXKEYS . SESSION ) ;
107
101
const [ lastRoute ] = useOnyx ( ONYXKEYS . LAST_ROUTE ) ;
102
+ const [ tryNewDotData ] = useOnyx ( ONYXKEYS . NVP_TRYNEWDOT ) ;
108
103
const [ shouldShowRequire2FAModal , setShouldShowRequire2FAModal ] = useState ( false ) ;
109
104
110
105
useEffect ( ( ) => {
@@ -123,11 +118,21 @@ function Expensify({
123
118
setAttemptedToOpenPublicRoom ( true ) ;
124
119
} , [ isCheckingPublicRoom ] ) ;
125
120
121
+ useEffect ( ( ) => {
122
+ if ( splashScreenState !== CONST . BOOT_SPLASH_STATE . HIDDEN || tryNewDotData === undefined ) {
123
+ return ;
124
+ }
125
+
126
+ handleHybridAppOnboarding ( ) ;
127
+ } , [ splashScreenState , tryNewDotData ] ) ;
128
+
126
129
const isAuthenticated = useMemo ( ( ) => ! ! ( session ?. authToken ?? null ) , [ session ] ) ;
127
130
const autoAuthState = useMemo ( ( ) => session ?. autoAuthState ?? '' , [ session ] ) ;
128
131
129
132
const shouldInit = isNavigationReady && hasAttemptedToOpenPublicRoom ;
130
- const shouldHideSplash = shouldInit && ! isSplashHidden ;
133
+ const shouldHideSplash =
134
+ shouldInit &&
135
+ ( NativeModules . HybridAppModule ? splashScreenState === CONST . BOOT_SPLASH_STATE . READY_TO_BE_HIDDEN && isAuthenticated : splashScreenState === CONST . BOOT_SPLASH_STATE . VISIBLE ) ;
131
136
132
137
const initializeClient = ( ) => {
133
138
if ( ! Visibility . isVisible ( ) ) {
@@ -145,17 +150,9 @@ function Expensify({
145
150
} , [ ] ) ;
146
151
147
152
const onSplashHide = useCallback ( ( ) => {
148
- setIsSplashHidden ( true ) ;
153
+ setSplashScreenState ( CONST . BOOT_SPLASH_STATE . HIDDEN ) ;
149
154
Performance . markEnd ( CONST . TIMING . SIDEBAR_LOADED ) ;
150
- } , [ ] ) ;
151
-
152
- const contextValue = useMemo (
153
- ( ) => ( {
154
- isSplashHidden,
155
- setIsSplashHidden,
156
- } ) ,
157
- [ isSplashHidden , setIsSplashHidden ] ,
158
- ) ;
155
+ } , [ setSplashScreenState ] ) ;
159
156
160
157
useLayoutEffect ( ( ) => {
161
158
// Initialize this client as being an active client
@@ -177,24 +174,22 @@ function Expensify({
177
174
178
175
useEffect ( ( ) => {
179
176
setTimeout ( ( ) => {
180
- BootSplash . getVisibilityStatus ( ) . then ( ( status ) => {
181
- const appState = AppState . currentState ;
182
- Log . info ( '[BootSplash] splash screen status' , false , { appState, status} ) ;
183
-
184
- if ( status === 'visible' ) {
185
- const propsToLog : Omit < ExpensifyProps & { isAuthenticated : boolean } , 'children' | 'session' > = {
186
- isCheckingPublicRoom,
187
- updateRequired,
188
- updateAvailable,
189
- isSidebarLoaded,
190
- screenShareRequest,
191
- focusModeNotification,
192
- isAuthenticated,
193
- lastVisitedPath,
194
- } ;
195
- Log . alert ( '[BootSplash] splash screen is still visible' , { propsToLog} , false ) ;
196
- }
197
- } ) ;
177
+ const appState = AppState . currentState ;
178
+ Log . info ( '[BootSplash] splash screen status' , false , { appState, splashScreenState} ) ;
179
+
180
+ if ( splashScreenState === CONST . BOOT_SPLASH_STATE . VISIBLE ) {
181
+ const propsToLog : Omit < ExpensifyProps & { isAuthenticated : boolean } , 'children' | 'session' > = {
182
+ isCheckingPublicRoom,
183
+ updateRequired,
184
+ updateAvailable,
185
+ isSidebarLoaded,
186
+ screenShareRequest,
187
+ focusModeNotification,
188
+ isAuthenticated,
189
+ lastVisitedPath,
190
+ } ;
191
+ Log . alert ( '[BootSplash] splash screen is still visible' , { propsToLog} , false ) ;
192
+ }
198
193
} , 30 * 1000 ) ;
199
194
200
195
// This timer is set in the native layer when launching the app and we stop it here so we can measure how long
@@ -304,18 +299,15 @@ function Expensify({
304
299
305
300
< AppleAuthWrapper />
306
301
{ hasAttemptedToOpenPublicRoom && (
307
- < SplashScreenHiddenContext . Provider value = { contextValue } >
308
- < NavigationRoot
309
- onReady = { setNavigationReady }
310
- authenticated = { isAuthenticated }
311
- lastVisitedPath = { lastVisitedPath as Route }
312
- initialUrl = { initialUrl }
313
- shouldShowRequire2FAModal = { shouldShowRequire2FAModal }
314
- />
315
- </ SplashScreenHiddenContext . Provider >
302
+ < NavigationRoot
303
+ onReady = { setNavigationReady }
304
+ authenticated = { isAuthenticated }
305
+ lastVisitedPath = { lastVisitedPath as Route }
306
+ initialUrl = { initialUrl }
307
+ shouldShowRequire2FAModal = { shouldShowRequire2FAModal }
308
+ />
316
309
) }
317
- { /* HybridApp has own middleware to hide SplashScreen */ }
318
- { ! NativeModules . HybridAppModule && shouldHideSplash && < SplashScreenHider onHide = { onSplashHide } /> }
310
+ { shouldHideSplash && < SplashScreenHider onHide = { onSplashHide } /> }
319
311
</ DeeplinkWrapper >
320
312
) ;
321
313
}
@@ -349,5 +341,3 @@ export default withOnyx<ExpensifyProps, ExpensifyOnyxProps>({
349
341
key : ONYXKEYS . LAST_VISITED_PATH ,
350
342
} ,
351
343
} ) ( Expensify ) ;
352
-
353
- export { SplashScreenHiddenContext } ;
0 commit comments