I’m growing a React Native app with a WebView to load an HTML bundle from the native file system. I’m specializing in iOS growth first and can work on Android later.
Under is the code I’m utilizing to load the HTML file:
App.js
import RNFS from 'react-native-fs';
const pathURI =
Platform.OS === 'android'
? 'file:///android_asset/samples/index.html'
: `${RNFS.MainBundlePath}/samples/index.html`;
{
const {nativeEvent} = syntheticEvent;
console.log('WebView error:', nativeEvent);
}}
onHttpError={syntheticEvent => {
const {nativeEvent} = syntheticEvent;
console.log('HTTP error:', nativeEvent);
}}
onMessage={occasion => {
console.log('WebView log:', occasion.nativeEvent.knowledge);
}}
/>
index.html
LOADING...
index.js
window.addEventListener('load', evt => {
console.log('Window Loaded');
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = operate () {
console.log('onreadystatechange', xhttp.standing, xhttp.readyState);
if (xhttp.readyState === XMLHttpRequest.DONE) {
if (xhttp.standing === 200) {
console.log('Response:', xhttp.responseText);
} else {
console.log('Error:', xhttp.statusText);
}
}
};
xhttp.open('GET', 'knowledge.json', true);
xhttp.ship();
console.log('Window onload code executed');
});
Problem:
The index.html and index.js information load efficiently, and the window.onload operate executes. Nevertheless, the XMLHttpRequest doesn't execute as a result of it requires an online server to operate.
To unravel this, I used the react-native-static-server bundle with the next code:
import StaticServer from 'react-native-static-server';
const pathURI =
Platform.OS === 'android'
? 'file:///android_asset/samples'
: `${RNFS.MainBundlePath}/samples`;
useEffect(() => {
const server = new StaticServer(8080, pathURI, {
localOnly: true,
});
server.begin().then(url => {
console.log(`Server began at ${url}`);
});
}, []);
Error:
After I run the above code, I get the next error:
Error: FPStaticServer.begin(): Error whereas changing JavaScript argument 2 to Goal C kind BOOL. Goal C kind BOOL is unsupported.
I’ve ensured that localOnly: true
is included, however I’m undecided the place I’m going improper.
Can somebody assist me establish the problem or present steering on methods to resolve this error?