Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

Commit fd82d71

Browse files
committed
put webview with transparent background
fix flutter/flutter#29300
1 parent 432f775 commit fd82d71

2 files changed

Lines changed: 10 additions & 0 deletions

File tree

packages/webview_flutter/android/src/main/java/io/flutter/plugins/webviewflutter/FlutterWebView.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
import android.annotation.TargetApi;
88
import android.content.Context;
9+
import android.graphics.Color;
910
import android.os.Build;
1011
import android.view.View;
1112
import android.webkit.WebStorage;
@@ -28,6 +29,7 @@ public class FlutterWebView implements PlatformView, MethodCallHandler {
2829
@SuppressWarnings("unchecked")
2930
FlutterWebView(Context context, BinaryMessenger messenger, int id, Map<String, Object> params) {
3031
webView = new WebView(context);
32+
webView.setBackgroundColor(Color.TRANSPARENT);
3133
// Allow local storage.
3234
webView.getSettings().setDomStorageEnabled(true);
3335

@@ -101,6 +103,7 @@ public void onMethodCall(MethodCall methodCall, Result result) {
101103
private void loadUrl(MethodCall methodCall, Result result) {
102104
String url = (String) methodCall.arguments;
103105
webView.loadUrl(url);
106+
webView.setBackgroundColor(Color.TRANSPARENT);
104107
result.success(null);
105108
}
106109

packages/webview_flutter/ios/Classes/FlutterWebView.m

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@ - (instancetype)initWithFrame:(CGRect)frame
6666
configuration.userContentController = userContentController;
6767

6868
_webView = [[WKWebView alloc] initWithFrame:frame configuration:configuration];
69+
_webView.opaque = NO;
70+
_webView.backgroundColor = UIColor.clearColor;
71+
_webView.scrollView.backgroundColor = UIColor.clearColor;
72+
6973
_navigationDelegate = [[FLTWKNavigationDelegate alloc] initWithChannel:_channel];
7074
_webView.navigationDelegate = _navigationDelegate;
7175
__weak __typeof__(self) weakSelf = self;
@@ -263,6 +267,9 @@ - (bool)loadUrl:(NSString*)url {
263267
}
264268
NSURLRequest* req = [NSURLRequest requestWithURL:nsUrl];
265269
[_webView loadRequest:req];
270+
_webView.opaque = NO;
271+
_webView.backgroundColor = UIColor.clearColor;
272+
_webView.scrollView.backgroundColor = UIColor.clearColor;
266273
return true;
267274
}
268275

0 commit comments

Comments
 (0)