'SplashScreen.show' has already been called for given view controller.
Problem
Summary This warning comes up on initial launch. Also I somtimes still get the ' No native splash screen registered for given view controller. Call 'SplashScreen.show' for given view controller first' error even though i'm upgraded to the latest beta which was supposed to address this issue Managed or bare workflow? If you have made manual changes inside of the `ios/` or `android/` directories in your project, the answer is bare! managed What platform(s) does this occur on? iOS Environment Expo CLI 4.12.6 environment info: System: OS: macOS 11.6 Shell: 5.8 - /bin/zsh Binaries: Node: 14.15.1 - /usr/local/bin/node Yarn: 1.22.10 - /usr/local/bin/yarn npm: 7.8.0 - /usr/local/bin/npm Watchman: 2021.10.04.00 - /usr/local/bin/watchman Managers: CocoaPods: 1.10.1 - /usr/local/bin/pod SDKs: iOS SDK: Platforms: iOS 15.0, DriverKit 20.4, macOS 11.3, tvOS 15.0, watchOS 8.0 IDEs: Android Studio: 4.1 AI-201.8743.12.41.6858069 Xcode: 13.0/13A233 - /usr/bin/xcodebuild npmPackages: expo: ^43.0.0-beta.4 => 43.0.0-beta.4 react: 17.0.1 => 17.0.1 react-dom: 17.0.1 => 17.0.1 react-native: 0.64.2 => 0.64.2 react-native-web: 0.17.1 => 0.17.1 npmGlobalPackages: expo-cli: 4.12.6 Expo Workflow: managed Reproducible demo or steps to reproduce from a blank project https://github.com/haibert/SplashScreenIssue I created a blank project with a custom dev c
Error Output
error even though i'm upgraded to the latest beta which was supposed to address this issue
Unverified for your environment
Select your OS to check compatibility.
1 Fix
Fix Splash Screen Initialization Error in Expo
The warning 'SplashScreen.show has already been called for given view controller' occurs when the splash screen is attempted to be shown multiple times for the same view controller. This can happen if the splash screen is called in a lifecycle method that runs more than once, such as componentDidMount or useEffect without proper checks. The 'No native splash screen registered' error indicates that the splash screen is not properly initialized before being shown.
Awaiting Verification
Be the first to verify this fix
- 1
Update Splash Screen Configuration
Ensure that the splash screen is configured correctly in your app.json or app.config.js. This includes setting the correct image and background color.
jsonjson { "expo": { "splash": { "image": "./assets/splash.png", "resizeMode": "contain", "backgroundColor": "#ffffff" } } } - 2
Modify Splash Screen Call
Ensure that the SplashScreen.show() is called only once during the app's lifecycle. You can use a flag to track if it has already been shown.
typescripttypescript import * as SplashScreen from 'expo-splash-screen'; let splashScreenShown = false; const App = () => { useEffect(() => { const prepare = async () => { if (!splashScreenShown) { await SplashScreen.preventAutoHideAsync(); splashScreenShown = true; } }; prepare(); }, []); return ( <View> {/* Your app content */} </View> ); }; - 3
Hide Splash Screen After Loading
Call SplashScreen.hideAsync() after your app has finished loading to properly dismiss the splash screen.
typescripttypescript const finishLoading = async () => { // Your loading logic await SplashScreen.hideAsync(); }; - 4
Check for Multiple Calls
Add checks to ensure that SplashScreen.show() is not called more than once. You can log a warning if it is called again.
typescripttypescript if (splashScreenShown) { console.warn('SplashScreen.show() has already been called.'); } else { SplashScreen.show(); }
Validation
To confirm the fix worked, run the application and ensure that the splash screen only appears once during the initial launch and disappears correctly after the app has loaded. Check for any warnings in the console regarding multiple calls to SplashScreen.show().
Sign in to verify this fix
Environment
Submitted by
Alex Chen
2450 rep