diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index 09bdae7b..07493bda 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -14,7 +14,36 @@
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -31,37 +60,38 @@
-
+
-
+
+
-
+
-
+
-
+
-
-
+
+
-
+
-
-
+
+
-
+
@@ -71,7 +101,7 @@
-
+
@@ -82,20 +112,11 @@
-
-
-
-
-
-
-
-
-
-
-
+
+
@@ -103,8 +124,8 @@
-
-
+
+
@@ -112,11 +133,23 @@
+
+
+
+
+
+
+
+
+
+
+
+
-
-
+
+
@@ -127,8 +160,8 @@
-
-
+
+
@@ -137,11 +170,7 @@
-
-
-
-
-
+
@@ -157,9 +186,6 @@
- InAppWebView {
- lookupMimeType
- AndroidView_uuidGeneratorin the flutterRELOAD
@@ -187,6 +213,9 @@
__safeBrowsingEnabled____safe__textZoom
+ hidden
+ builtInZoomControls
+ __builtInZoomControls__activity.getPreferences(0)
@@ -239,17 +268,17 @@
-
+
-
-
+
+
-
+
@@ -290,17 +319,6 @@
-
-
-
-
-
-
-
-
-
-
-
@@ -308,17 +326,6 @@
-
-
-
-
-
-
-
-
-
-
-
@@ -329,6 +336,17 @@
+
+
+
+
+
+
+
+
+
+
+
@@ -465,12 +483,21 @@
+
+
+
+
+
+
+
+
+
-
+
-
-
+
+
@@ -479,15 +506,15 @@
-
-
+
+
-
+
-
+
@@ -736,65 +763,61 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
+
+
diff --git a/CHANGELOG.md b/CHANGELOG.md
index aeb55744..958d806d 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,13 @@
+## 1.2.0
+
+- Merge "Adds a transparentBackground option for iOS and Android" [#86](https://github.com/pichillilorenzo/flutter_inappbrowser/pull/86) (thanks to [matthewlloyd](https://github.com/matthewlloyd))
+- Merge "The 'open' method requires an options dictionary" [#87](https://github.com/pichillilorenzo/flutter_inappbrowser/pull/87) (thanks to [matthewlloyd](https://github.com/matthewlloyd))
+- Merge "iOS: Call setNeedsLayout() in scrollViewDidScroll()" [#88](https://github.com/pichillilorenzo/flutter_inappbrowser/pull/88) (thanks to [matthewlloyd](https://github.com/matthewlloyd))
+- Fixed "java.lang.RuntimeException: Methods marked with @UiThread must be executed on the main thread." [#98](https://github.com/pichillilorenzo/flutter_inappbrowser/issues/98) (thanks to [DreamBuddy](https://github.com/DreamBuddy))
+- Fixed "app force close/crash when enabling zoom and repeatedly changing orientation and zoomin zoomout" [#93](https://github.com/pichillilorenzo/flutter_inappbrowser/issues/93)
+- Added `displayZoomControls` webview option for Android
+- Fixed "Compatibility with other plugins" [#80](https://github.com/pichillilorenzo/flutter_inappbrowser/issues/80)
+
## 1.1.3
- Merge "Add null checks around calls to InAppWebView callbacks" [#85](https://github.com/pichillilorenzo/flutter_inappbrowser/pull/85) (thanks to [matthewlloyd](https://github.com/matthewlloyd))
diff --git a/README.md b/README.md
index d357d9be..4763f67c 100644
--- a/README.md
+++ b/README.md
@@ -246,6 +246,7 @@ All platforms support:
- __clearSessionCache__: Set to `true` to have the session cookie cache cleared before the new window is opened.
- __builtInZoomControls__: Set to `true` if the WebView should use its built-in zoom mechanisms. The default value is `false`.
+ - __displayZoomControls__: Set to `true` if the WebView should display on-screen zoom controls when using the built-in zoom mechanisms. The default value is `false`.
- __supportZoom__: Set to `false` if the WebView should not support zooming using its on-screen zoom controls and gestures. The default value is `true`.
- __databaseEnabled__: Set to `true` if you want the database storage API is enabled. The default value is `false`.
- __domStorageEnabled__: Set to `true` if you want the DOM storage API is enabled. The default value is `false`.
@@ -819,6 +820,7 @@ Opens an `url` in a new `InAppBrowser` instance.
- __closeOnCannotGoBack__: Set to `false` to not close the InAppBrowser when the user click on the back button and the WebView cannot go back to the history. The default value is `true`.
- __clearSessionCache__: Set to `true` to have the session cookie cache cleared before the new window is opened.
- __builtInZoomControls__: Set to `true` if the WebView should use its built-in zoom mechanisms. The default value is `false`.
+ - __displayZoomControls__: Set to `true` if the WebView should display on-screen zoom controls when using the built-in zoom mechanisms. The default value is `false`.
- __supportZoom__: Set to `false` if the WebView should not support zooming using its on-screen zoom controls and gestures. The default value is `true`.
- __databaseEnabled__: Set to `true` if you want the database storage API is enabled. The default value is `false`.
- __domStorageEnabled__: Set to `true` if you want the DOM storage API is enabled. The default value is `false`.
diff --git a/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/FlutterWebView.java b/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/FlutterWebView.java
index 5947173a..a2ae78bf 100644
--- a/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/FlutterWebView.java
+++ b/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/FlutterWebView.java
@@ -30,13 +30,11 @@ public class FlutterWebView implements PlatformView, MethodCallHandler {
public InAppWebView webView;
public MethodChannel channel;
public final Registrar registrar;
- public final Context context;
public FlutterWebView(Registrar registrar, int id, HashMap params) {
this.registrar = registrar;
this.activity = registrar.activity();
- this.context = registrar.context();
String initialUrl = (String) params.get("initialUrl");
String initialFile = (String) params.get("initialFile");
@@ -47,7 +45,7 @@ public class FlutterWebView implements PlatformView, MethodCallHandler {
InAppWebViewOptions options = new InAppWebViewOptions();
options.parse(initialOptions);
- webView = new InAppWebView(context, this, id, options);
+ webView = new InAppWebView(registrar, this, id, options);
webView.prepare();
channel = new MethodChannel(registrar.messenger(), "com.pichillilorenzo/flutter_inappwebview_" + id);
diff --git a/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/FlutterWebViewFactory.java b/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/FlutterWebViewFactory.java
index fac312a5..abd42684 100644
--- a/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/FlutterWebViewFactory.java
+++ b/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/FlutterWebViewFactory.java
@@ -1,26 +1,20 @@
package com.pichillilorenzo.flutter_inappbrowser;
-import android.app.Activity;
import android.content.Context;
import java.util.HashMap;
-import io.flutter.plugin.common.BinaryMessenger;
import io.flutter.plugin.common.PluginRegistry.Registrar;
import io.flutter.plugin.common.StandardMessageCodec;
import io.flutter.plugin.platform.PlatformView;
import io.flutter.plugin.platform.PlatformViewFactory;
public class FlutterWebViewFactory extends PlatformViewFactory {
- private final BinaryMessenger messenger;
private final Registrar registrar;
- private final Activity activity;
- public FlutterWebViewFactory(Registrar registrar, Activity activity) {
+ public FlutterWebViewFactory(Registrar registrar) {
super(StandardMessageCodec.INSTANCE);
this.registrar = registrar;
- this.messenger = registrar.messenger();
- this.activity = activity;
}
@Override
diff --git a/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/InAppBrowserActivity.java b/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/InAppBrowserActivity.java
index e7c5b837..4bd20fb1 100644
--- a/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/InAppBrowserActivity.java
+++ b/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/InAppBrowserActivity.java
@@ -1,5 +1,6 @@
package com.pichillilorenzo.flutter_inappbrowser;
+import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.Canvas;
@@ -9,6 +10,7 @@ import android.graphics.drawable.ColorDrawable;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
+import android.util.Log;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuInflater;
@@ -25,6 +27,8 @@ import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
+import io.flutter.app.FlutterActivity;
+import io.flutter.app.FlutterApplication;
import io.flutter.plugin.common.MethodChannel;
public class InAppBrowserActivity extends AppCompatActivity {
@@ -39,6 +43,7 @@ public class InAppBrowserActivity extends AppCompatActivity {
public Map headers;
public ProgressBar progressBar;
public boolean isHidden = false;
+ public String fromActivity;
@Override
protected void onCreate(Bundle savedInstanceState) {
@@ -51,6 +56,7 @@ public class InAppBrowserActivity extends AppCompatActivity {
Bundle b = getIntent().getExtras();
uuid = b.getString("uuid");
+ fromActivity = b.getString("fromActivity");
HashMap optionsMap = (HashMap) b.getSerializable("options");
@@ -247,7 +253,7 @@ public class InAppBrowserActivity extends AppCompatActivity {
if (canGoBack())
goBack();
else if (options.closeOnCannotGoBack)
- InAppBrowserFlutterPlugin.close(uuid, null);
+ InAppBrowserFlutterPlugin.close(this, uuid, null);
return true;
}
return super.onKeyDown(keyCode, event);
@@ -297,15 +303,20 @@ public class InAppBrowserActivity extends AppCompatActivity {
}
public void hide() {
- isHidden = true;
- Intent openActivity = new Intent(this, InAppBrowserFlutterPlugin.registrar.activity().getClass());
- openActivity.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
- startActivityIfNeeded(openActivity, 0);
+ try {
+ isHidden = true;
+ Intent openActivity = new Intent(this, Class.forName(fromActivity));
+ openActivity.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
+ startActivityIfNeeded(openActivity, 0);
+ } catch (ClassNotFoundException e) {
+ e.printStackTrace();
+ Log.d(LOG_TAG, e.getMessage());
+ }
}
public void show() {
isHidden = false;
- Intent openActivity = new Intent(InAppBrowserFlutterPlugin.registrar.activity(), InAppBrowserActivity.class);
+ Intent openActivity = new Intent(this, InAppBrowserActivity.class);
openActivity.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
startActivityIfNeeded(openActivity, 0);
}
@@ -341,7 +352,7 @@ public class InAppBrowserActivity extends AppCompatActivity {
}
public void closeButtonClicked(MenuItem item) {
- InAppBrowserFlutterPlugin.close(uuid, null);
+ InAppBrowserFlutterPlugin.close(this, uuid, null);
}
public byte[] takeScreenshot() {
diff --git a/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/InAppBrowserFlutterPlugin.java b/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/InAppBrowserFlutterPlugin.java
index 83fe334a..ace324e6 100644
--- a/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/InAppBrowserFlutterPlugin.java
+++ b/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/InAppBrowserFlutterPlugin.java
@@ -22,6 +22,7 @@
package com.pichillilorenzo.flutter_inappbrowser;
import android.app.Activity;
+import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
@@ -39,13 +40,12 @@ import com.pichillilorenzo.flutter_inappbrowser.ChromeCustomTabs.CustomTabActivi
import java.io.IOException;
import java.io.Serializable;
-import java.net.MalformedURLException;
-import java.net.URL;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import io.flutter.app.FlutterApplication;
import io.flutter.plugin.common.MethodCall;
import io.flutter.plugin.common.MethodChannel;
import io.flutter.plugin.common.MethodChannel.MethodCallHandler;
@@ -57,17 +57,15 @@ import io.flutter.plugin.common.PluginRegistry.Registrar;
*/
public class InAppBrowserFlutterPlugin implements MethodCallHandler {
- public static Registrar registrar;
- public Activity activity;
+ public Registrar registrar;
public static MethodChannel channel;
public static Map webViewActivities = new HashMap<>();
public static Map chromeCustomTabsActivities = new HashMap<>();
protected static final String LOG_TAG = "IABFlutterPlugin";
- public InAppBrowserFlutterPlugin(Registrar r, Activity activity) {
+ public InAppBrowserFlutterPlugin(Registrar r) {
registrar = r;
- this.activity = activity;
channel = new MethodChannel(registrar.messenger(), "com.pichillilorenzo/flutter_inappbrowser");
}
@@ -76,23 +74,26 @@ public class InAppBrowserFlutterPlugin implements MethodCallHandler {
*/
public static void registerWith(Registrar registrar) {
Activity activity = registrar.activity();
+ // registrar.activity() may return null because of Flutter's background execution feature
+ // described here: https://medium.com/flutter-io/executing-dart-in-the-background-with-flutter-plugins-and-geofencing-2b3e40a1a124
+ if (activity != null) {
+ final MethodChannel channel = new MethodChannel(registrar.messenger(), "com.pichillilorenzo/flutter_inappbrowser");
+ channel.setMethodCallHandler(new InAppBrowserFlutterPlugin(registrar));
- final MethodChannel channel = new MethodChannel(registrar.messenger(), "com.pichillilorenzo/flutter_inappbrowser");
- channel.setMethodCallHandler(new InAppBrowserFlutterPlugin(registrar, activity));
+ new MyCookieManager(registrar);
- new MyCookieManager(registrar);
-
- registrar
- .platformViewRegistry()
- .registerViewFactory(
- "com.pichillilorenzo/flutter_inappwebview", new FlutterWebViewFactory(registrar, activity));
+ registrar
+ .platformViewRegistry()
+ .registerViewFactory(
+ "com.pichillilorenzo/flutter_inappwebview", new FlutterWebViewFactory(registrar));
+ }
}
@Override
public void onMethodCall(final MethodCall call, final Result result) {
String source;
- String jsWrapper;
String urlFile;
+ final Activity activity = registrar.activity();
final String uuid = (String) call.argument("uuid");
switch (call.method) {
@@ -107,7 +108,7 @@ public class InAppBrowserFlutterPlugin implements MethodCallHandler {
Log.d(LOG_TAG, "use Chrome Custom Tabs = " + useChromeSafariBrowser);
- this.activity.runOnUiThread(new Runnable() {
+ activity.runOnUiThread(new Runnable() {
@Override
public void run() {
@@ -119,7 +120,7 @@ public class InAppBrowserFlutterPlugin implements MethodCallHandler {
final HashMap optionsFallback = (HashMap) call.argument("optionsFallback");
- open(uuid, uuidFallback, url_final, options, headers, true, optionsFallback, result);
+ open(activity, uuid, uuidFallback, url_final, options, headers, true, optionsFallback, result);
} else {
String url = url_final;
@@ -142,7 +143,7 @@ public class InAppBrowserFlutterPlugin implements MethodCallHandler {
// SYSTEM
if (openWithSystemBrowser) {
Log.d(LOG_TAG, "in system");
- openExternal(url, result);
+ openExternal(activity, url, result);
} else {
//Load the dialer
if (url.startsWith(WebView.SCHEME_TEL)) {
@@ -158,7 +159,7 @@ public class InAppBrowserFlutterPlugin implements MethodCallHandler {
// load in InAppBrowserFlutterPlugin
else {
Log.d(LOG_TAG, "loading in InAppBrowserFlutterPlugin");
- open(uuid, null, url, options, headers, false, null, result);
+ open(activity, uuid, null, url, options, headers, false, null, result);
}
}
}
@@ -166,7 +167,7 @@ public class InAppBrowserFlutterPlugin implements MethodCallHandler {
});
}
else {
- this.activity.runOnUiThread(new Runnable() {
+ activity.runOnUiThread(new Runnable() {
@Override
public void run() {
HashMap options = (HashMap) call.argument("options");
@@ -174,7 +175,7 @@ public class InAppBrowserFlutterPlugin implements MethodCallHandler {
String mimeType = call.argument("mimeType").toString();
String encoding = call.argument("encoding").toString();
String baseUrl = call.argument("baseUrl").toString();
- openData(uuid, options, data, mimeType, encoding, baseUrl);
+ openData(activity, uuid, options, data, mimeType, encoding, baseUrl);
result.success(true);
}
});
@@ -208,7 +209,7 @@ public class InAppBrowserFlutterPlugin implements MethodCallHandler {
loadFile(uuid, call.argument("url").toString(), (Map) call.argument("headers"), result);
break;
case "close":
- close(uuid, result);
+ close(activity, uuid, result);
break;
case "injectScriptCode":
source = call.argument("source").toString();
@@ -349,7 +350,7 @@ public class InAppBrowserFlutterPlugin implements MethodCallHandler {
* @param result
* @return "" if ok, or error message.
*/
- public void openExternal(String url, Result result) {
+ public void openExternal(Activity activity, String url, Result result) {
try {
Intent intent;
intent = new Intent(Intent.ACTION_VIEW);
@@ -363,7 +364,7 @@ public class InAppBrowserFlutterPlugin implements MethodCallHandler {
}
intent.putExtra(Browser.EXTRA_APPLICATION_ID, activity.getPackageName());
// CB-10795: Avoid circular loops by preventing it from opening in the current app
- this.openExternalExcludeCurrentApp(intent);
+ this.openExternalExcludeCurrentApp(activity, intent);
result.success(true);
// not catching FileUriExposedException explicitly because buildtools<24 doesn't know about it
} catch (java.lang.RuntimeException e) {
@@ -376,7 +377,7 @@ public class InAppBrowserFlutterPlugin implements MethodCallHandler {
* Opens the intent, providing a chooser that excludes the current app to avoid
* circular loops.
*/
- private void openExternalExcludeCurrentApp(Intent intent) {
+ private void openExternalExcludeCurrentApp(Activity activity, Intent intent) {
String currentPackage = activity.getPackageName();
boolean hasCurrentPackage = false;
PackageManager pm = activity.getPackageManager();
@@ -408,10 +409,11 @@ public class InAppBrowserFlutterPlugin implements MethodCallHandler {
}
}
- public void open(String uuid, String uuidFallback, String url, HashMap options, Map headers, boolean useChromeSafariBrowser, HashMap optionsFallback, Result result) {
+ public void open(Activity activity, String uuid, String uuidFallback, String url, HashMap options, Map headers, boolean useChromeSafariBrowser, HashMap optionsFallback, Result result) {
Intent intent = null;
Bundle extras = new Bundle();
+ extras.putString("fromActivity", activity.getClass().getName());
extras.putString("url", url);
extras.putBoolean("isData", false);
extras.putString("uuid", uuid);
@@ -451,7 +453,7 @@ public class InAppBrowserFlutterPlugin implements MethodCallHandler {
result.error(LOG_TAG, "No WebView fallback declared.", null);
}
- public void openData(String uuid, HashMap options, String data, String mimeType, String encoding, String baseUrl) {
+ public void openData(Activity activity, String uuid, HashMap options, String data, String mimeType, String encoding, String baseUrl) {
Intent intent = new Intent(activity, InAppBrowserActivity.class);
Bundle extras = new Bundle();
@@ -597,10 +599,10 @@ public class InAppBrowserFlutterPlugin implements MethodCallHandler {
return false;
}
- public static void close(final String uuid, final Result result) {
+ public static void close(Activity activity, final String uuid, final Result result) {
final InAppBrowserActivity inAppBrowserActivity = webViewActivities.get(uuid);
if (inAppBrowserActivity != null) {
- registrar.activity().runOnUiThread(new Runnable() {
+ activity.runOnUiThread(new Runnable() {
@Override
public void run() {
diff --git a/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/InAppWebView/InAppWebView.java b/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/InAppWebView/InAppWebView.java
index 568df3ad..cdf8e313 100644
--- a/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/InAppWebView/InAppWebView.java
+++ b/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/InAppWebView/InAppWebView.java
@@ -32,15 +32,15 @@ import java.util.List;
import java.util.Map;
import io.flutter.plugin.common.MethodChannel;
+import io.flutter.plugin.common.PluginRegistry;
import okhttp3.Cache;
import okhttp3.OkHttpClient;
-import static com.pichillilorenzo.flutter_inappbrowser.InAppBrowserFlutterPlugin.registrar;
-
public class InAppWebView extends WebView {
static final String LOG_TAG = "InAppWebView";
+ public PluginRegistry.Registrar registrar;
public InAppBrowserActivity inAppBrowserActivity;
public FlutterWebView flutterWebView;
int id;
@@ -91,8 +91,9 @@ public class InAppWebView extends WebView {
super(context, attrs, defaultStyle);
}
- public InAppWebView(Context context, Object obj, int id, InAppWebViewOptions options) {
- super(context);
+ public InAppWebView(PluginRegistry.Registrar registrar, Object obj, int id, InAppWebViewOptions options) {
+ super(registrar.activeContext());
+ this.registrar = registrar;
if (obj instanceof InAppBrowserActivity)
this.inAppBrowserActivity = (InAppBrowserActivity) obj;
else if (obj instanceof FlutterWebView)
@@ -160,6 +161,8 @@ public class InAppWebView extends WebView {
settings.setJavaScriptEnabled(options.javaScriptEnabled);
settings.setJavaScriptCanOpenWindowsAutomatically(options.javaScriptCanOpenWindowsAutomatically);
settings.setBuiltInZoomControls(options.builtInZoomControls);
+ settings.setDisplayZoomControls(options.displayZoomControls);
+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
settings.setSafeBrowsingEnabled(options.safeBrowsingEnabled);
@@ -312,6 +315,9 @@ public class InAppWebView extends WebView {
if (newOptionsMap.get("builtInZoomControls") != null && options.builtInZoomControls != newOptions.builtInZoomControls)
settings.setBuiltInZoomControls(newOptions.builtInZoomControls);
+ if (newOptionsMap.get("displayZoomControls") != null && options.displayZoomControls != newOptions.displayZoomControls)
+ settings.setDisplayZoomControls(newOptions.displayZoomControls);
+
if (newOptionsMap.get("safeBrowsingEnabled") != null && options.safeBrowsingEnabled != newOptions.safeBrowsingEnabled && Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
settings.setSafeBrowsingEnabled(newOptions.safeBrowsingEnabled);
@@ -341,6 +347,14 @@ public class InAppWebView extends WebView {
if (newOptionsMap.get("textZoom") != null && options.textZoom != newOptions.textZoom)
settings.setTextZoom(newOptions.textZoom);
+ if (newOptionsMap.get("transparentBackground") != null && options.transparentBackground != newOptions.transparentBackground) {
+ if (newOptions.transparentBackground) {
+ setBackgroundColor(Color.TRANSPARENT);
+ } else {
+ setBackgroundColor(Color.parseColor("#FFFFFF"));
+ }
+ }
+
options = newOptions;
}
diff --git a/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/InAppWebView/InAppWebViewClient.java b/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/InAppWebView/InAppWebViewClient.java
index 2fb60f01..2dc0936f 100644
--- a/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/InAppWebView/InAppWebViewClient.java
+++ b/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/InAppWebView/InAppWebViewClient.java
@@ -6,6 +6,9 @@ import android.net.Uri;
import android.net.http.SslError;
import android.os.Build;
import androidx.annotation.RequiresApi;
+
+import android.os.Handler;
+import android.os.Looper;
import android.util.Log;
import android.webkit.CookieManager;
import android.webkit.CookieSyncManager;
@@ -341,7 +344,7 @@ public class InAppWebViewClient extends WebViewClient {
headersRequest.put(entry.getKey().toLowerCase(), value.toString());
}
- Map obj = new HashMap<>();
+ final Map obj = new HashMap<>();
Map res = new HashMap<>();
Map req = new HashMap<>();
@@ -365,7 +368,15 @@ public class InAppWebViewClient extends WebViewClient {
obj.put("response", res);
obj.put("request", req);
- getChannel().invokeMethod("onLoadResource", obj);
+ // java.lang.RuntimeException: Methods marked with @UiThread must be executed on the main thread.
+ // https://github.com/pichillilorenzo/flutter_inappbrowser/issues/98
+ final Handler handler = new Handler(Looper.getMainLooper());
+ handler.post(new Runnable() {
+ @Override
+ public void run() {
+ getChannel().invokeMethod("onLoadResource", obj);
+ }
+ });
// this return is not working (it blocks some resources), so return null
// return new WebResourceResponse(
diff --git a/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/InAppWebView/InAppWebViewOptions.java b/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/InAppWebView/InAppWebViewOptions.java
index 550a90e5..9391ada7 100644
--- a/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/InAppWebView/InAppWebViewOptions.java
+++ b/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/InAppWebView/InAppWebViewOptions.java
@@ -17,6 +17,7 @@ public class InAppWebViewOptions extends Options {
public boolean clearSessionCache = false;
public boolean builtInZoomControls = false;
+ public boolean displayZoomControls = false;
public boolean supportZoom = true;
public boolean databaseEnabled = false;
public boolean domStorageEnabled = false;
diff --git a/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/JavaScriptBridgeInterface.java b/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/JavaScriptBridgeInterface.java
index 2ed9320a..9f404803 100644
--- a/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/JavaScriptBridgeInterface.java
+++ b/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/JavaScriptBridgeInterface.java
@@ -1,6 +1,8 @@
package com.pichillilorenzo.flutter_inappbrowser;
import android.os.Build;
+import android.os.Handler;
+import android.os.Looper;
import android.util.Log;
import android.webkit.JavascriptInterface;
@@ -34,33 +36,42 @@ public class JavaScriptBridgeInterface {
@JavascriptInterface
public void _callHandler(String handlerName, final String _callHandlerID, String args) {
- Map obj = new HashMap<>();
+ final Map obj = new HashMap<>();
if (inAppBrowserActivity != null)
obj.put("uuid", inAppBrowserActivity.uuid);
obj.put("handlerName", handlerName);
obj.put("args", args);
- getChannel().invokeMethod("onCallJsHandler", obj, new MethodChannel.Result() {
+ // java.lang.RuntimeException: Methods marked with @UiThread must be executed on the main thread.
+ // https://github.com/pichillilorenzo/flutter_inappbrowser/issues/98
+ final Handler handler = new Handler(Looper.getMainLooper());
+ handler.post(new Runnable() {
@Override
- public void success(Object json) {
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
- flutterWebView.webView.evaluateJavascript("window." + name + "[" + _callHandlerID + "](" + json + "); delete window." + name + "[" + _callHandlerID + "];", null);
- }
- else {
- flutterWebView.webView.loadUrl("javascript:window." + name + "[" + _callHandlerID + "](" + json + "); delete window." + name + "[" + _callHandlerID + "];");
- }
- }
+ public void run() {
+ getChannel().invokeMethod("onCallJsHandler", obj, new MethodChannel.Result() {
+ @Override
+ public void success(Object json) {
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
+ flutterWebView.webView.evaluateJavascript("window." + name + "[" + _callHandlerID + "](" + json + "); delete window." + name + "[" + _callHandlerID + "];", null);
+ }
+ else {
+ flutterWebView.webView.loadUrl("javascript:window." + name + "[" + _callHandlerID + "](" + json + "); delete window." + name + "[" + _callHandlerID + "];");
+ }
+ }
- @Override
- public void error(String s, String s1, Object o) {
- Log.d(LOG_TAG, "ERROR: " + s + " " + s1);
- }
+ @Override
+ public void error(String s, String s1, Object o) {
+ Log.d(LOG_TAG, "ERROR: " + s + " " + s1);
+ }
- @Override
- public void notImplemented() {
+ @Override
+ public void notImplemented() {
+ }
+ });
}
});
+
}
private MethodChannel getChannel() {
diff --git a/ios/Classes/InAppWebView.swift b/ios/Classes/InAppWebView.swift
index 156cfcaf..d51c34b1 100644
--- a/ios/Classes/InAppWebView.swift
+++ b/ios/Classes/InAppWebView.swift
@@ -112,7 +112,7 @@ public class InAppWebView: WKWebView, UIScrollViewDelegate, WKUIDelegate, WKNavi
configuration.userContentController = WKUserContentController()
configuration.preferences = WKPreferences()
-
+
if (options?.transparentBackground)! {
isOpaque = false
backgroundColor = UIColor.clear
@@ -299,6 +299,18 @@ public class InAppWebView: WKWebView, UIScrollViewDelegate, WKUIDelegate, WKNavi
func setOptions(newOptions: InAppWebViewOptions, newOptionsMap: [String: Any]) {
+ if newOptionsMap["transparentBackground"] != nil && options?.transparentBackground != newOptions.transparentBackground {
+ if newOptions.transparentBackground {
+ isOpaque = false
+ backgroundColor = UIColor.clear
+ scrollView.backgroundColor = UIColor.clear
+ } else {
+ isOpaque = true
+ backgroundColor = nil
+ scrollView.backgroundColor = UIColor(red: 1, green: 1, blue: 1, alpha: 1)
+ }
+ }
+
if newOptionsMap["disallowOverScroll"] != nil && options?.disallowOverScroll != newOptions.disallowOverScroll {
if responds(to: #selector(getter: scrollView)) {
scrollView.bounces = !newOptions.disallowOverScroll
diff --git a/lib/flutter_inappbrowser.dart b/lib/flutter_inappbrowser.dart
index ffd5a11e..ed779328 100644
--- a/lib/flutter_inappbrowser.dart
+++ b/lib/flutter_inappbrowser.dart
@@ -179,6 +179,7 @@ class InAppBrowser {
/// - __closeOnCannotGoBack__: Set to `false` to not close the InAppBrowser when the user click on the back button and the WebView cannot go back to the history. The default value is `true`.
/// - __clearSessionCache__: Set to `true` to have the session cookie cache cleared before the new window is opened.
/// - __builtInZoomControls__: Set to `true` if the WebView should use its built-in zoom mechanisms. The default value is `false`.
+ /// - __displayZoomControls__: Set to `true` if the WebView should display on-screen zoom controls when using the built-in zoom mechanisms. The default value is `false`.
/// - __supportZoom__: Set to `false` if the WebView should not support zooming using its on-screen zoom controls and gestures. The default value is `true`.
/// - __databaseEnabled__: Set to `true` if you want the database storage API is enabled. The default value is `false`.
/// - __domStorageEnabled__: Set to `true` if you want the DOM storage API is enabled. The default value is `false`.
@@ -582,11 +583,13 @@ class InAppWebViewInitialData {
/// - __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:
///
/// - __clearSessionCache__: Set to `true` to have the session cookie cache cleared before the new window is opened.
/// - __builtInZoomControls__: Set to `true` if the WebView should use its built-in zoom mechanisms. The default value is `false`.
+/// - __displayZoomControls__: Set to `true` if the WebView should display on-screen zoom controls when using the built-in zoom mechanisms. The default value is `false`.
/// - __supportZoom__: Set to `false` if the WebView should not support zooming using its on-screen zoom controls and gestures. The default value is `true`.
/// - __databaseEnabled__: Set to `true` if you want the database storage API is enabled. The default value is `false`.
/// - __domStorageEnabled__: Set to `true` if you want the DOM storage API is enabled. The default value is `false`.
@@ -652,6 +655,13 @@ class InAppWebView extends StatefulWidget {
final Map initialHeaders;
///Initial options that will be used.
final Map initialOptions;
+ /// `gestureRecognizers` specifies which gestures should be consumed by the web view.
+ /// It is possible for other gesture recognizers to be competing with the web view on pointer
+ /// events, e.g if the web view is inside a [ListView] the [ListView] will want to handle
+ /// vertical drags. The web view will claim gestures that are recognized by any of the
+ /// recognizers on this list.
+ /// When `gestureRecognizers` is empty or null, the web view will only handle pointer events for gestures that
+ /// were not claimed by any other gesture recognizer.
final Set> gestureRecognizers;
const InAppWebView({
@@ -695,6 +705,7 @@ class _InAppWebViewState extends State {
if (defaultTargetPlatform == TargetPlatform.android) {
return GestureDetector(
onLongPress: () {},
+ excludeFromSemantics: true,
child: AndroidView(
viewType: 'com.pichillilorenzo/flutter_inappwebview',
onPlatformViewCreated: _onPlatformViewCreated,
diff --git a/pubspec.yaml b/pubspec.yaml
index cfa72ec8..64f5c6a7 100644
--- a/pubspec.yaml
+++ b/pubspec.yaml
@@ -1,6 +1,6 @@
name: flutter_inappbrowser
description: A Flutter plugin that allows you to add an inline webview or open an in-app browser window (inspired by the popular cordova-plugin-inappbrowser).
-version: 1.1.3
+version: 1.2.0
author: Lorenzo Pichilli
homepage: https://github.com/pichillilorenzo/flutter_inappbrowser