Added enableDropDownWorkaroud webview option for Android to enable a temporary workaround for html dropdowns (issue #182)

This commit is contained in:
Lorenzo Pichilli 2019-12-11 01:41:38 +01:00
parent 7f2eea680c
commit ebfd521aa5
9 changed files with 386 additions and 115 deletions

View File

@ -15,8 +15,20 @@
</component>
<component name="ChangeListManager">
<list default="true" id="9b41f7a2-a71e-4923-91fb-249d7815b3e7" name="Default" comment="">
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/CHANGELOG.md" beforeDir="false" afterPath="$PROJECT_DIR$/CHANGELOG.md" afterDir="false" />
<change beforePath="$PROJECT_DIR$/README.md" beforeDir="false" afterPath="$PROJECT_DIR$/README.md" afterDir="false" />
<change beforePath="$PROJECT_DIR$/example/lib/in_app_browser_example.screen.dart" beforeDir="false" afterPath="$PROJECT_DIR$/example/lib/in_app_browser_example.screen.dart" afterDir="false" />
<change beforePath="$PROJECT_DIR$/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/InAppWebView/InAppWebView.java" beforeDir="false" afterPath="$PROJECT_DIR$/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/InAppWebView/InAppWebView.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/InAppWebView/InAppWebViewClient.java" beforeDir="false" afterPath="$PROJECT_DIR$/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/InAppWebView/InAppWebViewClient.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/InAppWebView/InAppWebViewOptions.java" beforeDir="false" afterPath="$PROJECT_DIR$/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/InAppWebView/InAppWebViewOptions.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/JavaScriptBridgeInterface.java" beforeDir="false" afterPath="$PROJECT_DIR$/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/JavaScriptBridgeInterface.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/example/ios/.symlinks/plugins/flutter_inappwebview/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/example/ios/.symlinks/plugins/flutter_inappwebview/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/example/ios/.symlinks/plugins/flutter_inappwebview/CHANGELOG.md" beforeDir="false" afterPath="$PROJECT_DIR$/example/ios/.symlinks/plugins/flutter_inappwebview/CHANGELOG.md" afterDir="false" />
<change beforePath="$PROJECT_DIR$/example/ios/.symlinks/plugins/flutter_inappwebview/README.md" beforeDir="false" afterPath="$PROJECT_DIR$/example/ios/.symlinks/plugins/flutter_inappwebview/README.md" afterDir="false" />
<change beforePath="$PROJECT_DIR$/example/ios/.symlinks/plugins/flutter_inappwebview/example/lib/main.dart" beforeDir="false" afterPath="$PROJECT_DIR$/example/ios/.symlinks/plugins/flutter_inappwebview/example/lib/main.dart" afterDir="false" />
<change beforePath="$PROJECT_DIR$/example/ios/.symlinks/plugins/flutter_inappwebview/lib/src/webview_options.dart" beforeDir="false" afterPath="$PROJECT_DIR$/example/ios/.symlinks/plugins/flutter_inappwebview/lib/src/webview_options.dart" afterDir="false" />
<change beforePath="$PROJECT_DIR$/lib/src/in_app_webview.dart" beforeDir="false" afterPath="$PROJECT_DIR$/lib/src/in_app_webview.dart" afterDir="false" />
<change beforePath="$PROJECT_DIR$/lib/src/webview_options.dart" beforeDir="false" afterPath="$PROJECT_DIR$/lib/src/webview_options.dart" afterDir="false" />
</list>
<ignored path="$PROJECT_DIR$/.dart_tool/" />
<ignored path="$PROJECT_DIR$/.idea/" />
@ -36,11 +48,11 @@
<component name="ExecutionTargetManager" SELECTED_TARGET="Pixel_3_XL_API_24" />
<component name="FileEditorManager">
<leaf SIDE_TABS_SIZE_LIMIT_KEY="300">
<file pinned="false" current-in-tab="false">
<file pinned="false" current-in-tab="true">
<entry file="file://$PROJECT_DIR$/example/lib/main.dart">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="149">
<caret line="54" lean-forward="true" selection-start-line="54" selection-end-line="54" />
<state relative-caret-position="692">
<caret line="78" column="1" selection-start-line="78" selection-start-column="1" selection-end-line="78" selection-end-column="1" />
<folding>
<element signature="e#0#20#0" expanded="true" />
</folding>
@ -51,8 +63,8 @@
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/example/lib/in_app_browser_example.screen.dart">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="193">
<caret line="38" selection-start-line="38" selection-end-line="43" selection-end-column="3" />
<state relative-caret-position="465">
<caret line="36" column="3" selection-start-line="36" selection-start-column="3" selection-end-line="36" selection-end-column="3" />
<folding>
<element signature="e#0#20#0" expanded="true" />
</folding>
@ -63,8 +75,8 @@
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/lib/src/webview_options.dart">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="328">
<caret line="409" column="28" selection-start-line="409" selection-start-column="2" selection-end-line="409" selection-end-column="28" />
<state relative-caret-position="89">
<caret line="547" column="77" selection-start-line="547" selection-start-column="77" selection-end-line="547" selection-end-column="77" />
<folding>
<element signature="e#0#17#0" expanded="true" />
</folding>
@ -75,8 +87,8 @@
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/lib/src/in_app_webview.dart">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="235">
<caret line="78" column="45" selection-start-line="78" selection-start-column="15" selection-end-line="78" selection-end-column="45" />
<state relative-caret-position="405">
<caret line="27" column="2" selection-start-line="27" selection-start-column="2" selection-end-line="27" selection-end-column="2" />
<folding>
<element signature="e#0#17#0" expanded="true" />
</folding>
@ -87,7 +99,7 @@
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/lib/src/types.dart">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="100">
<state relative-caret-position="30285">
<caret line="2026" column="38" selection-start-line="2026" selection-start-column="38" selection-end-line="2026" selection-end-column="38" />
<folding>
<element signature="e#0#20#0" expanded="true" />
@ -99,8 +111,8 @@
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/lib/src/in_app_browser.dart">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="209">
<caret line="359" column="113" selection-start-line="359" selection-start-column="113" selection-end-line="359" selection-end-column="113" />
<state relative-caret-position="4575">
<caret line="315" column="50" selection-start-line="315" selection-start-column="50" selection-end-line="315" selection-end-column="50" />
<folding>
<element signature="e#0#20#0" expanded="true" />
</folding>
@ -108,15 +120,11 @@
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="true">
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/README.md">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="215">
<caret line="506" column="25" selection-start-line="506" selection-start-column="25" selection-end-line="506" selection-end-column="25" />
<folding>
<element signature="e#0#39#0" expanded="true" />
<element signature="e#0#39#0" expanded="true" />
</folding>
<state relative-caret-position="6315">
<caret line="421" column="86" selection-start-line="421" selection-start-column="86" selection-end-line="421" selection-end-column="86" />
</state>
</provider>
</entry>
@ -124,8 +132,8 @@
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/CHANGELOG.md">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="135">
<caret line="9" column="46" selection-start-line="9" selection-start-column="29" selection-end-line="9" selection-end-column="46" />
<state relative-caret-position="180">
<caret line="12" column="41" selection-start-line="12" selection-start-column="41" selection-end-line="12" selection-end-column="41" />
</state>
</provider>
</entry>
@ -160,7 +168,6 @@
<find>ontARGET</find>
<find>onCreateWindow</find>
<find>javaScriptHandlerForbiddenNames</find>
<find>supportMultipleWindows</find>
<find>ajaxRequest</find>
<find>onTarget</find>
<find>AjaxR</find>
@ -172,6 +179,7 @@
<find>fromValue</find>
<find>shouldOv</find>
<find>shouldOverrideUrlLoading</find>
<find>supportMultipleWindows</find>
</findStrings>
<replaceStrings>
<replace>activity.getPreferences(0)</replace>
@ -237,18 +245,18 @@
<option value="$PROJECT_DIR$/example/assets/js/main.js" />
<option value="$PROJECT_DIR$/example/pubspec.yaml" />
<option value="$PROJECT_DIR$/lib/src/types.dart" />
<option value="$PROJECT_DIR$/lib/src/webview_options.dart" />
<option value="$PROJECT_DIR$/lib/src/in_app_webview.dart" />
<option value="$PROJECT_DIR$/lib/src/in_app_browser.dart" />
<option value="$PROJECT_DIR$/example/test_driver/in_app_webview_should_override_url_loading_test.dart" />
<option value="$PROJECT_DIR$/CHANGELOG.md" />
<option value="$PROJECT_DIR$/example/lib/main.dart" />
<option value="$PROJECT_DIR$/example/lib/in_app_browser_example.screen.dart" />
<option value="$PROJECT_DIR$/README.md" />
<option value="$PROJECT_DIR$/lib/src/in_app_webview.dart" />
<option value="$PROJECT_DIR$/CHANGELOG.md" />
<option value="$PROJECT_DIR$/lib/src/webview_options.dart" />
<option value="$PROJECT_DIR$/example/lib/main.dart" />
</list>
</option>
</component>
<component name="ProjectFrameBounds">
<component name="ProjectFrameBounds" extendedState="6">
<option name="x" value="-1" />
<option name="y" value="23" />
<option name="width" value="1920" />
@ -260,17 +268,7 @@
<foldersAlwaysOnTop value="true" />
</navigator>
<panes>
<pane id="Scope">
<subPane subId="Project Files">
<expand>
<path>
<item name="Root" type="cbb8eebc:String" user="Root" />
<item name="flutter_inappbrowser" type="cbb8eebc:String" user="flutter_inappbrowser" />
</path>
</expand>
<select />
</subPane>
</pane>
<pane id="PackagesPane" />
<pane id="AndroidView">
<subPane>
<expand>
@ -300,6 +298,17 @@
<select />
</subPane>
</pane>
<pane id="Scope">
<subPane subId="Project Files">
<expand>
<path>
<item name="Root" type="cbb8eebc:String" user="Root" />
<item name="flutter_inappbrowser" type="cbb8eebc:String" user="flutter_inappbrowser" />
</path>
</expand>
<select />
</subPane>
</pane>
<pane id="ProjectPane">
<subPane>
<expand>
@ -333,7 +342,6 @@
<select />
</subPane>
</pane>
<pane id="PackagesPane" />
</panes>
</component>
<component name="PropertiesComponent">
@ -486,7 +494,7 @@
<frame x="-1" y="23" width="1920" height="1057" extended-state="0" />
<editor active="true" />
<layout>
<window_info active="true" content_ui="combo" id="Project" order="0" sideWeight="0.6177474" visible="true" weight="0.20766774" />
<window_info content_ui="combo" id="Project" order="0" sideWeight="0.6177474" visible="true" weight="0.20766774" />
<window_info id="Structure" order="1" sideWeight="0.38225257" side_tool="true" weight="0.2087327" />
<window_info id="Designer" order="2" />
<window_info id="Build Variants" order="3" side_tool="true" />
@ -497,7 +505,7 @@
<window_info id="Resources Explorer" order="8" />
<window_info anchor="bottom" id="Message" order="0" />
<window_info anchor="bottom" id="Find" order="1" weight="0.32745314" />
<window_info anchor="bottom" id="Run" order="2" sideWeight="0.49478307" weight="0.4787565" />
<window_info active="true" anchor="bottom" id="Run" order="2" sideWeight="0.49478307" visible="true" weight="0.4787565" />
<window_info anchor="bottom" id="Debug" order="3" weight="0.34196892" />
<window_info anchor="bottom" id="Cvs" order="4" weight="0.25" />
<window_info anchor="bottom" id="Inspection" order="5" weight="0.4" />
@ -505,7 +513,7 @@
<window_info anchor="bottom" id="Android Profiler" order="7" show_stripe_button="false" />
<window_info anchor="bottom" id="Event Log" order="8" sideWeight="0.50532484" side_tool="true" weight="0.35751295" />
<window_info anchor="bottom" id="Version Control" order="9" />
<window_info anchor="bottom" id="Terminal" order="10" sideWeight="0.4946752" visible="true" weight="0.35336787" />
<window_info anchor="bottom" id="Terminal" order="10" sideWeight="0.4946752" weight="0.35336787" />
<window_info anchor="bottom" id="Logcat" order="11" weight="0.32953367" />
<window_info anchor="bottom" id="Messages" order="12" sideWeight="0.4968051" weight="0.33782384" />
<window_info anchor="bottom" id="Dependency Viewer" order="13" weight="0.32800853" />
@ -804,16 +812,6 @@
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/example/lib/in_app_webiew_example.screen.dart">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="487">
<caret line="73" column="39" selection-start-line="73" selection-start-column="39" selection-end-line="73" selection-end-column="39" />
<folding>
<element signature="e#0#39#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/pubspec.yaml">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="165">
@ -835,36 +833,6 @@
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/lib/src/types.dart">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="100">
<caret line="2026" column="38" selection-start-line="2026" selection-start-column="38" selection-end-line="2026" selection-end-column="38" />
<folding>
<element signature="e#0#20#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/lib/src/webview_options.dart">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="328">
<caret line="409" column="28" selection-start-line="409" selection-start-column="2" selection-end-line="409" selection-end-column="28" />
<folding>
<element signature="e#0#17#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/lib/src/in_app_browser.dart">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="209">
<caret line="359" column="113" selection-start-line="359" selection-start-column="113" selection-end-line="359" selection-end-column="113" />
<folding>
<element signature="e#0#20#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/example/test_driver/in_app_webview_should_override_url_loading_test.dart">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="329">
@ -875,37 +843,40 @@
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/CHANGELOG.md">
<entry file="file://$PROJECT_DIR$/example/lib/in_app_webiew_example.screen.dart">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="135">
<caret line="9" column="46" selection-start-line="9" selection-start-column="29" selection-end-line="9" selection-end-column="46" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/example/lib/main.dart">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="149">
<caret line="54" lean-forward="true" selection-start-line="54" selection-end-line="54" />
<state relative-caret-position="-136">
<caret line="73" column="39" selection-start-line="73" selection-start-column="39" selection-end-line="73" selection-end-column="39" />
<folding>
<element signature="e#0#20#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/lib/src/in_app_webview.dart">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="235">
<caret line="78" column="45" selection-start-line="78" selection-start-column="15" selection-end-line="78" selection-end-column="45" />
<folding>
<element signature="e#0#17#0" expanded="true" />
<element signature="e#0#39#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/example/lib/in_app_browser_example.screen.dart">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="193">
<caret line="38" selection-start-line="38" selection-end-line="43" selection-end-column="3" />
<state relative-caret-position="465">
<caret line="36" column="3" selection-start-line="36" selection-start-column="3" selection-end-line="36" selection-end-column="3" />
<folding>
<element signature="e#0#20#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/lib/src/types.dart">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="30285">
<caret line="2026" column="38" selection-start-line="2026" selection-start-column="38" selection-end-line="2026" selection-end-column="38" />
<folding>
<element signature="e#0#20#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/lib/src/in_app_browser.dart">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="4575">
<caret line="315" column="50" selection-start-line="315" selection-start-column="50" selection-end-line="315" selection-end-column="50" />
<folding>
<element signature="e#0#20#0" expanded="true" />
</folding>
@ -914,11 +885,44 @@
</entry>
<entry file="file://$PROJECT_DIR$/README.md">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="215">
<caret line="506" column="25" selection-start-line="506" selection-start-column="25" selection-end-line="506" selection-end-column="25" />
<state relative-caret-position="6315">
<caret line="421" column="86" selection-start-line="421" selection-start-column="86" selection-end-line="421" selection-end-column="86" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/lib/src/in_app_webview.dart">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="405">
<caret line="27" column="2" selection-start-line="27" selection-start-column="2" selection-end-line="27" selection-end-column="2" />
<folding>
<element signature="e#0#39#0" expanded="true" />
<element signature="e#0#39#0" expanded="true" />
<element signature="e#0#17#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/CHANGELOG.md">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="180">
<caret line="12" column="41" selection-start-line="12" selection-start-column="41" selection-end-line="12" selection-end-column="41" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/lib/src/webview_options.dart">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="89">
<caret line="547" column="77" selection-start-line="547" selection-start-column="77" selection-end-line="547" selection-end-column="77" />
<folding>
<element signature="e#0#17#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/example/lib/main.dart">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="692">
<caret line="78" column="1" selection-start-line="78" selection-start-column="1" selection-end-line="78" selection-end-column="1" />
<folding>
<element signature="e#0#20#0" expanded="true" />
</folding>
</state>
</provider>

View File

@ -9,6 +9,8 @@
- Added `regexToCancelSubFramesLoading` webview option for Android to cancel subframe requests on `shouldOverrideUrlLoading` event based on a Regular Expression
- Updated default value for `domStorageEnabled` option to `true` for Android
- Fix for Android `InAppBrowser` for some controller methods not exposed.
- Merge "Fixes null error when calling getOptions for InAppBrowser class" [#214](https://github.com/pichillilorenzo/flutter_inappwebview/pull/214) (thanks to [panndoraBoo](https://github.com/panndoraBoo))
- Added `enableDropDownWorkaroud` webview option for Android to enable a temporary workaround for html dropdowns (issue [#182](https://github.com/pichillilorenzo/flutter_inappwebview/issues/182))
### BREAKING CHANGES

View File

@ -409,6 +409,7 @@ Instead, on the `onLoadStop` WebView event, you can use `callHandler` directly:
* `thirdPartyCookiesEnabled`: Boolean value to enable third party cookies in the WebView.
* `hardwareAcceleration`: Boolean value to enable Hardware Acceleration in the WebView.
* `supportMultipleWindows`: Sets whether the WebView whether supports multiple windows.
* `regexToCancelSubFramesLoading`: Regular expression used by `shouldOverrideUrlLoading` event to cancel navigation for frames that are not the main frame. If the url request of a subframe matches the regular expression, then the request of that subframe is canceled.
##### `InAppWebView` iOS-specific options

View File

@ -2,6 +2,7 @@ package com.pichillilorenzo.flutter_inappwebview.InAppWebView;
import android.app.Activity;
import android.content.Context;
import android.content.DialogInterface;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
@ -20,8 +21,13 @@ import android.webkit.WebBackForwardList;
import android.webkit.WebHistoryItem;
import android.webkit.WebSettings;
import android.webkit.WebStorage;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.FrameLayout;
import android.widget.ListView;
import androidx.annotation.RequiresApi;
import androidx.appcompat.app.AlertDialog;
import com.pichillilorenzo.flutter_inappwebview.ContentBlocker.ContentBlocker;
import com.pichillilorenzo.flutter_inappwebview.ContentBlocker.ContentBlockerAction;
@ -31,6 +37,7 @@ import com.pichillilorenzo.flutter_inappwebview.FlutterWebView;
import com.pichillilorenzo.flutter_inappwebview.InAppBrowserActivity;
import com.pichillilorenzo.flutter_inappwebview.InAppWebViewFlutterPlugin;
import com.pichillilorenzo.flutter_inappwebview.JavaScriptBridgeInterface;
import com.pichillilorenzo.flutter_inappwebview.R;
import com.pichillilorenzo.flutter_inappwebview.Util;
import java.io.ByteArrayOutputStream;
@ -507,6 +514,128 @@ final public class InAppWebView extends InputAwareWebView {
" };" +
"})(window.fetch);";
// Android API 19+
static final String dropDownWorkaroundJS = "(function() {" +
" function getIndexSelectValues(select) {" +
" var result = [];" +
" var options = select && select.options;" +
" for (var i = 0, iLen=options.length; i < iLen; i++) {" +
" var opt = options[i];" +
" if (opt.selected) {" +
" result.push(i);" +
" }" +
" }" +
" return result;" +
" }" +
" function setMultipleValues(select, values) {" +
" var options = select && select.options;" +
" for (var i = 0, iLen=options.length; i < iLen; i++) {" +
" var opt = options[i];" +
" opt.selected = values.indexOf(opt.value) >= 0;" +
" }" +
" }" +
" function addDivWrapper(selectElement) {" +
" var divElement = document.createElement('div');" +
" divElement.flutterInAppWebViewSelect = selectElement;" +
" divElement.class = 'flutterInAppWebViewSelect';" +
" divElement.style.position = 'absolute';" +
" divElement.style.zIndex = 99999999;" +
" divElement.style.backgroundColor = 'transparent';" +
" selectElement.flutterInAppWebViewDivWrapper = divElement;" +
" updateBoundingClientRectDivWrapper(selectElement);" +
" var mutationObserver = new MutationObserver(function(mutations) {" +
" mutations.forEach(function(mutation) {" +
" updateBoundingClientRectDivWrapper(selectElement);" +
" });" +
" });" +
" mutationObserver.observe(selectElement, {" +
" attributes: true," +
" attributeFilter: ['style']" +
" });" +
" selectElement.mutationObserver = mutationObserver;" +
" var clickEventListener = function(event) {" +
" var self = this;" +
" event.preventDefault();" +
" this.flutterInAppWebViewSelect.focus();" +
" var options = [];" +
" var optionElements = this.flutterInAppWebViewSelect.querySelectorAll('option');" +
" for (var i = 0; i < optionElements.length; i++) {" +
" var optionElement = optionElements[i];" +
" options.push({" +
" key: optionElement.textContent," +
" value: optionElement.value" +
" });" +
" }" +
" var isMultiple = !!this.flutterInAppWebViewSelect.multiple;" +
" window." + JavaScriptBridgeInterface.name + ".callHandler('flutterInAppWebViewDropDownWorkaroud', getIndexSelectValues(this.flutterInAppWebViewSelect), isMultiple, options).then(function(result) {" +
" if (result != null && result.values != null) {" +
" if (!isMultiple) {" +
" if (result.values.length > 0) {" +
" self.flutterInAppWebViewSelect.value = result.values[0];" +
" }" +
" } else {" +
" setMultipleValues(self.flutterInAppWebViewSelect, result.values);" +
" }" +
" }" +
" self.flutterInAppWebViewSelect.blur();" +
" });" +
" };" +
" divElement.addEventListener('click', clickEventListener);" +
" divWithEventListeners.push({" +
" divElement: divElement," +
" clickEvent: clickEventListener" +
" });" +
" document.body.appendChild(divElement);" +
" }" +
" function removeDivWrapper(selectElement) {" +
" if (selectElement.flutterInAppWebViewDivWrapper) {" +
" divWithEventListeners.splice(divWithEventListeners.indexOf(selectElement.flutterInAppWebViewDivWrapper), 1);" +
" document.body.removeChild(selectElement.flutterInAppWebViewDivWrapper);" +
" }" +
" }" +
" function updateBoundingClientRectDivWrapper(selectElement) {" +
" selectElement.flutterInAppWebViewDivWrapper.style.width = selectElement.getBoundingClientRect().width + 'px';" +
" selectElement.flutterInAppWebViewDivWrapper.style.height = selectElement.getBoundingClientRect().height + 'px';" +
" selectElement.flutterInAppWebViewDivWrapper.style.top = selectElement.getBoundingClientRect().y + 'px';" +
" selectElement.flutterInAppWebViewDivWrapper.style.left = selectElement.getBoundingClientRect().x + 'px';" +
" }" +
" var selectElements = document.querySelectorAll('select');" +
" var divWithEventListeners = [];" +
" for(var selectElement of selectElements) {" +
" addDivWrapper(selectElement);" +
" }" +
" window.addEventListener('resize', function(event) {" +
" for(var divWithEventListener of divWithEventListeners) {" +
" var divElement = divWithEventListener.divElement;" +
" var selectElement = divElement.flutterInAppWebViewSelect;" +
" divElement.style.width = selectElement.getBoundingClientRect().width + 'px';" +
" divElement.style.height = selectElement.getBoundingClientRect().height + 'px';" +
" divElement.style.top = selectElement.getBoundingClientRect().y + 'px';" +
" divElement.style.left = selectElement.getBoundingClientRect().x + 'px';" +
" }" +
" });" +
" var mutationObserver = new MutationObserver(function(mutations) {" +
" mutations.forEach(function(mutation) {" +
" for(var nodeElement of mutation.addedNodes) {" +
" if (nodeElement.tagName == 'SELECT') {" +
" addDivWrapper(nodeElement);" +
" }" +
" }" +
" for(var nodeElement of mutation.removedNodes) {" +
" if (nodeElement.tagName == 'SELECT') {" +
" removeDivWrapper(nodeElement);" +
" if (nodeElement.mutationObserver) {" +
" nodeElement.mutationObserver.disconnect();" +
" }" +
" }" +
" }" +
" });" +
" });" +
" mutationObserver.observe(document.body, {" +
" childList: true" +
" });" +
"})();";
public InAppWebView(Context context) {
super(context);
@ -1341,6 +1470,72 @@ final public class InAppWebView extends InputAwareWebView {
new PrintAttributes.Builder().build());
}
public void showDropDownWorkaroud(final List<Integer> selectedValues, final List<List<String>> values, final boolean isMultiSelect, final DropDownWorkaroudCallback callback) {
FrameLayout layout = new FrameLayout(getContext());
final List<String> listViewValues = new ArrayList<String>();
for(List<String> value : values) {
listViewValues.add(value.get(0));
}
ListView listView = new ListView(registrar.activeContext());
ArrayAdapter<String> spinnerArrayAdapter = new ArrayAdapter<String>(registrar.activeContext(), (!isMultiSelect) ? android.R.layout.simple_list_item_1 : android.R.layout.simple_list_item_multiple_choice, listViewValues);
spinnerArrayAdapter.setDropDownViewResource(android.R.layout.simple_list_item_multiple_choice);
listView.setAdapter(spinnerArrayAdapter);
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(registrar.activeContext(), R.style.Theme_AppCompat_Dialog_Alert);
final AlertDialog alertDialog = alertDialogBuilder.create();
final List<String> result = new ArrayList<>();
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
String value = values.get(position).get(1);
if (!isMultiSelect) {
result.add(value);
//callback.result(result);
alertDialog.dismiss();
} else {
if (!result.contains(value)) {
result.add(value);
} else {
result.remove(value);
}
}
}
});
if (isMultiSelect) {
listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
listView.setItemsCanFocus(false);
for(Integer selectedValueIndex : selectedValues) {
listView.setItemChecked(selectedValueIndex, true);
String value = values.get(selectedValueIndex).get(1);
result.add(value);
}
}
alertDialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
@Override
public void onDismiss(DialogInterface dialog) {
callback.result(result);
}
});
layout.addView(listView);
alertDialog.setView(layout);
alertDialog.show();
}
public static class DropDownWorkaroudCallback {
public void result(List<String> value) {
}
}
@Override
public void dispose() {
super.dispose();

View File

@ -1,6 +1,5 @@
package com.pichillilorenzo.flutter_inappwebview.InAppWebView;
import android.annotation.SuppressLint;
import android.annotation.TargetApi;
import android.graphics.Bitmap;
import android.net.http.SslCertificate;
@ -227,6 +226,10 @@ public class InAppWebViewClient extends WebViewClient {
String js = InAppWebView.platformReadyJS.replaceAll("[\r\n]+", "");
if (webView.options.dropDownWorkaroudEnabled) {
js += InAppWebView.dropDownWorkaroundJS.replaceAll("[\r\n]+", "");
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
webView.evaluateJavascript(js, (ValueCallback<String>) null);
} else {

View File

@ -83,6 +83,7 @@ public class InAppWebViewOptions extends Options {
public Boolean hardwareAcceleration = true;
public Boolean supportMultipleWindows = false;
public String regexToCancelSubFramesLoading;
public Boolean dropDownWorkaroudEnabled = false;
@Override
public Object onParse(Map.Entry<String, Object> pair) {

View File

@ -9,7 +9,13 @@ import android.webkit.ValueCallback;
import com.pichillilorenzo.flutter_inappwebview.InAppWebView.InAppWebView;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import io.flutter.plugin.common.MethodChannel;
@ -251,7 +257,7 @@ public class JavaScriptBridgeInterface {
}
@JavascriptInterface
public void _callHandler(final String handlerName, final String _callHandlerID, String args) {
public void _callHandler(final String handlerName, final String _callHandlerID, final String args) {
final InAppWebView webView = (inAppBrowserActivity != null) ? inAppBrowserActivity.webView : flutterWebView.webView;
final Map<String, Object> obj = new HashMap<>();
@ -266,6 +272,53 @@ public class JavaScriptBridgeInterface {
handler.post(new Runnable() {
@Override
public void run() {
// workaround for https://github.com/pichillilorenzo/flutter_inappwebview/issues/182
if (handlerName.equals("flutterInAppWebViewDropDownWorkaroud")) {
try {
JSONArray jsonArray = new JSONArray(args);
List<Integer> selectedValues = new ArrayList<>();
JSONArray jsonSelectedValues = jsonArray.getJSONArray(0);
for(int i = 0; i < jsonSelectedValues.length(); i++) {
Integer selectedValue = jsonSelectedValues.getInt(i);
selectedValues.add(selectedValue);
}
boolean isMultiSelect = jsonArray.getBoolean(1);
List<List<String>> values = new ArrayList<>();
JSONArray options = jsonArray.getJSONArray(2);
Log.d(LOG_TAG, options.toString());
for(int i = 0; i < options.length(); i++) {
JSONObject option = options.getJSONObject(i);
List<String> value = new ArrayList<>();
value.add(option.getString("key"));
value.add(option.getString("value"));
values.add(value);
}
webView.showDropDownWorkaroud(selectedValues, values, isMultiSelect, new InAppWebView.DropDownWorkaroudCallback() {
@Override
public void result(List<String> values) {
String value = "{values: " + (new JSONArray(values)) + "}";
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
webView.evaluateJavascript("if(window." + name + "[" + _callHandlerID + "] != null) {window." + name + "[" + _callHandlerID + "](" + value + "); delete window." + name + "[" + _callHandlerID + "];}", (ValueCallback<String>) null);
}
else {
webView.loadUrl("javascript:if(window." + name + "[" + _callHandlerID + "] != null) {window." + name + "[" + _callHandlerID + "](" + value + "); delete window." + name + "[" + _callHandlerID + "];}");
}
}
});
} catch (JSONException e) {
e.printStackTrace();
}
return;
}
if (handlerName.equals("onPrint") && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
webView.printCurrentPage();
}

View File

@ -24,6 +24,7 @@ const javaScriptHandlerForbiddenNames = [
"onAjaxProgress",
"shouldInterceptFetchRequest",
"onPrint",
"flutterInAppWebViewDropDownWorkaroud"
];
///InAppWebView Widget class.

View File

@ -404,9 +404,17 @@ class AndroidInAppWebViewOptions
///If set to `true`, [onCreateWindow] event must be implemented by the host application. The default value is `false`.
bool supportMultipleWindows;
///Regular expression used by [shouldOverrideUrlLoading] event to cancel navigation for frames that are not the main frame.
///Regular expression used by [shouldOverrideUrlLoading] event to cancel navigation requests for frames that are not the main frame.
///If the url request of a subframe matches the regular expression, then the request of that subframe is canceled.
String regexToCancelSubFramesLoading;
///Enable a temporary workaround for html dropdowns (`<select>` tags). It requires **JavaScript enabled**.
///It attempts to block click events for the dropdowns creating a custom `<div>` layer over the dropdown to intercept user's clicks.
///The default value is `false`.
///
///**NOTE**: available on Android 19+.
bool dropDownWorkaroudEnabled;
AndroidInAppWebViewOptions(
{this.textZoom = 100,
this.clearSessionCache = false,
@ -449,7 +457,8 @@ class AndroidInAppWebViewOptions
this.hardwareAcceleration = true,
this.initialScale = 0,
this.supportMultipleWindows = false,
this.regexToCancelSubFramesLoading});
this.regexToCancelSubFramesLoading,
this.dropDownWorkaroudEnabled = false});
@override
Map<String, dynamic> toMap() {
@ -495,7 +504,8 @@ class AndroidInAppWebViewOptions
"thirdPartyCookiesEnabled": thirdPartyCookiesEnabled,
"hardwareAcceleration": hardwareAcceleration,
"supportMultipleWindows": supportMultipleWindows,
"regexToCancelSubFramesLoading": regexToCancelSubFramesLoading
"regexToCancelSubFramesLoading": regexToCancelSubFramesLoading,
"dropDownWorkaroudEnabled": dropDownWorkaroudEnabled
};
}
@ -550,6 +560,7 @@ class AndroidInAppWebViewOptions
options.hardwareAcceleration = map["hardwareAcceleration"];
options.supportMultipleWindows = map["supportMultipleWindows"];
options.regexToCancelSubFramesLoading = map["regexToCancelSubFramesLoading"];
options.dropDownWorkaroudEnabled = map["dropDownWorkaroudEnabled"];
return options;
}
}