Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/Expensify.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,12 @@ function Expensify() {
initialUrl={initialUrl}
/>
)}
{shouldHideSplash && <SplashScreenHider onHide={onSplashHide} />}
{(isSplashVisible || isSplashReadyToBeHidden) && (
<SplashScreenHider
shouldHideSplash={shouldHideSplash}
onHide={onSplashHide}
/>
)}
</>
);
}
Expand Down
44 changes: 21 additions & 23 deletions src/HybridAppHandler.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {useCallback, useEffect} from 'react';
import {useEffect} from 'react';
import CONFIG from './CONFIG';
import CONST from './CONST';
import useOnyx from './hooks/useOnyx';
Expand All @@ -9,35 +9,25 @@ import Log from './libs/Log';
import {endSpan, startSpan} from './libs/telemetry/activeSpans';
import {addBootsplashBreadcrumb} from './libs/telemetry/bootsplashTelemetry';
import ONYXKEYS from './ONYXKEYS';
import {useSplashScreenActions, useSplashScreenState} from './SplashScreenStateContext';
import {useSplashScreenActions} from './SplashScreenStateContext';
import isLoadingOnyxValue from './types/utils/isLoadingOnyxValue';

function HybridAppHandler() {
const {splashScreenState} = useSplashScreenState();
const {setSplashScreenState} = useSplashScreenActions();
const [tryNewDot, tryNewDotMetadata] = useOnyx(ONYXKEYS.NVP_TRY_NEW_DOT);
const isLoadingTryNewDot = isLoadingOnyxValue(tryNewDotMetadata);

const finalizeTransitionFromOldDot = useCallback(
(hybridAppSettings: HybridAppSettings) => {
const loggedOutFromOldDot = !!hybridAppSettings.hybridApp.loggedOutFromOldDot;
const finalizeTransitionFromOldDot = (hybridAppSettings: HybridAppSettings) => {
const loggedOutFromOldDot = !!hybridAppSettings.hybridApp.loggedOutFromOldDot;

setupNewDotAfterTransitionFromOldDot(hybridAppSettings, tryNewDot).then(() => {
if (splashScreenState !== CONST.BOOT_SPLASH_STATE.VISIBLE) {
addBootsplashBreadcrumb('HybridAppHandler: Splash no longer VISIBLE, skipping state transition', {splashScreenState});
return;
}

if (loggedOutFromOldDot) {
setSplashScreenState(CONST.BOOT_SPLASH_STATE.HIDDEN);
endSpan(CONST.TELEMETRY.SPAN_OD_ND_TRANSITION_LOGGED_OUT);
} else {
setSplashScreenState(CONST.BOOT_SPLASH_STATE.READY_TO_BE_HIDDEN);
}
});
},
[setSplashScreenState, splashScreenState, tryNewDot],
);
setupNewDotAfterTransitionFromOldDot(hybridAppSettings, tryNewDot).then(() => {
if (loggedOutFromOldDot) {
endSpan(CONST.TELEMETRY.SPAN_OD_ND_TRANSITION_LOGGED_OUT);
} else {
setSplashScreenState(CONST.BOOT_SPLASH_STATE.READY_TO_BE_HIDDEN);
}
});
};

useEffect(() => {
if (!CONFIG.IS_HYBRID_APP || isLoadingTryNewDot) {
Expand All @@ -55,6 +45,14 @@ function HybridAppHandler() {

addBootsplashBreadcrumb('HybridAppHandler: Settings received', {loggedOutFromOldDot: String(!!hybridAppSettings.hybridApp.loggedOutFromOldDot)});

// Resolve splash state ASAP — this is the earliest moment we know
// whether the native splash is on screen or not
if (hybridAppSettings.hybridApp.loggedOutFromOldDot) {
setSplashScreenState(CONST.BOOT_SPLASH_STATE.HIDDEN);
} else {
setSplashScreenState(CONST.BOOT_SPLASH_STATE.VISIBLE);
}

if (hybridAppSettings.hybridApp.loggedOutFromOldDot) {
startSpan(CONST.TELEMETRY.SPAN_OD_ND_TRANSITION_LOGGED_OUT, {
name: CONST.TELEMETRY.SPAN_OD_ND_TRANSITION_LOGGED_OUT,
Expand All @@ -71,7 +69,7 @@ function HybridAppHandler() {

finalizeTransitionFromOldDot(hybridAppSettings);
});
}, [finalizeTransitionFromOldDot, isLoadingTryNewDot]);
}, [finalizeTransitionFromOldDot, isLoadingTryNewDot, setSplashScreenState]);
Comment thread
war-in marked this conversation as resolved.
Resolved

return null;
}
Expand Down
7 changes: 4 additions & 3 deletions src/SplashScreenStateContext.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
import React, {useContext, useEffect, useState} from 'react';
import type {ValueOf} from 'type-fest';
import CONFIG from './CONFIG';
import CONST from './CONST';
import {addBootsplashBreadcrumb} from './libs/telemetry/bootsplashTelemetry';
import type ChildrenProps from './types/utils/ChildrenProps';

type SplashScreenState = ValueOf<typeof CONST.BOOT_SPLASH_STATE>;

type SplashScreenStateContextType = {
splashScreenState: SplashScreenState;
splashScreenState: SplashScreenState | undefined;
};

type SplashScreenActionsContextType = {
setSplashScreenState: (state: SplashScreenState) => void;
};

const SplashScreenStateContext = React.createContext<SplashScreenStateContextType>({
splashScreenState: CONST.BOOT_SPLASH_STATE.VISIBLE,
splashScreenState: undefined,
});

const SplashScreenActionsContext = React.createContext<SplashScreenActionsContextType>({
Expand All @@ -29,7 +30,7 @@ function loadPostSplashScreenModules() {
}

function SplashScreenStateContextProvider({children}: ChildrenProps) {
const [splashScreenState, setSplashScreenStateRaw] = useState<SplashScreenState>(CONST.BOOT_SPLASH_STATE.VISIBLE);
const [splashScreenState, setSplashScreenStateRaw] = useState<SplashScreenState | undefined>(CONFIG.IS_HYBRID_APP ? undefined : CONST.BOOT_SPLASH_STATE.VISIBLE);

const setSplashScreenState = (state: SplashScreenState) => {
addBootsplashBreadcrumb(`splashScreenState changed to ${state}`);
Expand Down
17 changes: 11 additions & 6 deletions src/components/SplashScreenHider/index.native.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {useCallback, useRef} from 'react';
import {useEffect, useEffectEvent, useRef} from 'react';
import type {ViewStyle} from 'react-native';
import {StyleSheet} from 'react-native';
import Reanimated, {Easing, useAnimatedStyle, useSharedValue, withTiming} from 'react-native-reanimated';
Expand All @@ -9,7 +9,7 @@ import useThemeStyles from '@hooks/useThemeStyles';
import BootSplash from '@libs/BootSplash';
import type {SplashScreenHiderProps, SplashScreenHiderReturnType} from './types';

function SplashScreenHider({onHide = () => {}}: SplashScreenHiderProps): SplashScreenHiderReturnType {
function SplashScreenHider({onHide, shouldHideSplash}: SplashScreenHiderProps): SplashScreenHiderReturnType {
const styles = useThemeStyles();
const logoSizeRatio = BootSplash.logoSizeRatio || 1;

Expand All @@ -24,8 +24,7 @@ function SplashScreenHider({onHide = () => {}}: SplashScreenHiderProps): SplashS
}));

const hideHasBeenCalled = useRef(false);

const hide = useCallback(() => {
const hide = useEffectEvent(() => {
// hide can only be called once
if (hideHasBeenCalled.current) {
return;
Expand All @@ -52,13 +51,19 @@ function SplashScreenHider({onHide = () => {}}: SplashScreenHiderProps): SplashS
),
);
});
}, [opacity, scale, onHide]);
});

useEffect(() => {
if (!shouldHideSplash) {
return;
}
hide();
}, [shouldHideSplash]);

return (
<Reanimated.View style={[StyleSheet.absoluteFill, styles.splashScreenHider, opacityStyle]}>
<Reanimated.View style={scaleStyle}>
<ImageSVG
onLoadEnd={hide}
contentFit="fill"
style={{width: 100 * logoSizeRatio, height: 100 * logoSizeRatio}}
src={Logo}
Expand Down
15 changes: 11 additions & 4 deletions src/components/SplashScreenHider/index.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
import {useEffect} from 'react';
import {useEffect, useEffectEvent} from 'react';
import BootSplash from '@libs/BootSplash';
import type {SplashScreenHiderProps, SplashScreenHiderReturnType} from './types';

function SplashScreenHider({onHide = () => {}}: SplashScreenHiderProps): SplashScreenHiderReturnType {
useEffect(() => {
function SplashScreenHider({onHide, shouldHideSplash}: SplashScreenHiderProps): SplashScreenHiderReturnType {
const hide = useEffectEvent(() => {
BootSplash.hide().then(() => onHide());
}, [onHide]);
});

useEffect(() => {
if (!shouldHideSplash) {
return;
}
hide();
}, [shouldHideSplash]);

return null;
}
Expand Down
3 changes: 3 additions & 0 deletions src/components/SplashScreenHider/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ import type {ReactNode} from 'react';
type SplashScreenHiderProps = {
/** Splash screen has been hidden */
onHide: () => void;

/** Whether the splash screen should be hidden */
shouldHideSplash: boolean;
};

type SplashScreenHiderReturnType = ReactNode;
Expand Down
4 changes: 2 additions & 2 deletions src/libs/telemetry/bootsplashTelemetry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ function addBootsplashBreadcrumb(message: string, data?: Record<string, string>,
}

type BootsplashGateStatus = {
splashScreenState: string;
splashScreenState: string | undefined;
isOnyxMigrated: boolean;
isCheckingPublicRoom: boolean;
hasAttemptedToOpenPublicRoom: boolean;
Expand All @@ -35,7 +35,7 @@ function startBootsplashMonitor(gateStatusRef: React.RefObject<BootsplashGateSta
const appState = AppState.currentState;
Log.info('[BootSplash] splash screen status', false, {appState, splashScreenState: currentGateStatus?.splashScreenState});

if (currentGateStatus?.splashScreenState !== CONST.BOOT_SPLASH_STATE.VISIBLE) {
if (currentGateStatus?.splashScreenState !== CONST.BOOT_SPLASH_STATE.VISIBLE && currentGateStatus?.splashScreenState !== undefined) {
clearInterval(intervalId);
return;
}
Expand Down
Loading