React Native Intro Slider
React Native Intro Slider is used to introduce your App. It is used to showcase the attractive features of your App, for example, if you are making an E-commerce App then you can showcase the features like best deals and offers, Fast Delivery, vast variety.
To make an Intro Slider we are going to use react-native-app-intro-slider
library. It will provide a AppIntroSlider
component that is very easy to integrate.
Types of Intro Slider
With the help of react-native-app-intro-slider
library you can create 3 different types of intro slider:
1. Simple Intro Slider
You have a choice to provide your custom screen to render similar as FlatList
<AppIntroSlider
slides={Data related to the slides like FlatList}
renderItem={Provide item to render like FlatList}
onDone={Handler for done button click}
showSkipButton={What to show skip button or not, default not}
onSkip={Handler for skip button click}
/>
2. Intro Slider with Button in Centre
All the things will be the same as simple intro slider but with the addition of bottomButton
prop you can center the next button like below
<AppIntroSlider
slides={Data related to the slides like FlatList}
renderItem={Provide item to render like FlatList}
onDone={Handler for done button click}
showSkipButton={What to show skip button or not, default not}
onSkip={Handler for skip button click}
bottomButton
/>
3. Intro Slider with Custom Buttons
Here you have a choice to make the next and done button custom if you want
<AppIntroSlider
slides={Data related to the slides like FlatList}
renderItem={Provide item to render like FlatList}
onDone={Handler for done button click}
renderDoneButton={Provide the custom done button}
renderNextButton={Provide the custom next button}
/>
In this example, we will see how to add an intro slider to your app where the user can swipe through a few slides before getting into the app. Have a look at 3 different types of examples below that contain a few intro slides with next and skip options. The user can navigate through each slide using a swipe gesture or using the next button. So let’s get started.
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.
Installation of Dependency
To use AppIntroSlider
you need to install react-native-app-intro-slider
package. To install this open the terminal and jump into your project
cd ProjectName
Run the following command to install the dependency
npm install react-native-app-intro-slider --save
This command will copy all the dependencies into your node_module directory.
Now below are the code and screenshots of each type of Intro slider.
Code for Simple intro slider
For the simple intro, slider open App.js in any code editor and replace the code with the following code
App.js
// React Native App Intro Slider using AppIntroSlider
// https://aboutreact.com/react-native-app-intro-slider/
// Simple Intro Slider
// import React in our code
import React, {useState} from 'react';
// import all the components we are going to use
import {
SafeAreaView,
StyleSheet,
View,
Text,
Image,
Button,
} from 'react-native';
//import AppIntroSlider to use it
import AppIntroSlider from 'react-native-app-intro-slider';
const App = () => {
const [showRealApp, setShowRealApp] = useState(false);
const onDone = () => {
setShowRealApp(true);
};
const onSkip = () => {
setShowRealApp(true);
};
const RenderItem = ({item}) => {
return (
<View
style={{
flex: 1,
backgroundColor: item.backgroundColor,
alignItems: 'center',
justifyContent: 'space-around',
paddingBottom: 100,
}}>
<Text style={styles.introTitleStyle}>
{item.title}
</Text>
<Image
style={styles.introImageStyle}
source={item.image} />
<Text style={styles.introTextStyle}>
{item.text}
</Text>
</View>
);
};
return (
<>
{showRealApp ? (
<SafeAreaView style={styles.container}>
<View style={styles.container}>
<Text style={styles.titleStyle}>
React Native App Intro Slider using AppIntroSlider
</Text>
<Text style={styles.paragraphStyle}>
This will be your screen when you click Skip
from any slide or Done button at last
</Text>
<Button
title="Show Intro Slider again"
onPress={() => setShowRealApp(false)}
/>
</View>
</SafeAreaView>
) : (
<AppIntroSlider
data={slides}
renderItem={RenderItem}
onDone={onDone}
showSkipButton={true}
onSkip={onSkip}
/>
)}
</>
);
};
export default App;
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
alignItems: 'center',
padding: 10,
justifyContent: 'center',
},
titleStyle: {
padding: 10,
textAlign: 'center',
fontSize: 18,
fontWeight: 'bold',
},
paragraphStyle: {
padding: 20,
textAlign: 'center',
fontSize: 16,
},
introImageStyle: {
width: 200,
height: 200,
},
introTextStyle: {
fontSize: 18,
color: 'white',
textAlign: 'center',
paddingVertical: 30,
},
introTitleStyle: {
fontSize: 25,
color: 'white',
textAlign: 'center',
marginBottom: 16,
fontWeight: 'bold',
},
});
const slides = [
{
key: 's1',
text: 'Best Recharge offers',
title: 'Mobile Recharge',
image: {
uri:
'https://raw.githubusercontent.com/AboutReact/sampleresource/master/intro_mobile_recharge.png',
},
backgroundColor: '#20d2bb',
},
{
key: 's2',
title: 'Flight Booking',
text: 'Upto 25% off on Domestic Flights',
image: {
uri:
'https://raw.githubusercontent.com/AboutReact/sampleresource/master/intro_flight_ticket_booking.png',
},
backgroundColor: '#febe29',
},
{
key: 's3',
title: 'Great Offers',
text: 'Enjoy Great offers on our all services',
image: {
uri:
'https://raw.githubusercontent.com/AboutReact/sampleresource/master/intro_discount.png',
},
backgroundColor: '#22bcb5',
},
{
key: 's4',
title: 'Best Deals',
text: ' Best Deals on all our services',
image: {
uri:
'https://raw.githubusercontent.com/AboutReact/sampleresource/master/intro_best_deals.png',
},
backgroundColor: '#3395ff',
},
{
key: 's5',
title: 'Bus Booking',
text: 'Enjoy Travelling on Bus with flat 100% off',
image: {
uri:
'https://raw.githubusercontent.com/AboutReact/sampleresource/master/intro_bus_ticket_booking.png',
},
backgroundColor: '#f6437b',
},
{
key: 's6',
title: 'Train Booking',
text: ' 10% off on first Train booking',
image: {
uri:
'https://raw.githubusercontent.com/AboutReact/sampleresource/master/intro_train_ticket_booking.png',
},
backgroundColor: '#febe29',
},
];
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 of Simple intro slider
Code for Intro slider with a button in the center
For the intro slider with a button in center open App.js in any code editor and replace the code with the following code. It is the same as the above code just the addition of bottomButton prop.
App.js
// React Native App Intro Slider using AppIntroSlider
// https://aboutreact.com/react-native-app-intro-slider/
// Intro slider with a button in the center
// import React in our code
import React, {useState} from 'react';
// import all the components we are going to use
import {
SafeAreaView,
StyleSheet,
View,
Text,
Image,
Button,
} from 'react-native';
//import AppIntroSlider to use it
import AppIntroSlider from 'react-native-app-intro-slider';
const App = () => {
const [showRealApp, setShowRealApp] = useState(false);
const onDone = () => {
setShowRealApp(true);
};
const onSkip = () => {
setShowRealApp(true);
};
const RenderItem = ({item}) => {
return (
<View
style={{
flex: 1,
backgroundColor: item.backgroundColor,
alignItems: 'center',
justifyContent: 'space-around',
paddingBottom: 100,
}}>
<Text style={styles.introTitleStyle}>
{item.title}
</Text>
<Image
style={styles.introImageStyle}
source={item.image} />
<Text style={styles.introTextStyle}>
{item.text}
</Text>
</View>
);
};
return (
<>
{showRealApp ? (
<SafeAreaView style={styles.container}>
<View style={styles.container}>
<Text style={styles.titleStyle}>
React Native App Intro Slider using AppIntroSlider
</Text>
<Text style={styles.paragraphStyle}>
This will be your screen when you click Skip
from any slide or Done button at last
</Text>
<Button
title="Show Intro Slider again"
onPress={() => setShowRealApp(false)}
/>
</View>
</SafeAreaView>
) : (
<AppIntroSlider
data={slides}
renderItem={RenderItem}
onDone={onDone}
showSkipButton={true}
onSkip={onSkip}
bottomButton
/>
)}
</>
);
};
export default App;
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
alignItems: 'center',
padding: 10,
justifyContent: 'center',
},
titleStyle: {
padding: 10,
textAlign: 'center',
fontSize: 18,
fontWeight: 'bold',
},
paragraphStyle: {
padding: 20,
textAlign: 'center',
fontSize: 16,
},
introImageStyle: {
width: 200,
height: 200,
},
introTextStyle: {
fontSize: 18,
color: 'white',
textAlign: 'center',
paddingVertical: 30,
},
introTitleStyle: {
fontSize: 25,
color: 'white',
textAlign: 'center',
marginBottom: 16,
fontWeight: 'bold',
},
});
const slides = [
{
key: 's1',
text: 'Best Recharge offers',
title: 'Mobile Recharge',
image: {
uri:
'https://raw.githubusercontent.com/AboutReact/sampleresource/master/intro_mobile_recharge.png',
},
backgroundColor: '#20d2bb',
},
{
key: 's2',
title: 'Flight Booking',
text: 'Upto 25% off on Domestic Flights',
image: {
uri:
'https://raw.githubusercontent.com/AboutReact/sampleresource/master/intro_flight_ticket_booking.png',
},
backgroundColor: '#febe29',
},
{
key: 's3',
title: 'Great Offers',
text: 'Enjoy Great offers on our all services',
image: {
uri:
'https://raw.githubusercontent.com/AboutReact/sampleresource/master/intro_discount.png',
},
backgroundColor: '#22bcb5',
},
{
key: 's4',
title: 'Best Deals',
text: ' Best Deals on all our services',
image: {
uri:
'https://raw.githubusercontent.com/AboutReact/sampleresource/master/intro_best_deals.png',
},
backgroundColor: '#3395ff',
},
{
key: 's5',
title: 'Bus Booking',
text: 'Enjoy Travelling on Bus with flat 100% off',
image: {
uri:
'https://raw.githubusercontent.com/AboutReact/sampleresource/master/intro_bus_ticket_booking.png',
},
backgroundColor: '#f6437b',
},
{
key: 's6',
title: 'Train Booking',
text: ' 10% off on first Train booking',
image: {
uri:
'https://raw.githubusercontent.com/AboutReact/sampleresource/master/intro_train_ticket_booking.png',
},
backgroundColor: '#febe29',
},
];
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 of Intro slider with a button in the center
Code for Intro Slider with Custom Buttons
For the Intro slider with custom buttons, we need some custom buttons with an icon so we need vector icons or the Ionicons so as per your wish you can choose any of them, for now, here I am using react-native-vector-icons
, To install it run
npm install react-native-vector-icons --save
Please visit Example to Use React Native Vector Icons for further instructions to complete the installation of Vector Icons.
Now we need to install pods
npx pod-install
Now Open App.js in any code editor and replace the code with the following code.
App.js
// React Native App Intro Slider using AppIntroSlider
// https://aboutreact.com/react-native-app-intro-slider/
// Intro slider with Custom Buttons
// import React in our code
import React, {useState} from 'react';
// import all the components we are going to use
import {
SafeAreaView,
StyleSheet,
View,
Text,
Image,
Button,
} from 'react-native';
//import AppIntroSlider to use it
import AppIntroSlider from 'react-native-app-intro-slider';
//import AppIntroSlider to use it
import Icon from 'react-native-vector-icons/FontAwesome';
const App = () => {
const [showRealApp, setShowRealApp] = useState(false);
const onDone = () => {
setShowRealApp(true);
};
const RenderNextButton = () => {
return (
<View style={styles.buttonCircle}>
<Icon
name="arrow-right"
color="rgba(255, 255, 255, .9)"
size={24}
/>
</View>
);
};
const RenderDoneButton = () => {
return (
<View style={styles.buttonCircle}>
<Icon
name="check"
color="rgba(255, 255, 255, .9)"
size={24}
/>
</View>
);
};
const RenderItem = ({item}) => {
return (
<View
style={{
flex: 1,
backgroundColor: item.backgroundColor,
alignItems: 'center',
justifyContent: 'space-around',
paddingBottom: 100,
}}>
<Text style={styles.introTitleStyle}>
{item.title}
</Text>
<Image
style={styles.introImageStyle}
source={item.image} />
<Text style={styles.introTextStyle}>
{item.text}
</Text>
</View>
);
};
return (
<>
{showRealApp ? (
<SafeAreaView style={styles.container}>
<View style={styles.container}>
<Text style={styles.titleStyle}>
React Native App Intro Slider using AppIntroSlider
</Text>
<Text style={styles.paragraphStyle}>
This will be your screen when you click Skip
from any slide or Done button at last
</Text>
<Button
title="Show Intro Slider again"
onPress={() => setShowRealApp(false)}
/>
</View>
</SafeAreaView>
) : (
<AppIntroSlider
data={slides}
renderItem={RenderItem}
onDone={onDone}
renderDoneButton={RenderDoneButton}
renderNextButton={RenderNextButton}
/>
)}
</>
);
};
export default App;
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
alignItems: 'center',
padding: 10,
justifyContent: 'center',
},
titleStyle: {
padding: 10,
textAlign: 'center',
fontSize: 18,
fontWeight: 'bold',
},
paragraphStyle: {
padding: 20,
textAlign: 'center',
fontSize: 16,
},
introImageStyle: {
width: 200,
height: 200,
},
introTextStyle: {
fontSize: 18,
color: 'white',
textAlign: 'center',
paddingVertical: 30,
},
introTitleStyle: {
fontSize: 25,
color: 'white',
textAlign: 'center',
marginBottom: 16,
fontWeight: 'bold',
},
buttonCircle: {
width: 40,
height: 40,
backgroundColor: 'rgba(0, 0, 0, .2)',
borderRadius: 20,
justifyContent: 'center',
alignItems: 'center',
},
});
const slides = [
{
key: 's1',
text: 'Best Recharge offers',
title: 'Mobile Recharge',
image: {
uri:
'https://raw.githubusercontent.com/AboutReact/sampleresource/master/intro_mobile_recharge.png',
},
backgroundColor: '#20d2bb',
},
{
key: 's2',
title: 'Flight Booking',
text: 'Upto 25% off on Domestic Flights',
image: {
uri:
'https://raw.githubusercontent.com/AboutReact/sampleresource/master/intro_flight_ticket_booking.png',
},
backgroundColor: '#febe29',
},
{
key: 's3',
title: 'Great Offers',
text: 'Enjoy Great offers on our all services',
image: {
uri:
'https://raw.githubusercontent.com/AboutReact/sampleresource/master/intro_discount.png',
},
backgroundColor: '#22bcb5',
},
{
key: 's4',
title: 'Best Deals',
text: ' Best Deals on all our services',
image: {
uri:
'https://raw.githubusercontent.com/AboutReact/sampleresource/master/intro_best_deals.png',
},
backgroundColor: '#3395ff',
},
{
key: 's5',
title: 'Bus Booking',
text: 'Enjoy Travelling on Bus with flat 100% off',
image: {
uri:
'https://raw.githubusercontent.com/AboutReact/sampleresource/master/intro_bus_ticket_booking.png',
},
backgroundColor: '#f6437b',
},
{
key: 's6',
title: 'Train Booking',
text: ' 10% off on first Train booking',
image: {
uri:
'https://raw.githubusercontent.com/AboutReact/sampleresource/master/intro_train_ticket_booking.png',
},
backgroundColor: '#febe29',
},
];
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 of Intro Slider with Custom Buttons
Output in Online Emulator
That was the React Native Intro Slider. If you have any doubts or you 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. 🙂
Hello,
How do I open only once?
You have to store a flag in AsyncStorage and then you have to check for the flag. For example When you launch the activity you have to check for the value 1 in AsyncStorage if it is not set then show the screen, after showing the Intro Slider set the AsyncStorage with the value 1 and next time it will skip the Intro Slider.
You can visit the below Example to store the flag in AsyncStorage
https://aboutreact.com/react-native-asyncstorage/
And if i want to put an Icon from native-base or vector-icons in slides into image: {} instead of un image??
Instead of using Image in RenderItem you can use Icon
How can I change slider dots colour ?
How can I remove next, done buttons?