React native webview is a component that is used to load HTML content and also web page. So you can convert any website into a mobile app. In this tutorial we will discuss How you will create a mobile app step by step.

React Native Webview Example
Convert Website to App

Basically webview can show websites like web browser. It also supports CSS and javascript. So if you want to convert any website into a mobile application, then you can use the webview component. The main advantage of this type of application is a maintenance-free mobile application.

Basically react native app use for developing mobile application so webview load responsive view of a website. Therefore you do not need to maintain mobile applications separately. Just you need to upgrade your website from time to time.

Now we will discuss step by step process to convert a website into a mobile application.

Step 1 : Responsive Design.

As you want to create a mobile application using a “react-native app” using a webview component, therefore, you need a responsive design for the whole website.

Step 2 : Create React Native App.

First of all you need to install and create a native application in the “react-native”. Use the following command to create a native app.

create-react-native-app native-demo

Create React Native App

How you will create React Native App

Click on above link to know how you will create react native app 1st time in Visual Studio Code.

Step 3 : Install and import webview component.

In React native app webview is a react component. so to use it you should install “react-native-webview” in your application. To install it run following command.

npm install –save react-native-webview

Step 4 : Write code as follows

Before using webview you should import the component in your .js file. To import the component use the following code.

import {WebView} from ‘react-native-webview’;

Basic code for webview is following

         <WebView
          automaticallyAdjustContentInsets={false}
          source={{uri‘https://demoshop.logisofttechnologies.com/’}}
          javaScriptEnabled={true}
          domStorageEnabled={true}
          startInLoadingState={true}
          style={{marginTop25}}
        />

Now the app is ready to work. You can test your application at the expo. Read more about Basic React Native App.

Step 5 : Handle Mobile Back Button.

In case of web view application mobile back button not functioning as per webview browsing history. Every time the app closes after pressing the back button of the mobile. So if you want to enable go back function for webview application you need to write code properly for go back function.

To enable the “goBack” function write the following code in the .js file where the webview component used. In this case “App.js” file.

Code for App.js File

import React, {Componentfrom ‘react’;
import {View,BackHandler,Platform,} from ‘react-native’;
import {WebViewfrom ‘react-native-webview’;

export default class App extends Component {
  constructor(props) {
    super(props);
  }
  webView = {
    canGoBackfalse,
    refnull,
  }

  onAndroidBackPress = () => {
    if (this.webView.canGoBack && this.webView.ref) {
      this.webView.ref.goBack();
      return true;
    }
    return false;
  }

  componentWillMount() {
    if (Platform.OS === ‘android’) {
      BackHandler.addEventListener(‘hardwareBackPress’this.onAndroidBackPress);
    }
  }

  componentWillUnmount() {
    if (Platform.OS === ‘android’) {
      BackHandler.removeEventListener(‘hardwareBackPress’);
    }
  }

  render() {
    return (
      <View style={{flex:1}}>
        <WebView
          ref={(webView=> { this.webView.ref = webView; }}
          onNavigationStateChange={(navState=> { this.webView.canGoBack = navState.canGoBack; }}
          automaticallyAdjustContentInsets={false}
          source={{uri‘https://demoshop.logisofttechnologies.com/’}}
          javaScriptEnabled={true}
          domStorageEnabled={true}
          startInLoadingState={true}
          style={{marginTop25}}
        />
    </View>
    )
  }
  
}

Hare we added two more attributes one is “ref” and another is “onNavigationStateChange” in the webview component. Then create an arrow function “onAndroidBackPress” to handle the android back button.

After that add Event Listener under componentWillMount() function and also remove Listener under componentWillUnmount() function.

Step 6 : Build Android and iOS App for Mobile.

Now time to build an app for android and ios also. Before start, build make sure that you have properly configured the “App.json” file.

You have to set the name, description, slug, and Also configure the android and ios sections. Following is my “App.json” file.

App.json file Sample

{
  “expo”: {
    “name”“QUILL ECOMM”,
    “slug”“quill-ecomm”,
    “privacy”“public”,
    “sdkVersion”“36.0.0”,
    “platforms”: [
      “ios”,
      “android”,
      “web”
    ],
    “version”“1.0.0”,
    “orientation”“portrait”,
    “icon”“./assets/icon.png”,
    “splash”: {
      “image”“./assets/splash.png”,
      “resizeMode”“contain”,
      “backgroundColor”“#ffffff”
    },
    “updates”: {
      “fallbackToCacheTimeout”0
    },
    “assetBundlePatterns”: [
      “assets/*”
    ],
    “ios”: {
      “bundleIdentifier”“com.quillecomm.quillecomm”,
      “buildNumber”“1.0.0”
    },
    “android”: {
      “package”“com.quillecomm.quillecomm”,
      “versionCode”1
    },
    “description”“QUILL E-Commerce Demo Application by Logisoft Technologies”
  }
}

For build app run appropriated command. If you want to build an android app then the command is below.

expo build:android

In case of ios command is below.

expo build:ios

Read more about building app for android and ios

This Post Has 24 Comments

  1. Power Bi Aplicado a Problemas Reais Métricas + Kpi'S Leonardo Karpinski

    whoah this blog is fantastic i love reading your articles. Keep up the good work! You know, lots of people are hunting around for this information, you could aid them greatly.

  2. curso e-commerce - sebrae

    You made some decent points there. I appeared on the internet for the problem and located most individuals will go along with with your website.

  3. Curso Método Cronos Wendell Carvalho

    Hi there, I found your website by means of Google whilst looking for a related matter, your web site came up, it looks great. I’ve bookmarked it in my google bookmarks.

  4. vorbelutr ioperbir

    A large percentage of of the things you claim happens to be astonishingly precise and it makes me wonder the reason why I had not looked at this with this light before. This particular piece truly did turn the light on for me personally as far as this specific issue goes. But at this time there is just one point I am not too comfy with and whilst I try to reconcile that with the actual main idea of the issue, let me see just what the rest of the subscribers have to say.Very well done.

  5. pro dentim

    very good put up, i definitely love this website, keep on it

  6. curso de relacionamento amoroso gratuito

    Thanks for the ideas you are sharing on this site. Another thing I’d prefer to say is getting hold of some copies of your credit file in order to examine accuracy of any detail is the first action you have to perform in credit restoration. You are looking to clean your credit profile from harmful details flaws that wreck your credit score.

  7. Anon slot online uk

    naturally like your website however you need to check the spelling on quite a few of your posts. Several of them are rife with spelling issues and I find it very bothersome to tell the reality however I will surely come again again.

  8. Ikaria juice

    Today, with the fast way of living that everyone is having, credit cards get this amazing demand throughout the economy. Persons throughout every arena are using credit card and people who aren’t using the card have prepared to apply for just one. Thanks for revealing your ideas in credit cards.

  9. Curso Injeção Eletrônica Peugeot 206 Videocarro

    I was just searching for this information for some time. After six hours of continuous Googleing, at last I got it in your site. I wonder what is the lack of Google strategy that do not rank this type of informative web sites in top of the list. Generally the top sites are full of garbage.

  10. textile shop india

    Thanks for your article. My partner and i have continually noticed that most people are eager to lose weight when they wish to look slim as well as attractive. On the other hand, they do not usually realize that there are many benefits to losing weight additionally. Doctors say that overweight people come across a variety of conditions that can be directly attributed to the excess weight. Fortunately that people who’re overweight in addition to suffering from numerous diseases can reduce the severity of their illnesses by losing weight. You are able to see a gradual but marked improvement with health if even a negligible amount of weight loss is reached.

  11. Jeremiah Fyock

    Thank you for providing me with these article examples. May I ask you a question?

  12. Ron Fritchley

    What are your articles about? Please tell me more.

  13. Tim Mrowka

    Thanks for your help and for writing this post. It’s been great.

  14. Margaret Cunliffe

    Thank you for posting this post. I found it extremely helpful because it explained what I was trying to say. I hope it can help others as well.

  15. graliontorile

    I was just searching for this information for some time. After six hours of continuous Googleing, finally I got it in your site. I wonder what is the lack of Google strategy that do not rank this type of informative websites in top of the list. Normally the top sites are full of garbage.

  16. where to buy cialis online forum

    Spot on with this write-up, I honestly feel this
    amazing site needs a great deal more attention. I’ll probably be returning to
    read more, thanks for the info!

  17. zoritoler imol

    Hello my friend! I want to say that this post is awesome, nice written and include almost all vital infos. I would like to see more posts like this.

  18. zoritoler imol

    After examine a couple of of the weblog posts on your website now, and I really like your means of blogging. I bookmarked it to my bookmark website list and shall be checking again soon. Pls take a look at my website as nicely and let me know what you think.

  19. zoritoler imol

    I also think thence, perfectly pent post! .

  20. Yong

    I blog frequently and I truly appreciate your information. This great article
    has really peaked my interest. I’m going to book mark your website and keep checking for new details about once per week.
    I opted in for your RSS feed too.

  21. zortilonrel

    I like this weblog very much, Its a real nice office to read and find information. “Reason is not measured by size or height, but by principle.” by Epictetus.

  22. zortilonrel

    I am constantly searching online for articles that can facilitate me. Thx!

  23. genuine ford key fob

    Very nice post. I simply stumbled upon your weblog and wished to mention that I’ve truly enjoyed surfing around your blog posts.

  24. Androidena

    Raw WebViews are good for most workflows, especially if there is a team of native app developers who are building the hybrid part of the application. They allow native developers to feel at home while the web developers can fully implement most of the cross-platform logic. The boilerplate has been reduced over time and with most requirements never actually needing native code, the reasons for not putting it in a WebView are diminishing at a great speed.

Leave a Reply