I’m trying to include an HTML file in a React Native WebView. The GitHub repo containing the full project is located here: https://github.com/reggie3/webview-inline-javascript-test. To summarize, the WebView shows the correct file using the XDE’s “Share” functionality. However, it displays the following error when published: “This XML file does not appear to have any style information associated with it”
The project works when “Shared” via the Expo XDE and renders the HTML file correctly as shown below:
However, when the project is published via the XDE’s “Publish” button, I get the following ““xml file does not appear to have any style information”” error shown below:
I have the following lines in my app.json file to ensure that the HTML file the WebView is trying to access is included in the published bundle. Note that I specifically included the HTML file to ensure it was included. I received :
"packagerOpts": {
"assetExts": ["html"]
},
"assetBundlePatterns": [
"./assets/**",
"./assets/dist/test.html"
],
The HTML file is just a simple attempt to render some text:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
</head>
<body style="
margin: 0 !important;
padding: 0 !important;
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
">
<h2>JavaScript in Body 123</h2>
<div id="p1">test area</div>
</body>
</html>
The HTML file is included in the application by via a require
statement:
const INDEX_FILE = require("./assets/dist/test.html");
Finally, the WebView component looks like this:
<WebView
style={{
...StyleSheet.absoluteFillObject,
backgroundColor: '#ffebba',
padding: 10
}}
ref={this.createWebViewRef}
source={INDEX_FILE}
onLoadEnd={this.webViewLoaded}
onMessage={this.handleMessage}
startInLoadingState={true}
renderLoading={this.showLoadingIndicator}
renderError={this.renderError}
onError={this.onError}
scalesPageToFit={false}
javaScriptEnabled={true}
/>
This project is an attempt to create a simple proof of concept project to diagnose and solve issues mentioned in a previous Expo Forum post: here