SDK Version: latest stable
Platforms: Android
Hey, I am desparetly looking for a way to run a single page webapplication in WebView, with the corresponding files being stored locally.
I was able to achieve what I want while being in development mode and operating the app through Expo Go.
But as soon as I build the app into an APK and install it on an Android device, it stops working.
This is my code:
import React from 'react';
import { StatusBar } from 'expo-status-bar';
import { StyleSheet, Text, View, SafeAreaView } from 'react-native';
import { WebView } from 'react-native-webview';
export default function App() {
const webViewProps = {
javaScriptEnabled: true,
androidLayerType: 'hardware',
originWhitelist: ['*'],
allowFileAccess: true,
domStorageEnabled: true,
mixedContentMode: 'always',
allowUniversalAccessFromFileURLs: true,
scalesPageToFit: true,
};
const Header = () => (
<View style={styles.header}>
</View>
);
return (
<SafeAreaView style={{ flex: 1 }}>
<StatusBar style="light" />
<Header />
<WebView
style={styles.container}
source={require('./assets/out/index.html')}
{...webViewProps}
/>
</SafeAreaView>
);
}
const styles = StyleSheet.create({
header: {
paddingTop: 15,
paddingBottom: 10,
backgroundColor: "#ec3c3c"
},
title: {
color: "#fff",
fontSize: 20,
fontWeight: "bold",
textAlign: "center"
},
container: {
flex: 1,
backgroundColor: '#fff',
alignItems: 'center',
justifyContent: 'center',
paddingTop: 40,
},
});
My best guess is, that the HTML files are somehow not included in the app bundle or are located somewhere, where WebView is unable to find them.
Do you guys have any idea on how I can solve this?
Do I need a local http-server? Do I need to serve the files in a different way?
I am open to all suggestions, except for hosting the HTML on a remote server, as I need the app to work offline.
Additionally: The solution has to work for Android and iOS.