I created complete offline ReactJS web application and I want to run it from android application from Web View using React-Native.
I followed the following procedure to do so:
1. I created a compiled ReactJS web application got the build
using the following command:
npm run build
Then I created react-native project and placed the build
folder with following architecture
I updated App.js
with the following content:
import React, {Component} from 'react';
import {Platform, StyleSheet, Text, View, WebView} from 'react-native';
import {roscon} from "./build/index.html";
type Props = {};
export default class App extends Component<Props> {
render() {
return (
<View style={{height: 300, width: 300,overflow:'hidden' }}>
<WebView
source={{uri: roscon}}
scalesPageToFit={true}
domStorageEnabled={true}
javaScriptEnabled={true}
startInLoadingState={true}
/>
</View>
);
}
}
After running this code I expected it to run my ReactJS Web application, instead I got white screen.
Can you please tell what can be the causing issues and how i can make my ReactJS Web App run on react-native?
Note: I was able to run generated build
folder using npm command
serve -s build
But I still can't figure out how to port it to react-native project as WebView
A WebView is an embedded browser that can be used to display web pages inside your React Native applications. It can display anything (from custom HTML elements to entire web applications) inside React Native. In React Native, we can use WebView by using a third-party package called react-native-webview.
To use a WebView component, you have to install the react-native-webview package. Also, make sure you link the native bindings with the newly installed dependency. An iOS application does not require any further steps to make this work. For Android platforms version 6.
After research and testing, I found a solution.
The main issue i found was the compiled build
folder is rendered as static html
. And it needed a server
to serve pages.
So, I followed this link for getting build
project to get it up and running
Then, integrating it with nodejs Android Project Samples to get my build
folder running in android as a Webview.
Note: I also tried react-snapshot
and react-snap
but they didn't gave satisfactory results.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With