React Native App Intro Slider using AppIntroSlider

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 init to make our React Native App. Assuming that you have node installed, you can use npm to install the react-native-cli command line utility. Open the terminal and go to the workspace and run

npm install -g react-native-cli

Run the following commands to create a new React Native project

react-native init ProjectName

If you want to start a new project with a specific React Native version, you can use the --version argument:

react-native init ProjectName --version X.XX.X
react-native init ProjectName --version react-native@next

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

/*This is an example of React Native App Intro Slider */
import React from 'react';
//import react in project
import { StyleSheet, View, Text, Image } from 'react-native';
//import all the required component
import AppIntroSlider from 'react-native-app-intro-slider';
//import AppIntroSlider to use it
export default class App extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      showRealApp: false,
      //To show the main page of the app
    };
  }
  _onDone = () => {
    this.setState({ showRealApp: true });
  };
  _onSkip = () => {
    this.setState({ showRealApp: true });
  };
  _renderItem = ({ item }) => {
    return (
      <View
        style={{
          flex: 1,
          backgroundColor: item.backgroundColor,
          alignItems: 'center',
          justifyContent: 'space-around',
          paddingBottom: 100
        }}>
        <Text style={styles.title}>{item.title}</Text>
        <Image style={styles.image} source={item.image} />
        <Text style={styles.text}>{item.text}</Text>
      </View>
    );
  };
  render() {
    //If false show the Intro Slides
    if (this.state.showRealApp) {
      //Real Application
      return (
        <View
          style={{
            flex: 1,
            justifyContent: 'center',
            alignItems: 'center',
            padding: 50,
          }}>
          <Text>
            This will be your screen when you click Skip from any slide or Done
            button at last
          </Text>
        </View>
      );
    } else {
      //Intro slides
      return (
        <AppIntroSlider
          slides={slides}
          renderItem={this._renderItem}
          onDone={this._onDone}
          showSkipButton={true}
          onSkip={this._onSkip}
        />
      );
    }
  }
}
const styles = StyleSheet.create({
  image: {
    width: 200,
    height: 200,
  },
  text: {
    fontSize: 18,
    color: 'white',
    textAlign: 'center',
    paddingVertical: 30,
  },
  title: {
    fontSize: 25,
    color: 'white',
    textAlign: 'center',
    marginBottom: 16,
  },
});

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
To run the project on an Android Virtual Device or on real debugging device
react-native run-android
or on the iOS Simulator by running
react-native run-ios (macOS only).

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

/*This is an example of React Native App Intro Slider */
import React from 'react';
//import react in project
import { StyleSheet, View, Text, Image } from 'react-native';
//import all the required component
import AppIntroSlider from 'react-native-app-intro-slider';
//import AppIntroSlider to use it
export default class App extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      showRealApp: false,
      //To show the main page of the app
    };
  }
  _onDone = () => {
    this.setState({ showRealApp: true });
  };
  _onSkip = () => {
    this.setState({ showRealApp: true });
  };
  _renderItem = ({ item }) => {
    return (
      <View
        style={{
          flex: 1,
          backgroundColor: item.backgroundColor,
          alignItems: 'center',
          justifyContent: 'space-around',
          paddingBottom: 100
        }}>
        <Text style={styles.title}>{item.title}</Text>
        <Image style={styles.image} source={item.image} />
        <Text style={styles.text}>{item.text}</Text>
      </View>
    );
  };
  render() {
    //If false show the Intro Slides
    if (this.state.showRealApp) {
      //Real Application
      return (
        <View
          style={{
            flex: 1,
            justifyContent: 'center',
            alignItems: 'center',
            padding: 50,
          }}>
          <Text>
            This will be your screen when you click Skip from any slide or Done
            button at last
          </Text>
        </View>
      );
    } else {
      //Intro slides
      return (
        <AppIntroSlider
          slides={slides}
          renderItem={this._renderItem}
          onDone={this._onDone}
          showSkipButton={true}
          onSkip={this._onSkip}
          bottomButton
        />
      );
    }
  }
}
const styles = StyleSheet.create({
  image: {
    width: 200,
    height: 200,
  },
  text: {
    fontSize: 18,
    color: 'white',
    textAlign: 'center',
    paddingVertical: 30,
  },
  title: {
    fontSize: 25,
    color: 'white',
    textAlign: 'center',
    marginBottom: 16,
  },
});

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
To run the project on an Android Virtual Device or on real debugging device
react-native run-android
or on the iOS Simulator by running
react-native run-ios (macOS only).

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, I am using Ionicons.

