Skip to content

Commit 490a3c5

Browse files
committed
fix: trigger hide on shouldHideSplash change
1 parent 1def202 commit 490a3c5

3 files changed

Lines changed: 25 additions & 10 deletions

File tree

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({onHide, shouldHideSplash}: 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: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
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({onHide, shouldHideSplash}: SplashScreenHiderProps): SplashScreenHiderReturnType {
6+
const hide = useEffectEvent(() => {
77
BootSplash.hide().then(() => onHide());
8-
}, [onHide]);
8+
});
9+
10+
useEffect(() => {
11+
if (!shouldHideSplash) {
12+
return;
13+
}
14+
hide();
15+
}, [shouldHideSplash]);
916

1017
return null;
1118
}

src/components/SplashScreenHider/types.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ import type {ReactNode} from 'react';
33
type SplashScreenHiderProps = {
44
/** Splash screen has been hidden */
55
onHide: () => void;
6+
7+
/** Whether the splash screen should be hidden */
8+
shouldHideSplash: boolean;
69
};
710

811
type SplashScreenHiderReturnType = ReactNode;

0 commit comments

Comments
 (0)