-
Notifications
You must be signed in to change notification settings - Fork 9.8k
[webview_flutter] put webview with transparent background #1336
Conversation
e36da33
to
fd82d71
Compare
will it be merged soon? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the contribution!
Left a few comments/questions.
Please also update the example app with a sample that shows this in action.
@@ -101,6 +103,7 @@ public void onMethodCall(MethodCall methodCall, Result result) { | |||
private void loadUrl(MethodCall methodCall, Result result) { | |||
String url = (String) methodCall.arguments; | |||
webView.loadUrl(url); | |||
webView.setBackgroundColor(Color.TRANSPARENT); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to do this after each loadUrl?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I remember reading that if you don't on some device or iOS version you might have trouble... but I can't find back the source, maybe I dream it... I'll remove this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In fact I just tested when update the example app and in fact the web view is not transparent even with this ! :( searching why if anyone have an idea...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd guess that the VD hosting it needs to be made transparent as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is VD hosting ? I'm not familiar with that, on iOS side there no problem thing are not working the same in Android?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@amirh bump ^^ :) where do I look for this ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Getting this to work may require changes to the platform views code in the engine, you can take a look here as a starting point: https://github.com/flutter/engine/blob/master/shell/platform/android/io/flutter/plugin/platform/PlatformViewsController.java
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @amirh I'll try to take a look at this but I'm going deep into flutter with that lol let's see
@@ -28,6 +29,7 @@ | |||
@SuppressWarnings("unchecked") | |||
FlutterWebView(Context context, BinaryMessenger messenger, int id, Map<String, Object> params) { | |||
webView = new WebView(context); | |||
webView.setBackgroundColor(Color.TRANSPARENT); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm curious whether it works through the virtual display compositing...
@@ -66,6 +66,10 @@ - (instancetype)initWithFrame:(CGRect)frame | |||
configuration.userContentController = userContentController; | |||
|
|||
_webView = [[WKWebView alloc] initWithFrame:frame configuration:configuration]; | |||
_webView.opaque = NO; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a performance penalty for doing this? should we only do this if the developer asked?
@chinmaygarde do you happen to know?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't find any performance penalty information by playing with this parameter on my side
c01c5b0
to
dfb6d63
Compare
I've also had problems like yours. https://github.com/lzxb/flutter-webview-black-screen/blob/master/black-screen.mp4 |
Flutter webview plugin black screen |
Transparent background is not working on Android |
Are there any updates on this? 🤔 |
Anyone working on? |
I believe this is possible on Android since flutter/engine#9849 not sure if we even need the setBackgroundColor. We should probably remove the setBackground calls from everywhere but the constructor. We should also confirm whether the setBackground in the constructor is needed. This will need a test before it can land. |
dfb6d63
to
968e4b1
Compare
968e4b1
to
7255aeb
Compare
@bparrishMines @amirh should be ok now :) |
@amirh What's about this now? I seriously need this change for my |
Can't believe it's been a year. Please merge it if it's alright. ;( |
I'm also using the fork for some time... please merge 👍 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jaumard As Amir stated in a comment, I believe we want the developer to have the option to make the background transparent and not have it as transparent by default.
Could we add this as a parameter in Webview and pass this as a creation parameter?
As for testing it should be sufficient to include this in the creation test.
Since the original author didn't fix it for months, I decided to create another PR: #2895 |
Thank you for your contribution. I'm going to close this PR for now since there are outstanding comments, just to get this off our PR review queue. Please don't hesitate to submit a new PR (or follow up on #2895) if you have the time to address the review comments. Thanks! |
fix flutter/flutter#29300
to use it right now: