No way to load a local HTML file in the webview on Android
See original GitHub issueBug description:
I have a file with name index.html
. I’m trying to load the file into the webview. However, there seems to be no option for it in android.
To Reproduce:
On iOS I tried:
const myHtml = require("./index.html");
// In Render
<WebView
ref={this._webViewRef}
source={myHtml}
/>
It worked perfectly fine. However on Android it threw TypeError: Cannot use 'in' operator to search for 'method'
So, I tried manually resolving the asset uri like I used to do for Images,
<WebView
ref={this._webViewRef}
source={{uri: Image.resolveAssetSource(myHtml).uri}}
/>
However it directly loads the file HTML source instead of the actual webpage.
Expected behavior:
const myHtml = require("./index.html");
// In Render
<WebView
ref={this._webViewRef}
source={myHtml}
/>
The above code should just load the webpage on both android and iOS I guess…
Environment:
- OS: macOS
- OS version: 10.14 (18A391)
- react-native version: 0.60.3
- react-native-webview version: 5.12.1
Issue Analytics
- State:
- Created 4 years ago
- Reactions:24
- Comments:48 (8 by maintainers)
Top Results From Across the Web
Load HTML file into WebView - android - Stack Overflow
Use assetLoader from (2) to construct WebViewClient from (3), and set it in your WebView . Your index.html can be loaded by using...
Read more >Loading in-app content - Android Developers
Right-click the assets folder and then click New > File. Enter index.html and press Return or Enter . Screen showing create-file menus. Figure...
Read more >Loading local web content on Android - Hellsoft
One way to load the content is to embed a HTTP server in your application and load the content into your WebView through...
Read more >How to load and display a local html file in Android Webview?
Let's say the html file is called as index.html and is located in the asset folder of the app. The following Activity shows...
Read more >How to load a local HTML or PDF file? - Vuplex Support
Copy your web page resources to the StreamingAssets folder. For example, you could have a folder with the following files: ... await webViewPrefab...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Per this comment using
<WebView source={require('page.html')} />
is not supported by react-native-webview. So, indeed, there seems to be no official way to load a local HTML file in the webview.It would be really nice if using
require
withsource
could work like it did with the webview previously included in react-native. We can’t currently upgrade react-native due to this problem.Shouldn’t this be documented?