From f511e4d1f5441f277231c9e05a70cc917755fb64 Mon Sep 17 00:00:00 2001 From: Lorenzo Pichilli Date: Sat, 23 Apr 2022 15:43:57 +0200 Subject: [PATCH] Fixed Android default context menu over custom context menu on API Level 31+ --- CHANGELOG.md | 4 ++++ .../in_app_webview/InAppWebView.java | 19 ++++++++++++------- pubspec.yaml | 2 +- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3f8d43c1..aff19c95 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 5.4.1+1 + +- Fixed Android default context menu over custom context menu on API Level 31+ + ## 5.4.1 - Managed iOS native `detachFromEngine` flutter plugin event and updated `dispose` methods diff --git a/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/in_app_webview/InAppWebView.java b/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/in_app_webview/InAppWebView.java index 4a4c0567..3ae40f08 100755 --- a/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/in_app_webview/InAppWebView.java +++ b/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/in_app_webview/InAppWebView.java @@ -41,7 +41,6 @@ import android.webkit.URLUtil; import android.webkit.ValueCallback; import android.webkit.WebBackForwardList; import android.webkit.WebHistoryItem; -import android.webkit.WebMessage; import android.webkit.WebSettings; import android.webkit.WebStorage; import android.widget.HorizontalScrollView; @@ -55,8 +54,6 @@ import androidx.webkit.WebViewCompat; import androidx.webkit.WebViewFeature; import com.pichillilorenzo.flutter_inappwebview.InAppWebViewFlutterPlugin; -import com.pichillilorenzo.flutter_inappwebview.types.DownloadStartRequest; -import com.pichillilorenzo.flutter_inappwebview.types.InAppWebViewInterface; import com.pichillilorenzo.flutter_inappwebview.JavaScriptBridgeInterface; import com.pichillilorenzo.flutter_inappwebview.R; import com.pichillilorenzo.flutter_inappwebview.Util; @@ -77,6 +74,8 @@ import com.pichillilorenzo.flutter_inappwebview.plugin_scripts_js.PrintJS; import com.pichillilorenzo.flutter_inappwebview.plugin_scripts_js.PromisePolyfillJS; import com.pichillilorenzo.flutter_inappwebview.pull_to_refresh.PullToRefreshLayout; import com.pichillilorenzo.flutter_inappwebview.types.ContentWorld; +import com.pichillilorenzo.flutter_inappwebview.types.DownloadStartRequest; +import com.pichillilorenzo.flutter_inappwebview.types.InAppWebViewInterface; import com.pichillilorenzo.flutter_inappwebview.types.PluginScript; import com.pichillilorenzo.flutter_inappwebview.types.PreferredContentModeOptionType; import com.pichillilorenzo.flutter_inappwebview.types.URLRequest; @@ -1357,8 +1356,16 @@ final public class InAppWebView extends InputAwareWebView implements InAppWebVie } Menu actionMenu = actionMode.getMenu(); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { + actionMode.hide(3000); + } + List defaultMenuItems = new ArrayList<>(); + for (int i = 0; i < actionMenu.size(); i++) { + defaultMenuItems.add(actionMenu.getItem(i)); + } + actionMenu.clear(); + actionMode.finish(); if (options.disableContextMenu) { - actionMenu.clear(); return actionMode; } @@ -1379,8 +1386,7 @@ final public class InAppWebView extends InputAwareWebView implements InAppWebVie customMenuItems = customMenuItems == null ? new ArrayList>() : customMenuItems; if (contextMenuOptions.hideDefaultSystemContextMenuItems == null || !contextMenuOptions.hideDefaultSystemContextMenuItems) { - for (int i = 0; i < actionMenu.size(); i++) { - final MenuItem menuItem = actionMenu.getItem(i); + for (final MenuItem menuItem : defaultMenuItems) { final int itemId = menuItem.getItemId(); final String itemTitle = menuItem.getTitle().toString(); @@ -1457,7 +1463,6 @@ final public class InAppWebView extends InputAwareWebView implements InAppWebVie checkContextMenuShouldBeClosedTask.run(); } } - actionMenu.clear(); return actionMode; } diff --git a/pubspec.yaml b/pubspec.yaml index 51954c14..6e180b82 100755 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: flutter_inappwebview description: A Flutter plugin that allows you to add an inline webview, to use an headless webview, and to open an in-app browser window. -version: 5.4.1 +version: 5.4.1+1 homepage: https://github.com/pichillilorenzo/flutter_inappwebview environment: