application

React Native Hybrid with Ease

React Native Hybrid:

Is React native hybrid? a popular question that mostly developers asked. Let start with the definition off an hybrid apps. An app that is in fact a full-screen web browser (WebView), in which it renders view components. Popular mobile frameworks that use this approach are Ionic, Cordova and PhoneGap.

So React native is not pure hybrid its a blend of both native and hybrid. React Native renders native views, so its native as far views are concerned. on the other hand React Native allows you to mix languages like Java, Kotlin, Objective-C or Swift with JavaScript. In this way we can use it in both platforms. If you want to create hybrid apps for desktop like VS Code, check this out, Electron JS Tutorial.

React Native Hybrid WebView:

In new react native WebView component there are so much opportunity with new features. One of them is loading local HTML(Hyper text mark-up language) file in WebView component. This feature allow us to hold some of HTML pages inside our application directory so when they needed in app, there are no need to use internet connection to access them. It increases our app responding time. So in this tutorial we would learn about New React Native WebView Load Local HTML File From Assets Folder in Android or iOS App.

Creating a new application:

React Native has a built-in command line interface, which you can use to generate a new project. You can access it without installing anything globally using npx, which ships with Node.js. Let’s create a new React Native project called “AwesomeProject”:

npx react-native init AwesomeProject 

The second step is to install the react-native-webview NPM package in our current react native application. So open your react native project root directory in Command Prompt or Terminal and execute below command to install react-native-webview.

npm install --save react-native-webview 

Usage:

Import the WebView component from react-native-webview and use it like so:

import React, { Component } from 'react';
import { StyleSheet, Text, View } from 'react-native';
import { WebView } from 'react-native-webview';

// ...
class MyWebComponent extends Component {
  render() {
    return <WebView source={{ uri: 'https://reactnative.dev/' }} />;
  }
}

Inline HTML:

Minimal example with inline HTML:

import React, { Component } from 'react';
import { WebView } from 'react-native';

class MyInlineWeb extends Component {
render() {
return (
<WebView
originWhitelist={['*']}
source={{ html: '<h1>Hello world</h1>' }}
/>
);
}
}

You can use this component to navigate back and forth in the web view’s history and configure various properties for the web content.

On iOS, the useWebKit prop can be used to opt into a WKWebView-backed implementation.

Conclusion

In this post, we have reviewed how to embed WebViews into your React Native app. You can either provide URLs to your WebView component or add some custom inline HTML.

moin

Recent Posts

Setup Tailwind CSS with Angular Version greater than 11

Install tailwind css with npm Run the following command to install tailwind css npm install…

4 weeks ago

How to setup laravel project using homestead

Step 1 : Create a new directory Homestead by using this command  cd ~/Homestead Step…

4 weeks ago

NPM vs NPX

npx and npm are both command line tools that are used to install and run…

4 weeks ago

Configure laravel project in vagrant box in ubuntu

Step 1: Create a directory where you want to store project such as  mkdir ~/vagrant_projects…

1 month ago

Guide To Naming Conventions

Specifically, there are certain naming conventions available across all programming languages, also known as Snake…

1 month ago

How to use a CORS proxy to avoid “No Access-Control-Allow-Origin header” problems

If you want to solve the Access-Control-Allow-Orgin header problems, you can setup the cors proxy.…

2 months ago

This website uses cookies.