If you want to know more about Ionicons then you can visit Example to Use Ionicons in React Native using react-native-ionicons.

So to use Ionicons we have to install react-native-ionicons dependency and to do that run the following command

npm install react-native-ionicons --save

After the updation of React Native 0.60, they have introduced autolinking feature means we do not require to link the library but they have also mentioned that some libraries need linking and react-native-ionicons is one of those cases. So for that, we need to link the library using

react-native link react-native-ionicons

Now we need to install pods

cd ios && pod install && cd ..

Now Open App.js in any code editor and replace the code with the following code.

App.js

/*This is an example of React Native App Intro Slider */
import React from 'react';
//import react in project
import { StyleSheet, View, Text, Image } from 'react-native';
//import all the required component
import AppIntroSlider from 'react-native-app-intro-slider';
//import AppIntroSlider to use it
import Icon from 'react-native-ionicons'

export default class App extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      showRealApp: false,
      //To show the main page of the app
    };
  }
  _renderNextButton = () => {
    return (
      <View style={styles.buttonCircle}>
        <Icon
          name="md-arrow-round-forward"
          color="rgba(255, 255, 255, .9)"
          size={24}
          style={{ backgroundColor: 'transparent' }}
        />
      </View>
    );
  };
  _renderDoneButton = () => {
    return (
      <View style={styles.buttonCircle}>
        <Icon
          name="md-checkmark"
          color="rgba(255, 255, 255, .9)"
          size={24}
          style={{ backgroundColor: 'transparent' }}
        />
      </View>
    );
  };
  _onDone = () => {
    this.setState({ showRealApp: true });
  };
  _onSkip = () => {
    this.setState({ showRealApp: true });
  };
  _renderItem = ({ item }) => {
    return (
      <View
        style={{
          flex: 1,
          backgroundColor: item.backgroundColor,
          alignItems: 'center',
          justifyContent: 'space-around',
          paddingBottom: 100
        }}>
        <Text style={styles.title}>{item.title}</Text>
        <Image style={styles.image} source={item.image} />
        <Text style={styles.text}>{item.text}</Text>
      </View>
    );
  };
  render() {
    //If false show the Intro Slides
    if (this.state.showRealApp) {
      //Real Application
      return (
        <View
          style={{
            flex: 1,
            justifyContent: 'center',
            alignItems: 'center',
            padding: 50,
          }}>
          <Text>
            This will be your screen when you click Skip from any slide or Done
            button at last
          </Text>
        </View>
      );
    } else {
      //Intro slides
      return (
        <AppIntroSlider
          slides={slides}
          renderItem={this._renderItem}
          onDone={this._onDone}
          renderDoneButton={this._renderDoneButton}
          renderNextButton={this._renderNextButton}
        />
      );
    }
  }
}
const styles = StyleSheet.create({
  image: {
    width: 200,
    height: 200,
  },
  text: {
    fontSize: 18,
    color: 'white',
    textAlign: 'center',
    paddingVertical: 30,
  },
  title: {
    fontSize: 25,
    color: 'white',
    textAlign: 'center',
    marginBottom: 16,
  },
  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
To run the project on an Android Virtual Device or on real debugging device
react-native run-android
or on the iOS Simulator by running
react-native run-ios (macOS only).

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. 🙂

 

34 thoughts on “React Native App Intro Slider using AppIntroSlider”

  1. Hi,
    really nice work.
    I just have one question/comment.
    When you this intro-slider in a real device, you’ll find that the user can scroll all slides with just one fast touch. I know that paging is used in the scroller, but it is very easy to reach the end of the scroller with one fast touch across the screen. Have you noticed that? any workaround?

    Reply
  2. …I have placed my images in the ./src/assets/…jpg folder
    also in ./src/assets/images/…jpg folder
    also same images in .\android\app\src\main\res\drawable-hdpi folder
    even from https://web.facebook.com/photo.php?fbid

    I tried using require(“../assets/images/image.jpg”)
    {uri: ‘image’}
    {uri: ‘https:/…’}
    but none works.

    I’m new to this…Thanks

    Reply
    • Don’t worry about the image loading I will solve it for you.
      An image component that we have used in the example can load the image from the live server or from the local directory but passing the image path has some differences.

      Please have a look on the following example and try to load the image from local directory.

      https://aboutreact.com/react-native-image/

      If you are still stucked then please share your directory structure and the image component with URL to load the image.
      A screenshot will help me alot to solve it. Please send me the screenshot on snehalagrawal1701@gmail.com

      Reply
      • Thanks for your assistance.
        I don’t have any background in programming I’m just trying to switch, so it’s kind of distracting, but with your aboutreact.com site, it boost my confidence to carry on.
        I’m trying to develop a business directory app, which has to do a lot with images, that’s why I wanted to get a good experience with images.
        Regarding this introslide, do i have to configure and import render the image props using a constructor(parent & child component) export default class.
        Please, don’t mind my terms if they are not correct, I’m trying to get familiar with them.
        I can’t express how glad I am, talking to you, I’m very grateful.

        Reply
  3. I tried it, still having the same image issue I had in appintroslider.
    it is not loading the image in my asset folder ‘drawer.png’
    I have also placed the image in the root directory image folder, yet, nothing…
    How do I load the images…Thanks

    Reply
      • Thanks for your assistance. I really appreciate. After some workarounds, I have been able to get it right. But I still need your help. There is this component the slides at the bottom Tab position which I wish to apply to my project, find attached the image in the mail send to you (@snehalagrawal1701@gmail.com) and see if you can help me with it, I don’t if the feature exists in react native.
        Like I said earlier, my project is a business directory app, so I wish to slide logos of business at the bottom tap position.
        Thanks. You are doing a really great job.

        Reply
          • Greetings
            Thanks a lot. You are one in million.
            The align view to bottom tab is close to what I need, but it has to have autoplay to keep swiping repeatedly non stop.
            I appreciate your assistance. I’m very grateful.

          • Thanx for the appreciation 🙂 it means a lot to me.
            As per my understanding, you need something like Google ad banner which changes time to time right?

            For that, we have 2 options
            1. You can make an array of images and make a view in the bottom with 5 image view component.
            Make a state to manage those images.
            Now in the constructor or in componentDidMount method setInterval of 5-10 sec and change the state and try to change those images.

            2. You can use auto-swipe menu/slider which swipes the images in a particular interval. I can help you in that if you want me to do it as I have planned to post a related post on that.

    • 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/

      Reply
  4. How to add custom buttons and how to change size of this slider?
    For example this slider cover all of the screen but I want to just 70% of height and 30% of remaining screen will be use for buttons.

    Reply
    • Hello Sander,
      Just wrap the IntroSlider with a View and give it a height and with the help of other view make a space for you button

      <View style={{ flex: 1 }}>
          <View style={{ height: ‘80%’ }}>
              <AppIntroSlider
               slides={slides}
               onDone={this._onDone}
               showSkipButton={true}
               onSkip={this._onSkip}
              />
          </View>
          <View style={{ height: ‘20%’, justifyContent: ‘center’ }}>
              <Button title=”Click me” onPress={this.handlerFunc.bind(this)}         />
          </View>
      </View>

      Here is the screenshot after changes:

      Reply
  5. Hello,
    How to change length between title and image? It is always constant and I can’t find how to change it.
    I want to change length between title and image and it should be just 16 px.

    Reply
  6. hello,
    in my project i have 3 screens such as profile,linked in,education.i had applied app intro slider for that but it is applied only in profile page rather than 3 pages.could you tell me how to apply for 3 screens.its just only showing to starting page. please will you help from this

    Reply
  7. Hello,

    thanks a lot for this page, it’s really well explained and work very well.
    Do you know if it’s possible to insert translation code in it thanks to i18n ? I have this kind of code : {i18n.t(“world”)} and I want to put the translation in the title and text items of my slides :

    for example :
    {
    key: ‘s2’,
    title: ‘Share your adventures !’,
    text: ‘Share with your friends\nAnd take part to the biggest distance done on 2019’,
    image: require(‘../assets/images/bg_mobile_portrait.jpg’),
    titleStyle: styles.title,
    textStyle: styles.text,
    imageStyle: styles.image,
    },

    Do you have an idea of how can i do it ?
    Thank you!

    Reply
  8. Hi i am using White background, because the text for skip is also white its not visible.
    is there any way to change font color of ‘skip’ or background of ‘skip’ any other color

    Reply

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.