-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Android] Opening local HTML file as text #428
Comments
same problem |
I'm having an issue on Android also, but it's actually crashing with this error: It is working if I use a URI source to a local asset (which is what I do when |
same problem with Android |
same error , Opening html file as text in IOS. Any updates??? |
@tusharmutreja wait, this is happening to you on iOS? Care to show your code? |
Does not happen in iOS, happens in Android as no Content-Type header is returned for the asset. |
Error
with local file in source prop But works correctly with url in source prop Android Debug |
@danielgindi I found this in my investigation as well, but either that isn't the only problem, or I wasn't successful in adding the Content-Type |
Currently having the same issue with Expo SDK 33 as they have now added support for this package. Did anyone find a proper solution for Dev + Prod? |
@filiptdz How did you attempt to set the Content-Type header? |
Yeah, but either I was unsuccessful (I couldn't debug that it was working)
or it didn't solve the issue.
…On Sun, Jun 23, 2019, 14:03 Reginald Johnson ***@***.***> wrote:
@filiptdz <https://github.com/filiptdz> How did you attempt to set the
Content-Type header?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#428>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AE4KTRXTQ23XAMSTGVBXQG3P36UFFANCNFSM4G7HSZHQ>
.
|
@filiptdz Do you mind saying what you did and how you did it? |
@reggie3 I'm sorry, but it's been a couple months. My best guess would be adding it on the |
I fixed the issue by doing the following:
|
This does not fix the issue, as it will not load any resources referenced by the HTML. |
Actually yes it will. Since the html will be processed like an html file. I am just changing the way its imported. I am using webpack and preact with some loaders to generate my html. Everything is working flawlessly. |
You're not getting it. It you have an assets folder with |
Oh this is what you mean. Ok but this is not really an issue, it makes sense. Sorry I was talking about the first issue. If you want to use local assets you need to bundle them inline using webpack or host them externally. |
Well that defeats the purpose of the property that's meant to load an HTML from the assets folder :-) |
If it helps anyone, I resorted to hosting my html file in an S3 bucket and including using
|
Per this comment it appears that |
anyone fix this on Android ? need this urgent. I can't even path the file in android, this path didnt work |
You're free to try fixing it :)
…On Mon, Jul 15, 2019, 05:06 Dale Watson ***@***.***> wrote:
anyone fix this on Android ? need this urgent
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#428>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AE4KTRXQVS37GOECLCKJL7TP7QVYXANCNFSM4G7HSZHQ>
.
|
@dellwatson This workaround may help. That's what we did to get around this issue. It's essentially what @bulby97 suggested above but with a Webpack configuration that bundles everything into a single HTML file to fix the problem pointed out by @danielgindi. |
@paldepind nice one! thanks for sharing |
Any fix for this issue? Appreciate the help |
I'd say this issue is still unresolved
…On Thu, Jan 2, 2020, 21:07 github-actions[bot] ***@***.***> wrote:
Hello 👋, this issue has been opened for more than 2 months with no
activity on it. If the issue is still here, please keep in mind that we
need community support and help to fix it! Just comment something like *still
searching for solutions* and if you found one, please open a pull
request! You have 7 days until this gets closed automatically
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#428>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AE4KTRW5SNQ2RKX7GXKYJ6TQ3Z6VXANCNFSM4G7HSZHQ>
.
|
It seems there are many things that need to be looked into in order to solve this issue. It would be a dream come true if it's resolved though. :) |
still searching for solutions |
@danielgindi I appreciate your detailed comment from last September. Have you learned any more about this in the meantime? |
The following solution works in both iOS and Android Apps. Also I have tested it on Debug and Release builds. Web view component:
chart template file:
|
Very interesting, @samithaf ! |
And if that html template references JS scripts, or images? |
Samithaf's solution doesn't render js or css linked by that html file.
…On Sat, Jun 13, 2020 at 4:34 PM Jamon Holmgren ***@***.***> wrote:
Very interesting, @samithaf <https://github.com/samithaf> !
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#428 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AEN5EZWZ6N7RAGRL35OYTVTRWPPFTANCNFSM4G7HSZHQ>
.
--
Jay Treat
|
@jtreat3 I used this solution to wire up a charting library which had a JS script and it was working. I can tryout again if you can specify the build type that you noticed the problem Here is a sample working solution which got JS and CSS in the HTML file, https://snack.expo.io/@samithaf/react-native-web-view |
I was able to apply CSS with an inline style tag, but I wasn't able to
execute JS, inline or otherwise.
…On Wed, Sep 9, 2020 at 7:07 PM Samitha Fernando ***@***.***> wrote:
@jtreat3 <https://github.com/jtreat3> I used this solution to wire up a
charting library which had a JS script and it was working. I can tryout
again if you can specify the build type that you noticed the problem
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#428 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AEN5EZU4CE2TZZGN7KUQR3LSFADELANCNFSM4G7HSZHQ>
.
--
Jay Treat
|
If you looked at the sample project that I have shared, for sure it execute the JS and draws the chart as well. |
@samithaf, your solution worked! But I had to add @jtreat3, you might want to try adding export const template = () => String.raw`<!doctype html>
<html lang="en">
<head>
<meta name='viewport' content='width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0'/>
</head>
<body>
<h1>Hey React Native</h1>
</body>
</html>` |
@jeloagnasin Good to hear that the solution worked for you. Maybe the solution can be added to |
@samithaf as your solution anything to do with TradingView? I am currently investigating the best way to support loading TV files from local files on Android. |
@Alain1405 I found this workaround when I wanted to show the high-charts in a simple web-view within React Native. Probably you can apply the sample principal to TradingView too? |
Did your html had div tags and js files and script tags? Only static part of html file worked for me, but not dynamic javascript code. |
@jkreddy123 could you please check the following working sample? (this one creates a chart on run time) https://snack.expo.io/@samithaf/react-native-web-view |
@samithaf your solution is quite nice, although using strings of html and JavaScript becomes a problem when the JS itself contains functions which use template literals. Have you encountered the same or figured out a solution for this case? |
Hi @dpwiese , we could preserve functions by using a custom replacer.
Updated version of @samithaf 's example. |
In case anyone else is looking for a different solution here, this is what worked for me: https://medium.com/@snehabagri.90/reactnative-webview-with-local-content-c98a09340801 It is essentially just adding the HTML, JS, and CSS files to android assets and the iOS IPA and then using a local file URI to show it. |
I got this to work on expo, ios, android somehow |
When I use
source={require('./filePath.html')}
, the iOS WebView loads the file correctly, but Android renders it as text instead:The text was updated successfully, but these errors were encountered: