question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Display the html source code on android when load local file, but working on iOS use the same code.

See original GitHub issue
const html = require('@/assets/index.html');
<WebView source={html} />

Environment:

  • OS: android
  • OS version: 5.1.1
  • react-native version: 0.62.2
  • react-native-webview version: 10.3.2

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:2
  • Comments:8

github_iconTop GitHub Comments

3reactions
ngtrungtcommented, Jun 30, 2020

I got same issue then I did as below:

  1. Manually copy the HTML pages to android/app/src/main/assets folder
  2. Change the reference in code to file:///android_asset instead of ./ or …/
  • For example file:///android_asset/generic.html
  1. Using: <WebView source={{ uri: ‘file:///android_asset/generic.html’ }} />
1reaction
codthingcommented, Jan 19, 2021

I got same issue then I did as below:

  1. Manually copy the HTML pages to android/app/src/main/assets folder
  2. Change the reference in code to file:///android_asset instead of ./ or …/
  • For example file:///android_asset/generic.html
  1. Using: <WebView source={{ uri: ‘file:///android_asset/generic.html’ }} />

What if it is an Expo user?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Display the html source code on android when load local file ...
Manually copy the HTML pages to android/app/src/main/assets folder; Change the reference in code to file:///android_asset instead of ./ or ../.
Read more >
(React Native) Load local HTML file into WebView
I come across this post searching for loading static html. If your html code is retrieved using, for example, an API, you can...
Read more >
Build web apps in WebView - Android Developers
Work with WebView on older versions of Android; Use JavaScript in WebView. Enable JavaScript; Bind JavaScript code to Android code.
Read more >
How to View the HTML Source Code of a Web Page
Open Chrome and navigate the web page whose source code you'd like to ... don't work on your Android phone, use the method...
Read more >
Handling common HTML and CSS problems - MDN Web Docs
This includes linting code, handling CSS prefixes, using browser dev ... try loading up an HTML file and a CSS file: you'll see...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found