React Native Animated Splash Screen
This is an Example of an Animated Splash Screen in React Native. The splash screen is the first screen that appears in front of the user when they interact with your application so to make an impactful impression you can create an Animated Splash Screen. This example contains a simple splash screen with some animation in which we will show the image first and then the name of the app.
If you want to explore more then you can also visit Example of Animation Splash Screen with Zoom Effect.
To Make a React Native App
Getting started with React Native will help you to know more about the way you can make a React Native project. We are going to use react native command line interface to make our React Native App.
If you have previously installed a global react-native-cli package, please remove it as it may cause unexpected issues:
npm uninstall -g react-native-cli @react-native-community/cli
Run the following commands to create a new React Native project
npx react-native init ProjectName
If you want to start a new project with a specific React Native version, you can use the --version argument:
npx react-native init ProjectName --version X.XX.X
Note If the above command is failing, you may have old version of react-native
or react-native-cli
installed globally on your pc. Try uninstalling the cli and run the cli using npx.
This will make a project structure with an index file named App.js in your project directory.
Code
Now Open App.js in any code editor and replace the code with the following code
App.js
// Example of Animated Splash Screen in React Native
// https://aboutreact.com/animated-splash-screen/
// import React in our code
import React, {useState, useEffect} from 'react';
// import all the components we are going to use
import {View, Text, Image, StyleSheet} from 'react-native';
const App = () => {
const [align, setAlign] = useState('center');
const [alignsecond, setAlignsecond] = useState(false);
useEffect(() => {
let myTimeout = setTimeout(() => {
setAlign('flex-start'), setAlignsecond(true);
}, 3000);
return () => clearTimeout(myTimeout);
}, []);
return (
<View
style={[
styles.container,
{justifyContent: align}
]}>
<Image
source={{
uri:
'https://raw.githubusercontent.com/AboutReact/sampleresource/master/react_logo.png',
}}
style={{width: 100, height: 100}}
/>
{!alignsecond ? null : (
<View style={{margin: 10}}>
<Text
style={{
color: '#114998',
fontSize: 30,
fontWeight: 'bold',
}}>
About React
</Text>
</View>
)}
</View>
);
};
export default App;
const styles = StyleSheet.create({
container: {
flex: 1,
alignItems: 'center',
flexDirection: 'row',
marginHorizontal: 40,
},
});
To Run the React Native App
Open the terminal again and jump into your project using.
cd ProjectName
1. Start Metro Bundler
First, you will need to start Metro, the JavaScript bundler that ships with React Native. To start Metro bundler run following command
npx react-native start
Once you start Metro Bundler it will run forever on your terminal until you close it. Let Metro Bundler run in its own terminal. Open a new terminal and run the application.
2. Start React Native Application
To run the project on an Android Virtual Device or on real debugging device
npx react-native run-android
or on the iOS Simulator by running (macOS only)
npx react-native run-ios
Output Screenshots
Output in Online Emulator
This is how you can make an animated splash screen in React Native. If you have any doubts or want to share something about the topic you can comment below or contact us here. There will be more posts coming soon. Stay tuned!
Hope you liked it. 🙂
a good and helpful post
Hi Snehal, I’m learning React native through your posts only,it’s very helpful to a newbies like me.
How can we show multiple images sliding one by one in splash screen. Could you please help me in this situation.
Can you please look into it https://aboutreact.com/react-native-app-intro-slider/
Hello.
Can you create some tutorials on Liquid Swipe same as like
https://www.youtube.com/watch?v=gLopy2MCAqM
Also like Fluid Transition or Shared Element Transition
https://github.com/IjzerenHein/react-navigation-shared-element/tree/navigation-v5
Its look so nice after all this animation. I am struggling to implement all this.
Nice suggestion, Will look into it.
Thanks for this tutorial. I’m enjoying your website. After following the steps in this tutorial line by line, I got this warning message ‘Warning: Can’t perform a React state update on an unmounted component. This is a no-op, but it indicates a memory leak in your application. To fix, cancel all subscriptions and asynchronous tasks in a useEffect cleanup function’. How can I fit it please.
Updated the code for the same.