Skip to content
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

Adds a transparentBackground option for iOS and Android #88

Merged
merged 1 commit into from
May 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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