Skip to content

Commit 062209b

Browse files
JulesssssOSBotify
authored andcommitted
Merge pull request #86659 from software-mansion-labs/revert-86226-war-in/improve-bootsplash-performance
Revert "performance: Always mount `SplashScreenHider` and control hide timing via prop instead of conditional rendering" (cherry picked from commit 9bed498) (cherry-picked to staging by jasperhuangg)
1 parent dacdb08 commit 062209b

4 files changed

Lines changed: 11 additions & 32 deletions

File tree

src/Expensify.tsx

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -199,9 +199,7 @@ function Expensify() {
199199
Navigation.setIsNavigationReady();
200200
}, []);
201201

202-
const [splashHideHasBeenCalled, setSplashHideHasBeenCalled] = useState(false);
203202
const onSplashHide = useCallback(() => {
204-
setSplashHideHasBeenCalled(true);
205203
setSplashScreenState(CONST.BOOT_SPLASH_STATE.HIDDEN);
206204
endSpan(CONST.TELEMETRY.SPAN_OD_ND_TRANSITION);
207205
endSpan(CONST.TELEMETRY.SPAN_APP_STARTUP);
@@ -294,12 +292,7 @@ function Expensify() {
294292
initialUrl={initialUrl}
295293
/>
296294
)}
297-
{!splashHideHasBeenCalled && (
298-
<SplashScreenHider
299-
shouldHideSplash={shouldHideSplash}
300-
onHide={onSplashHide}
301-
/>
302-
)}
295+
{shouldHideSplash && <SplashScreenHider onHide={onSplashHide} />}
303296
</>
304297
);
305298
}

src/components/SplashScreenHider/index.native.tsx

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {useEffect, useEffectEvent, useRef} from 'react';
1+
import {useCallback, 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({shouldHideSplash, onHide}: SplashScreenHiderProps): SplashScreenHiderReturnType {
12+
function SplashScreenHider({onHide = () => {}}: SplashScreenHiderProps): SplashScreenHiderReturnType {
1313
const styles = useThemeStyles();
1414
const logoSizeRatio = BootSplash.logoSizeRatio || 1;
1515

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

2626
const hideHasBeenCalled = useRef(false);
27-
const hide = useEffectEvent(() => {
27+
28+
const hide = useCallback(() => {
2829
// hide can only be called once
2930
if (hideHasBeenCalled.current) {
3031
return;
@@ -51,19 +52,13 @@ function SplashScreenHider({shouldHideSplash, onHide}: SplashScreenHiderProps):
5152
),
5253
);
5354
});
54-
});
55-
56-
useEffect(() => {
57-
if (!shouldHideSplash) {
58-
return;
59-
}
60-
hide();
61-
}, [shouldHideSplash]);
55+
}, [opacity, scale, onHide]);
6256

6357
return (
6458
<Reanimated.View style={[StyleSheet.absoluteFill, styles.splashScreenHider, opacityStyle]}>
6559
<Reanimated.View style={scaleStyle}>
6660
<ImageSVG
61+
onLoadEnd={hide}
6762
contentFit="fill"
6863
style={{width: 100 * logoSizeRatio, height: 100 * logoSizeRatio}}
6964
src={Logo}

src/components/SplashScreenHider/index.tsx

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

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

1610
return null;
1711
}

src/components/SplashScreenHider/types.ts

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

33
type SplashScreenHiderProps = {
4-
/** Whether the splash screen should be hidden */
5-
shouldHideSplash: boolean;
6-
74
/** Splash screen has been hidden */
85
onHide: () => void;
96
};

0 commit comments

Comments
 (0)