About The Tutorial –
In this tutorial, we are going to learn “How To Show App Intro Slider in React Native“.
What is app intro functionality –
We use the app intro slider to show the basic information about the app the first time when you start the app.
So it’s basically used for introducing your app. here you showcase your attractive feature.
To create an app Intro Slider we are going to use the react-native-app-intro-slider
library. here you find a AppIntroSlider
component that is very easy to integrate.
So these are the 3 – types of app intro slider that meet your requirement implement that one in your app.
So let’s start to implement these.
Step 1 – Installation
First, we need to install the third-party npm plugin.
npm install react-native-app-intro-slider
or
yarn add react-native-app-intro-slider
Step 2 – Import
After installing the npm plugin successfully, now we need to import that plugin into your file.
import AppIntroSlider from 'react-native-app-intro-slider';
Step 3 – Set up the data
Now we are going to create a formate for data, which we show in this app intro, you can customize it based on your requirements.
const slides = [
{
key: 1,
title: 'Title 1',
text: 'Description.\nSay something cool',
image: require('./assets/1.jpg'),
backgroundColor: '#59b2ab',
},
{
key: 2,
title: 'Title 2',
text: 'Other cool stuff',
image: require('./assets/2.jpg'),
backgroundColor: '#febe29',
},
{
key: 3,
title: 'Rocket guy',
text: 'I\'m already out of descriptions\n\nLorem ipsum bla bla bla',
image: require('./assets/3.jpg'),
backgroundColor: '#22bcb5',
}
];
Step 4 – Setup States
Here you need to define a variable based on that variable condition you show the slider.
this.state = {
showRealApp: false
}
Step 5 – Design the view
Now we set up the view for showing the app slider.
render() {
if (this.state.showRealApp) {
return <App />;
} else {
return <AppIntroSlider renderItem={this._renderItem} data={slides} onDone={this._onDone}/>;
}
}
Step 6 – Complete code
Here we see the complete code of all three types of intro sliders.
Types of Intro Slider –
This third-party library provides you 3 types of sliders.
1. Simple Intro Slider – Basic
import React from 'react';
import { StyleSheet } from 'react-native';
import AppIntroSlider from 'react-native-app-intro-slider';
const slides = [
{
key: 1,
title: 'Title 1',
text: 'Description.\nSay something cool',
image: require('./assets/1.jpg'),
backgroundColor: '#59b2ab',
},
{
key: 2,
title: 'Title 2',
text: 'Other cool stuff',
image: require('./assets/2.jpg'),
backgroundColor: '#febe29',
},
{
key: 3,
title: 'Rocket guy',
text: 'I\'m already out of descriptions\n\nLorem ipsum bla bla bla',
image: require('./assets/3.jpg'),
backgroundColor: '#22bcb5',
}
];
export default class App extends React.Component {
this.state = {
showRealApp: false
}
_renderItem = ({ item }) => {
return (
<View style={styles.slide}>
<Text style={styles.title}>{item.title}</Text>
<Image source={item.image} />
<Text style={styles.text}>{item.text}</Text>
</View>
);
}
_onDone = () => {
// User finished the introduction. Show real app through
// navigation or simply by controlling state
this.setState({ showRealApp: true });
}
render() {
if (this.state.showRealApp) {
return <App />;
} else {
return <AppIntroSlider renderItem={this._renderItem} data={slides} onDone={this._onDone}/>;
}
}
}
2. Configuring buttons – showSkipButton
Here is one twist, you need to show the icon so we need to install the third party for the icon.
npm i react-native-vector-icons
import React from 'react';
import Icon from 'react-native-vector-icons/Ionicons';
import { StyleSheet, View } from 'react-native';
import AppIntroSlider from 'react-native-app-intro-slider';
const styles = StyleSheet.create({
buttonCircle: {
width: 40,
height: 40,
backgroundColor: 'rgba(0, 0, 0, .2)',
borderRadius: 20,
justifyContent: 'center',
alignItems: 'center',
},
//[...]
});
// slides = [...]
export default class App extends React.Component {
_renderItem = ({ item }) => {
return (
<View style={styles.slide}>
<Text style={styles.title}>{item.title}</Text>
<Image source={item.image} />
<Text style={styles.text}>{item.text}</Text>
</View>
);
}
_renderNextButton = () => {
return (
<View style={styles.buttonCircle}>
<Ion
name="md-arrow-round-forward"
color="rgba(255, 255, 255, .9)"
size={24}
/>
</View>
);
};
_renderDoneButton = () => {
return (
<View style={styles.buttonCircle}>
<Ion
name="md-checkmark"
color="rgba(255, 255, 255, .9)"
size={24}
/>
</View>
);
};
render() {
return (
<AppIntroSlider
data={slides}
renderDoneButton={this._renderDoneButton}
renderNextButton={this._renderNextButton}
/>
);
}
}
3. Custom Buttons – bottomButton
andshowSkipButton
Step 7 – Run the app
Now you can run your app and see your sliders.
react-native run-android
react-native run-ios
Step 8 – Props
Name | Type | Default | Description |
---|---|---|---|
data | object | None, required | An array of objects (they should either contain a unique key -prop or you should pass a keyExtractor -function to the component) |
renderItem | function | None, required | FlatList’s renderItem. Receives ({item, index, dimensions}) where dimensions contains height and width of the slides |
onSlideChange | function | void | Called when user goes changes slide (by swiping or pressing next/prev). Function called with arguments (index: number, lastIndex: number) |
renderPagination | function | Function to render a custom pagination/button component on top of slides. Receives the index of the currently active slide | |
onDone | function | void | Called when user ends the introduction by pressing the done button |
onSkip | function | Scrolls to the end | Called when user presses the skip button |
bottomButton | boolean | false | Enable to show a full-width button under pagination |
dotStyle | style | {backgroundColor: ‘rgba(0, 0, 0, .2)’} | Style of inactive pagination dots |
dotClickEnabled | boolean | true | Whether users can navigate using the pagination dots |
activeDotStyle | style | {backgroundColor: ‘rgba(255, 255, 255, .9)’} | Style of active pagination dot |
skipLabel | string | Skip | Custom label for Skip button |
doneLabel | string | Done | Custom label for Done button |
nextLabel | string | Next | Custom label for Next button |
prevLabel | string | Back | Custom label for Prev button |
showSkipButton | boolean | false | Enable to show a skip button to the left of pagination dots. When bottomButton == true the skip button is a small text under the full-width next button |
showPrevButton | boolean | false | Enable to show a previous button. If showSkipButton is true, the skip button will be displayed on the first page and prev button on subsequent one |
showNextButton | boolean | true | Disable to hide the next button |
showDoneButton | boolean | true | Disable to hide the done button |
renderNextButton | function | renders a Text-component | Use to supply your own next button. Has no effect if using renderPagination . |
renderPrevButton | function | renders a Text-component | Use to supply your own prev button . Has no effect if using renderPagination |
renderDoneButton | function | renders a Text-component | Use to supply your own done button. Has no effect if using renderPagination |
renderSkipButton | function | renders a Text-component | Use to supply your own skip button. Has no effect if using renderPagination |
Step 9 – Methods
Method Name | Arguments | Description |
---|---|---|
goToSlide | number | Change to slide with specified index |
getListRef | none | Returns the Flat List ref |
So we completed the react-native drag and drop functionality which is “How To Show App Intro Slider in React Native“
You can find my next post here.
You can find my post on medium as well click here please follow me on medium as well.
If have any query or issues, please feel free to ask.
For more info – https://www.npmjs.com/package/react-native-app-intro-slider
Happy Coding Guys.
Hi, I am a professional Ionic and React Native Pixel Perfect App Designer and Developer, with expertise in Client Communication, Bug Fixing, Third Party Lib, Version Control Tools, Requirement Understanding, and managing teams, I have 6+ years of experience in the same domain as well as in Codeigniter, JS, IoT, and more than 10 other languages. For the last 6+ years, not a single day went without design/development.
Please follow me on Medium: https://nehadwivedi1004.medium.com/