Table of Contents
Animated Splash Screen with Zoom Effect
This is an example to make an Animation Splash Screen with Zoom Effect for Android and IOS. 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. In this example, we will see make a zoom effect on the Splash Screen.
If you want to see other examples of Splash Screen You can also visit Example of Animated Splash Screen in React Native.
Note: We are not going to use any external library to make an animated screen. We are going to use an Animated component provided by React Native.
In this example, we will create a Screen having a background image with a zoom effect and a floating image over it. You can replace it with your application logo and banner and make some cool stuff.
How to make an Animation Effect?
To make the zoom effect, the first step is to initialize the height and width of the background image.
const height = new Animated.Value(600),
const width = new Animated.Value(350),
Then define the animation timing and the final value you want to make the zoom to.
Animated.timing(
width, // The animated value to drive
{
toValue: 360, // Animate to opacity: 1 (opaque)
duration: 450, // Make it take a while
}
).start(); // Starts the animation
Animated.timing(
height, // The animated value to drive
{
toValue: 750, // Animate to opacity: 1 (opaque)
duration: 10000, // Make it take a while
}
).start(); // Starts the animation
You can see the full example code below.
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 for Animated Splash Screen with Zoom Effect
Now Open App.js in any code editor and replace the code with the following code
App.js
// Example of Animation Splash Screen with Zoom Effect
// https://aboutreact.com/animation-splash-screen-with-zoom-effect/
// Import React
import React, {useEffect} from 'react';
// Import required components
import {View, Text, StyleSheet, Image, Animated} from 'react-native';
const App = () => {
const width = new Animated.Value(360);
const height = new Animated.Value(600);
const SITE_BANNER_VERTICAL_IMAGE =
'https://raw.githubusercontent.com/AboutReact/sampleresource/master/site_banner_vertical.png';
const SAMPLE_APP_LOGO =
'https://raw.githubusercontent.com/AboutReact/sampleresource/master/react_logo.png';
useEffect(() => {
Animated.timing(
width, // The animated value to drive
{
toValue: 360, // Animate to opacity: 1 (opaque)
duration: 450, // Make it take a while
useNativeDriver: false,
},
).start(); // Starts the animation
Animated.timing(
height, // The animated value to drive
{
toValue: 750, // Animate to opacity: 1 (opaque)
duration: 10000, // Make it take a while
useNativeDriver: false,
},
).start(); // Starts the animation
}, []);
return (
<View style={styles.container}>
<Animated.Image
source={{uri: SITE_BANNER_VERTICAL_IMAGE}}
style={{
width: width,
height: height,
position: 'absolute',
}}
/>
<View style={styles.logoContainer}>
<Image source={{uri: SAMPLE_APP_LOGO}} style={styles.logo} />
<Text style={styles.textStyle}>
Example of Animation Splash Screen with Zoom Effect
</Text>
</View>
</View>
);
};
export default App;
const styles = StyleSheet.create({
container: {
flex: 1,
position: 'relative',
backgroundColor: '#2F7ECC',
},
logoContainer: {
flex: 1,
alignItems: 'center',
paddingTop: 48,
backgroundColor: 'rgba(11, 56, 82, 0.3)',
},
logo: {
width: 100,
height: 100,
},
textStyle: {
fontSize: 18,
color: 'white',
textAlign: 'center',
},
});
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 create an Animation Splash Screen with Zoom Effect for Android and IOS. 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. 🙂