diff --git a/packages/react-native-storybook/src/getStorybook/getStorybook.tsx b/packages/react-native-storybook/src/getStorybook/getStorybook.tsx index 846eb37..a6a35d0 100644 --- a/packages/react-native-storybook/src/getStorybook/getStorybook.tsx +++ b/packages/react-native-storybook/src/getStorybook/getStorybook.tsx @@ -1,11 +1,11 @@ -import { useEffect, useMemo, useRef, useState, ReactElement } from 'react'; +import { useEffect, useMemo, useState, ReactElement } from 'react'; import { StyleSheet, Text, View } from 'react-native'; import { SafeAreaProvider } from 'react-native-safe-area-context'; import { RunnerBridge, SherloModule } from '../helpers'; import { Snapshot, StorybookParams, StorybookView } from '../types'; import { SherloContext } from './contexts'; import generateStorybookComponent from './generateStorybookComponent'; -import { useOriginalMode, useStoryEmitter, useTestingMode } from './hooks'; +import { useHideSplashScreen, useOriginalMode, useStoryEmitter, useTestingMode } from './hooks'; import { setupErrorSilencing } from './utils'; import { Layout } from './components'; @@ -32,6 +32,8 @@ function getStorybook(view: StorybookView, params?: StorybookParams): () => Reac }, }); + useHideSplashScreen(); + // Testing mode useTestingMode(view, mode, setSnapshots, setTestedIndex, RunnerBridge); diff --git a/packages/react-native-storybook/src/getStorybook/hooks/index.ts b/packages/react-native-storybook/src/getStorybook/hooks/index.ts index 5641c9b..5d61df0 100644 --- a/packages/react-native-storybook/src/getStorybook/hooks/index.ts +++ b/packages/react-native-storybook/src/getStorybook/hooks/index.ts @@ -1,3 +1,4 @@ +export { default as useHideSplashScreen } from './useHideSplashScreen'; export { default as useOriginalMode } from './useOriginalMode'; export { default as useStoryEmitter } from './useStoryEmitter'; export { default as useTestingMode } from './useTestingMode'; diff --git a/packages/react-native-storybook/src/getStorybook/hooks/useHideSplashScreen.ts b/packages/react-native-storybook/src/getStorybook/hooks/useHideSplashScreen.ts new file mode 100644 index 0000000..19d27af --- /dev/null +++ b/packages/react-native-storybook/src/getStorybook/hooks/useHideSplashScreen.ts @@ -0,0 +1,51 @@ +import { useEffect } from 'react'; + +const hideSplashScreens: (() => void)[] = []; + +try { + const ExpoSplashScreen = require('expo-splash-screen'); + + hideSplashScreens.push(() => { + try { + ExpoSplashScreen.hide(); + } catch { + try { + ExpoSplashScreen.hideAsync(); + } catch {} + } + }); +} catch { + // No expo-splash-scree package available +} + +try { + const RNSplashScreen = require('react-native-splash-screen'); + + hideSplashScreens.push(() => { + try { + RNSplashScreen.hide(); + } catch {} + }); +} catch { + // No react-native-splash-screen package available +} + +try { + const BootSplash = require('react-native-bootsplash'); + + hideSplashScreens.push(() => { + try { + BootSplash.hide(); + } catch {} + }); +} catch { + // No react-native-bootsplash package available +} + +export function useHideSplashScreen() { + useEffect(() => { + hideSplashScreens.forEach((hide) => hide()); + }, []); +} + +export default useHideSplashScreen;