Commit ebfd521a authored by Lorenzo Pichilli's avatar Lorenzo Pichilli

Added enableDropDownWorkaroud webview option for Android to enable a temporary...

Added enableDropDownWorkaroud webview option for Android to enable a temporary workaround for html dropdowns (issue #182)
parent 7f2eea68
This diff is collapsed.
...@@ -9,6 +9,8 @@ ...@@ -9,6 +9,8 @@
- Added `regexToCancelSubFramesLoading` webview option for Android to cancel subframe requests on `shouldOverrideUrlLoading` event based on a Regular Expression - 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 - Updated default value for `domStorageEnabled` option to `true` for Android
- Fix for Android `InAppBrowser` for some controller methods not exposed. - 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 ### BREAKING CHANGES
......
...@@ -409,6 +409,7 @@ Instead, on the `onLoadStop` WebView event, you can use `callHandler` directly: ...@@ -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. * `thirdPartyCookiesEnabled`: Boolean value to enable third party cookies in the WebView.
* `hardwareAcceleration`: Boolean value to enable Hardware Acceleration in the WebView. * `hardwareAcceleration`: Boolean value to enable Hardware Acceleration in the WebView.
* `supportMultipleWindows`: Sets whether the WebView whether supports multiple windows. * `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 ##### `InAppWebView` iOS-specific options
......
package com.pichillilorenzo.flutter_inappwebview.InAppWebView; package com.pichillilorenzo.flutter_inappwebview.InAppWebView;
import android.annotation.SuppressLint;
import android.annotation.TargetApi; import android.annotation.TargetApi;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.net.http.SslCertificate; import android.net.http.SslCertificate;
...@@ -227,6 +226,10 @@ public class InAppWebViewClient extends WebViewClient { ...@@ -227,6 +226,10 @@ public class InAppWebViewClient extends WebViewClient {
String js = InAppWebView.platformReadyJS.replaceAll("[\r\n]+", ""); 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) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
webView.evaluateJavascript(js, (ValueCallback<String>) null); webView.evaluateJavascript(js, (ValueCallback<String>) null);
} else { } else {
......
...@@ -83,6 +83,7 @@ public class InAppWebViewOptions extends Options { ...@@ -83,6 +83,7 @@ public class InAppWebViewOptions extends Options {
public Boolean hardwareAcceleration = true; public Boolean hardwareAcceleration = true;
public Boolean supportMultipleWindows = false; public Boolean supportMultipleWindows = false;
public String regexToCancelSubFramesLoading; public String regexToCancelSubFramesLoading;
public Boolean dropDownWorkaroudEnabled = false;
@Override @Override
public Object onParse(Map.Entry<String, Object> pair) { public Object onParse(Map.Entry<String, Object> pair) {
......
...@@ -9,7 +9,13 @@ import android.webkit.ValueCallback; ...@@ -9,7 +9,13 @@ import android.webkit.ValueCallback;
import com.pichillilorenzo.flutter_inappwebview.InAppWebView.InAppWebView; 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.HashMap;
import java.util.List;
import java.util.Map; import java.util.Map;
import io.flutter.plugin.common.MethodChannel; import io.flutter.plugin.common.MethodChannel;
...@@ -251,7 +257,7 @@ public class JavaScriptBridgeInterface { ...@@ -251,7 +257,7 @@ public class JavaScriptBridgeInterface {
} }
@JavascriptInterface @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 InAppWebView webView = (inAppBrowserActivity != null) ? inAppBrowserActivity.webView : flutterWebView.webView;
final Map<String, Object> obj = new HashMap<>(); final Map<String, Object> obj = new HashMap<>();
...@@ -266,6 +272,53 @@ public class JavaScriptBridgeInterface { ...@@ -266,6 +272,53 @@ public class JavaScriptBridgeInterface {
handler.post(new Runnable() { handler.post(new Runnable() {
@Override @Override
public void run() { 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) { if (handlerName.equals("onPrint") && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
webView.printCurrentPage(); webView.printCurrentPage();
} }
......
...@@ -24,6 +24,7 @@ const javaScriptHandlerForbiddenNames = [ ...@@ -24,6 +24,7 @@ const javaScriptHandlerForbiddenNames = [
"onAjaxProgress", "onAjaxProgress",
"shouldInterceptFetchRequest", "shouldInterceptFetchRequest",
"onPrint", "onPrint",
"flutterInAppWebViewDropDownWorkaroud"
]; ];
///InAppWebView Widget class. ///InAppWebView Widget class.
......
...@@ -404,9 +404,17 @@ class AndroidInAppWebViewOptions ...@@ -404,9 +404,17 @@ class AndroidInAppWebViewOptions
///If set to `true`, [onCreateWindow] event must be implemented by the host application. The default value is `false`. ///If set to `true`, [onCreateWindow] event must be implemented by the host application. The default value is `false`.
bool supportMultipleWindows; 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; 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( AndroidInAppWebViewOptions(
{this.textZoom = 100, {this.textZoom = 100,
this.clearSessionCache = false, this.clearSessionCache = false,
...@@ -449,7 +457,8 @@ class AndroidInAppWebViewOptions ...@@ -449,7 +457,8 @@ class AndroidInAppWebViewOptions
this.hardwareAcceleration = true, this.hardwareAcceleration = true,
this.initialScale = 0, this.initialScale = 0,
this.supportMultipleWindows = false, this.supportMultipleWindows = false,
this.regexToCancelSubFramesLoading}); this.regexToCancelSubFramesLoading,
this.dropDownWorkaroudEnabled = false});
@override @override
Map<String, dynamic> toMap() { Map<String, dynamic> toMap() {
...@@ -495,7 +504,8 @@ class AndroidInAppWebViewOptions ...@@ -495,7 +504,8 @@ class AndroidInAppWebViewOptions
"thirdPartyCookiesEnabled": thirdPartyCookiesEnabled, "thirdPartyCookiesEnabled": thirdPartyCookiesEnabled,
"hardwareAcceleration": hardwareAcceleration, "hardwareAcceleration": hardwareAcceleration,
"supportMultipleWindows": supportMultipleWindows, "supportMultipleWindows": supportMultipleWindows,
"regexToCancelSubFramesLoading": regexToCancelSubFramesLoading "regexToCancelSubFramesLoading": regexToCancelSubFramesLoading,
"dropDownWorkaroudEnabled": dropDownWorkaroudEnabled
}; };
} }
...@@ -550,6 +560,7 @@ class AndroidInAppWebViewOptions ...@@ -550,6 +560,7 @@ class AndroidInAppWebViewOptions
options.hardwareAcceleration = map["hardwareAcceleration"]; options.hardwareAcceleration = map["hardwareAcceleration"];
options.supportMultipleWindows = map["supportMultipleWindows"]; options.supportMultipleWindows = map["supportMultipleWindows"];
options.regexToCancelSubFramesLoading = map["regexToCancelSubFramesLoading"]; options.regexToCancelSubFramesLoading = map["regexToCancelSubFramesLoading"];
options.dropDownWorkaroudEnabled = map["dropDownWorkaroudEnabled"];
return options; return options;
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment