SplashScreen.show() not working on app state change.
See original GitHub issueI need to show a splash screen when my app state was changed to inactive
or background
, but unfortunately, it’s not working.
Anyone faced with this issue?
react-native info results:
System:
OS: macOS 12.2.1
CPU: (8) x64 Intel(R) Core(TM) i5-1038NG7 CPU @ 2.00GHz
Memory: 61.12 MB / 16.00 GB
Shell: 5.8 - /bin/zsh
Binaries:
Node: 14.17.6 - ~/.nvm/versions/node/v14.17.6/bin/node
Yarn: 1.22.17 - ~/.nvm/versions/node/v14.17.6/bin/yarn
npm: 8.1.4 - ~/.nvm/versions/node/v14.17.6/bin/npm
Watchman: Not Found
Managers:
CocoaPods: 1.11.2 - /usr/local/bin/pod
SDKs:
iOS SDK:
Platforms: DriverKit 21.0.1, iOS 15.0, macOS 12.0, tvOS 15.0, watchOS 8.0
Android SDK:
API Levels: 30, 32
Build Tools: 30.0.2, 32.0.0, 32.1.0, 33.0.0
System Images: android-31 | Google APIs Intel x86 Atom_64
Android NDK: Not Found
IDEs:
Android Studio: 2021.1 AI-211.7628.21.2111.8193401
Xcode: 13.1/13A1030d - /usr/bin/xcodebuild
Languages:
Java: 17.0.2 - /usr/bin/javac
npmPackages:
@react-native-community/cli: Not Found
react: ^17.0.2 => 17.0.2
react-native: ^0.67.3 => 0.67.3
react-native-macos: Not Found
npmGlobalPackages:
*react-native*: Not Found
I’m using the following packages versions:
Package Name. | Version |
---|---|
react-native-splash-screen | 3.3.0 |
react | 17.0.2 |
react-native | 0.67.3 |
The issue occurs on both
platforms.
My code:
import React, { useEffect, useCallback } from "react";
import { AppState, AppStateStatus } from "react-native";
import SplashScreen from "react-native-splash-screen";
import Navigation from "./Navigation";
function App() {
const onAppStateChange = useCallback((nextAppState: AppStateStatus) => {
if (nextAppState !== "active") {
SplashScreen.show(); // <--- not working
} else {
SplashScreen.hide();
}
}, []);
useEffect(() => {
SplashScreen.hide();
const subscription = AppState.addEventListener("change", onAppStateChange);
return () => {
subscription.remove();
};
}, []);
return <Navigation />;
}
export default App;
Issue Analytics
- State:
- Created 2 years ago
- Reactions:4
- Comments:7
Top Results From Across the Web
React Native Splash Screen: Unfortunately <APP> has ...
React Native Splash Screen: Unfortunately <APP> has stopped after SplashScreen.show() ... I'm building a React Native App and I'm using React ...
Read more >SplashScreen - Expo Documentation
The SplashScreen module from the expo-splash-screen library is used to tell the splash screen to remain visible until it has been explicitly told...
Read more >Display a splash screen for more time - UWP applications
Make sure to register your Window.SizeChanged handler ( ExtendedSplash_OnResize in the example) in your class constructor so that your app ...
Read more >Splash Screen Tutorial for Android - Kodeco
Note: Running the app through Android Studio is not the same as launching the ... In onCreate() , replace TODO: Install Splash Screen...
Read more >How to add a splash screen to a React Native app
At first, it shows only a blank View with the background color we picked. · The image fades in · We wait in...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
i tried to the the same thing recently and had the same problem.
so for your specific problem i would say you should just remove all the AppState functionality. is there a specific reason you NEED to show the splash screen when the appstate changes? probably not. i personally just call
.hide()
once and that is it, i have never had to use.show()
.so i would just simplify it:
No.
show() getting deprecated and new android version doesn’t work good with onPause.
Looks like react native needs to upgrade to kotlin or maybe a plugin kotlin with co-routines would work.