Skip to content

Commit

Permalink
Merge pull request #88 from matthewlloyd/transparent
Browse files Browse the repository at this point in the history
Adds a transparentBackground option for iOS and Android
  • Loading branch information
pichillilorenzo authored May 22, 2019
2 parents 9b02652 + 89d2e0b commit 76ffe41
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ All platforms support:
- __javaScriptEnabled__: Set to `true` to enable JavaScript. The default value is `true`.
- __javaScriptCanOpenWindowsAutomatically__: Set to `true` to allow JavaScript open windows without user interaction. The default value is `false`.
- __mediaPlaybackRequiresUserGesture__: Set to `true` to prevent HTML5 audio or video from autoplaying. The default value is `true`.
- __transparentBackground__: Set to `true` to make the background of the WebView transparent. If your app has a dark theme, this can prevent a white flash on initialization. The default value is `false`.

**Android** supports these additional options:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Picture;
import android.os.Build;
import android.util.AttributeSet;
Expand Down Expand Up @@ -183,6 +184,10 @@ else if (options.clearSessionCache)
settings.setUseWideViewPort(options.useWideViewPort);
settings.setSupportZoom(options.supportZoom);
settings.setTextZoom(options.textZoom);

if (options.transparentBackground) {
setBackgroundColor(Color.TRANSPARENT);
}
}

public void loadUrl(String url, MethodChannel.Result result) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ public class InAppWebViewOptions extends Options {
public boolean domStorageEnabled = false;
public boolean useWideViewPort = true;
public boolean safeBrowsingEnabled = true;

public boolean transparentBackground = false;
}
6 changes: 6 additions & 0 deletions ios/Classes/InAppWebView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,12 @@ public class InAppWebView: WKWebView, UIScrollViewDelegate, WKUIDelegate, WKNavi
configuration.userContentController = WKUserContentController()
configuration.preferences = WKPreferences()

if (options?.transparentBackground)! {
isOpaque = false
backgroundColor = UIColor.clear
scrollView.backgroundColor = UIColor.clear
}

// prevent webView from bouncing
if (options?.disallowOverScroll)! {
if responds(to: #selector(getter: scrollView)) {
Expand Down
1 change: 1 addition & 0 deletions ios/Classes/InAppWebViewOptions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public class InAppWebViewOptions: Options {
var ignoresViewportScaleLimits = false
var allowsInlineMediaPlayback = false
var allowsPictureInPictureMediaPlayback = true
var transparentBackground = false

override init(){
super.init()
Expand Down
1 change: 1 addition & 0 deletions lib/flutter_inappbrowser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ class InAppBrowser {
/// - __toolbarTopBackgroundColor__: Set the custom background color of the toolbar at the top.
/// - __hideUrlBar__: Set to `true` to hide the url bar on the toolbar at the top. The default value is `false`.
/// - __mediaPlaybackRequiresUserGesture__: Set to `true` to prevent HTML5 audio or video from autoplaying. The default value is `true`.
/// - __transparentBackground__: Set to `true` to make the background of the WebView transparent. If your app has a dark theme, this can prevent a white flash on initialization. The default value is `false`.
///
/// - **Android** supports these additional options:
///
Expand Down

0 comments on commit 76ffe41

Please sign in to comment.