Skip to content

Commit 264543e

Browse files
authored
Merge pull request Expensify#86226 from software-mansion-labs/war-in/improve-bootsplash-performance
performance: Always mount `SplashScreenHider` and control hide timing via prop instead of conditional rendering
2 parents 00ddfe5 + e3c1764 commit 264543e

4 files changed

Lines changed: 32 additions & 11 deletions

File tree

src/Expensify.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,9 @@ function Expensify() {
181181
Navigation.setIsNavigationReady();
182182
}, []);
183183

184+
const [splashHideHasBeenCalled, setSplashHideHasBeenCalled] = useState(false);
184185
const onSplashHide = useCallback(() => {
186+
setSplashHideHasBeenCalled(true);
185187
setSplashScreenState(CONST.BOOT_SPLASH_STATE.HIDDEN);
186188
endSpan(CONST.TELEMETRY.SPAN_OD_ND_TRANSITION);
187189
endSpan(CONST.TELEMETRY.SPAN_APP_STARTUP);
@@ -285,7 +287,12 @@ function Expensify() {
285287
initialUrl={initialUrl}
286288
/>
287289
)}
288-
{shouldHideSplash && <SplashScreenHider onHide={onSplashHide} />}
290+
{!splashHideHasBeenCalled && (
291+
<SplashScreenHider
292+
shouldHideSplash={shouldHideSplash}
293+
onHide={onSplashHide}
294+
/>
295+
)}
289296
</>
290297
);
291298
}

src/components/SplashScreenHider/index.native.tsx

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {useCallback, useRef} from 'react';
1+
import {useEffect, useEffectEvent, useRef} from 'react';
22
import type {ViewStyle} from 'react-native';
33
import {StyleSheet} from 'react-native';
44
import Reanimated, {Easing, useAnimatedStyle, useSharedValue, withTiming} from 'react-native-reanimated';
@@ -9,7 +9,7 @@ import useThemeStyles from '@hooks/useThemeStyles';
99
import BootSplash from '@libs/BootSplash';
1010
import type {SplashScreenHiderProps, SplashScreenHiderReturnType} from './types';
1111

12-
function SplashScreenHider({onHide = () => {}}: SplashScreenHiderProps): SplashScreenHiderReturnType {
12+
function SplashScreenHider({shouldHideSplash, onHide}: SplashScreenHiderProps): SplashScreenHiderReturnType {
1313
const styles = useThemeStyles();
1414
const logoSizeRatio = BootSplash.logoSizeRatio || 1;
1515

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

2626
const hideHasBeenCalled = useRef(false);
27-
28-
const hide = useCallback(() => {
27+
const hide = useEffectEvent(() => {
2928
// hide can only be called once
3029
if (hideHasBeenCalled.current) {
3130
return;
@@ -52,13 +51,19 @@ function SplashScreenHider({onHide = () => {}}: SplashScreenHiderProps): SplashS
5251
),
5352
);
5453
});
55-
}, [opacity, scale, onHide]);
54+
});
55+
56+
useEffect(() => {
57+
if (!shouldHideSplash) {
58+
return;
59+
}
60+
hide();
61+
}, [shouldHideSplash]);
5662

5763
return (
5864
<Reanimated.View style={[StyleSheet.absoluteFill, styles.splashScreenHider, opacityStyle]}>
5965
<Reanimated.View style={scaleStyle}>
6066
<ImageSVG
61-
onLoadEnd={hide}
6267
contentFit="fill"
6368
style={{width: 100 * logoSizeRatio, height: 100 * logoSizeRatio}}
6469
src={Logo}

src/components/SplashScreenHider/index.tsx

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
1-
import {useEffect} from 'react';
1+
import {useEffect, useEffectEvent} from 'react';
22
import BootSplash from '@libs/BootSplash';
33
import type {SplashScreenHiderProps, SplashScreenHiderReturnType} from './types';
44

5-
function SplashScreenHider({onHide = () => {}}: SplashScreenHiderProps): SplashScreenHiderReturnType {
6-
useEffect(() => {
5+
function SplashScreenHider({shouldHideSplash, onHide}: SplashScreenHiderProps): SplashScreenHiderReturnType {
6+
const hide = useEffectEvent(() => {
77
BootSplash.hide().then(() => onHide());
8-
}, [onHide]);
8+
});
9+
useEffect(() => {
10+
if (!shouldHideSplash) {
11+
return;
12+
}
13+
hide();
14+
}, [shouldHideSplash]);
915

1016
return null;
1117
}

src/components/SplashScreenHider/types.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import type {ReactNode} from 'react';
22

33
type SplashScreenHiderProps = {
4+
/** Whether the splash screen should be hidden */
5+
shouldHideSplash: boolean;
6+
47
/** Splash screen has been hidden */
58
onHide: () => void;
69
};

0 commit comments

Comments
 (0)