updated dropDownWorkaround

This commit is contained in:
Lorenzo Pichilli 2019-12-11 21:21:21 +01:00
parent 2ae07055c3
commit a7e0f33b08
3 changed files with 453 additions and 141 deletions

View File

@ -15,10 +15,12 @@
</component>
<component name="ChangeListManager">
<list default="true" id="9b41f7a2-a71e-4923-91fb-249d7815b3e7" name="Default" comment="">
<change beforePath="$PROJECT_DIR$/CHANGELOG.md" beforeDir="false" afterPath="$PROJECT_DIR$/CHANGELOG.md" 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$/lib/src/webview_options.dart" beforeDir="false" afterPath="$PROJECT_DIR$/lib/src/webview_options.dart" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" 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$/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/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/InAppWebView/InAppWebView.java" beforeDir="false" afterPath="$PROJECT_DIR$/example/ios/.symlinks/plugins/flutter_inappwebview/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/InAppWebView/InAppWebView.java" 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/lib/main.dart" beforeDir="false" afterPath="$PROJECT_DIR$/example/lib/main.dart" afterDir="false" />
</list>
<ignored path="$PROJECT_DIR$/.dart_tool/" />
<ignored path="$PROJECT_DIR$/.idea/" />
@ -38,13 +40,14 @@
<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="509">
<caret line="78" column="1" selection-start-line="78" selection-start-column="1" selection-end-line="78" selection-end-column="1" />
<state relative-caret-position="316">
<caret line="130" column="3" selection-start-line="130" selection-start-column="3" selection-end-line="130" selection-end-column="3" />
<folding>
<element signature="e#0#20#0" expanded="true" />
<element signature="e#0#12718#0" expanded="true" />
<element signature="e#1907#1927#0" expanded="true" />
</folding>
</state>
</provider>
@ -65,7 +68,7 @@
<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="234">
<state relative-caret-position="7560">
<caret line="507" column="32" selection-start-line="507" selection-start-column="32" selection-end-line="507" selection-end-column="32" />
<folding>
<element signature="e#0#17#0" expanded="true" />
@ -77,11 +80,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="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>
<state relative-caret-position="195">
<caret line="13" selection-start-line="13" selection-end-line="13" />
</state>
</provider>
</entry>
@ -113,13 +113,13 @@
<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="350">
<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>
</file>
<file pinned="false" current-in-tab="true">
<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="180">
@ -140,10 +140,6 @@
</component>
<component name="FindInProjectRecents">
<findStrings>
<find>long</find>
<find>should</find>
<find>allowunivers</find>
<find>onNavigationStateChange</find>
<find>_channel</find>
<find>default</find>
<find>_staticChannel</find>
@ -170,6 +166,10 @@
<find>shouldOv</find>
<find>shouldOverrideUrlLoading</find>
<find>supportMultipleWindows</find>
<find>ThreadedInputConnection</find>
<find>ThreadedInputConnecti</find>
<find>InputAwareWebView</find>
<find>\n</find>
</findStrings>
<replaceStrings>
<replace>activity.getPreferences(0)</replace>
@ -240,14 +240,13 @@
<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$/example/lib/main.dart" />
<option value="$PROJECT_DIR$/lib/src/webview_options.dart" />
<option value="$PROJECT_DIR$/CHANGELOG.md" />
<option value="$PROJECT_DIR$/example/lib/main.dart" />
</list>
</option>
</component>
<component name="ProjectFrameBounds" extendedState="6">
<option name="x" value="-1" />
<option name="y" value="23" />
<option name="width" value="1920" />
<option name="height" value="1057" />
@ -258,7 +257,17 @@
<foldersAlwaysOnTop value="true" />
</navigator>
<panes>
<pane id="PackagesPane" />
<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="AndroidView">
<subPane>
<expand>
@ -288,17 +297,7 @@
<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="PackagesPane" />
<pane id="ProjectPane">
<subPane>
<expand>
@ -306,17 +305,6 @@
<item name="flutter_inappwebview" type="b2602c69:ProjectViewProjectNode" />
<item name="flutter_inappwebview" type="462c0819:PsiDirectoryNode" />
</path>
<path>
<item name="flutter_inappwebview" type="b2602c69:ProjectViewProjectNode" />
<item name="flutter_inappwebview" type="462c0819:PsiDirectoryNode" />
<item name="example" type="462c0819:PsiDirectoryNode" />
</path>
<path>
<item name="flutter_inappwebview" type="b2602c69:ProjectViewProjectNode" />
<item name="flutter_inappwebview" type="462c0819:PsiDirectoryNode" />
<item name="example" type="462c0819:PsiDirectoryNode" />
<item name="lib" type="462c0819:PsiDirectoryNode" />
</path>
<path>
<item name="flutter_inappwebview" type="b2602c69:ProjectViewProjectNode" />
<item name="flutter_inappwebview" type="462c0819:PsiDirectoryNode" />
@ -481,10 +469,9 @@
</todo-panel>
</component>
<component name="ToolWindowManager">
<frame x="-1" y="23" width="1920" height="1057" extended-state="0" />
<editor active="true" />
<frame x="0" y="23" width="1920" height="1057" extended-state="6" />
<layout>
<window_info 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.1368477" />
<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" />
@ -495,7 +482,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" />
@ -503,7 +490,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 active="true" 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.2507772" />
<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" />
@ -853,6 +840,16 @@
</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="7560">
<caret line="507" column="32" selection-start-line="507" selection-start-column="32" selection-end-line="507" selection-end-column="32" />
<folding>
<element signature="e#0#17#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">
@ -873,43 +870,13 @@
</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#17#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/README.md">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="350">
<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/webview_options.dart">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="234">
<caret line="507" column="32" selection-start-line="507" selection-start-column="32" selection-end-line="507" selection-end-column="32" />
<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="509">
<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>
</entry>
<entry file="file://$PROJECT_DIR$/CHANGELOG.md">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="180">
@ -917,6 +884,24 @@
</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="195">
<caret line="13" selection-start-line="13" selection-end-line="13" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/example/lib/main.dart">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="316">
<caret line="130" column="3" selection-start-line="130" selection-start-column="3" selection-end-line="130" selection-end-column="3" />
<folding>
<element signature="e#0#12718#0" expanded="true" />
<element signature="e#1907#1927#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
</component>
<component name="masterDetails">
<states>

View File

@ -410,6 +410,7 @@ Instead, on the `onLoadStop` WebView event, you can use `callHandler` directly:
* `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.
* `dropDownWorkaroundEnabled`: Enable a temporary workaround for html dropdowns (`<select>` tags) (available on Android 19+). 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`.
##### `InAppWebView` iOS-specific options

View File

@ -516,6 +516,322 @@ final public class InAppWebView extends InputAwareWebView {
// Android API 19+
static final String dropDownWorkaroundJS = "(function() {" +
" var uuid = 0;" +
" function prepare() {" +
" if (typeof window === \"undefined\") {" +
" return null;" +
" }" +
" var globalWindow =" +
" typeof window != \"undefined\" && window.Math == Math" +
" ? window" +
" : typeof self != \"undefined\" && self.Math == Math" +
" ? self" +
" : Function(\"return this\")();" +
" var requestAnimationFrame =" +
" globalWindow.requestAnimationFrame ||" +
" globalWindow.mozRequestAnimationFrame ||" +
" globalWindow.webkitRequestAnimationFrame ||" +
" function(fn) {" +
" return globalWindow.setTimeout(fn, 20);" +
" };" +
" function forEachElement(elements, callback) {" +
" var elementsType = Object.prototype.toString.call(elements);" +
" var isCollectionTyped =" +
" \"[object Array]\" === elementsType ||" +
" \"[object NodeList]\" === elementsType ||" +
" \"[object HTMLCollection]\" === elementsType ||" +
" \"[object Object]\" === elementsType ||" +
" (\"undefined\" !== typeof jQuery && elements instanceof jQuery) ||" +
" (\"undefined\" !== typeof Elements && elements instanceof Elements);" +
" var i = 0," +
" j = elements.length;" +
" if (isCollectionTyped) {" +
" for (; i < j; i++) {" +
" callback(elements[i]);" +
" }" +
" } else {" +
" callback(elements);" +
" }" +
" }" +
" function getElementSize(element) {" +
" if (!element.getBoundingClientRect) {" +
" return {" +
" width: element.offsetWidth," +
" height: element.offsetHeight" +
" };" +
" }" +
"" +
" var rect = element.getBoundingClientRect();" +
" return {" +
" width: Math.round(rect.width)," +
" height: Math.round(rect.height)" +
" };" +
" }" +
" function setStyle(element, style) {" +
" Object.keys(style).forEach(function(key) {" +
" element.style[key] = style[key];" +
" });" +
" }" +
" var ResizeSensor = function(element, callback) {" +
" var lastAnimationFrame = 0;" +
" function EventQueue() {" +
" var q = [];" +
" this.add = function(ev) {" +
" q.push(ev);" +
" };" +
"" +
" var i, j;" +
" this.call = function(sizeInfo) {" +
" for (i = 0, j = q.length; i < j; i++) {" +
" q[i].call(this, sizeInfo);" +
" }" +
" };" +
"" +
" this.remove = function(ev) {" +
" var newQueue = [];" +
" for (i = 0, j = q.length; i < j; i++) {" +
" if (q[i] !== ev) newQueue.push(q[i]);" +
" }" +
" q = newQueue;" +
" };" +
"" +
" this.length = function() {" +
" return q.length;" +
" };" +
" }" +
" function attachResizeEvent(element, resized) {" +
" if (!element) return;" +
" if (element.resizedAttached) {" +
" element.resizedAttached.add(resized);" +
" return;" +
" }" +
"" +
" element.resizedAttached = new EventQueue();" +
" element.resizedAttached.add(resized);" +
"" +
" element.resizeSensor = document.createElement(\"div\");" +
" element.resizeSensor.dir = \"ltr\";" +
" element.resizeSensor.className = \"resize-sensor\";" +
"" +
" var style = {" +
" pointerEvents: \"none\"," +
" position: \"absolute\"," +
" left: \"0px\"," +
" top: \"0px\"," +
" right: \"0px\"," +
" bottom: \"0px\"," +
" overflow: \"hidden\"," +
" zIndex: \"-1\"," +
" visibility: \"hidden\"," +
" maxWidth: \"100%\"" +
" };" +
" var styleChild = {" +
" position: \"absolute\"," +
" left: \"0px\"," +
" top: \"0px\"," +
" transition: \"0s\"" +
" };" +
"" +
" setStyle(element.resizeSensor, style);" +
"" +
" var expand = document.createElement(\"div\");" +
" expand.className = \"resize-sensor-expand\";" +
" setStyle(expand, style);" +
"" +
" var expandChild = document.createElement(\"div\");" +
" setStyle(expandChild, styleChild);" +
" expand.appendChild(expandChild);" +
"" +
" var shrink = document.createElement(\"div\");" +
" shrink.className = \"resize-sensor-shrink\";" +
" setStyle(shrink, style);" +
"" +
" var shrinkChild = document.createElement(\"div\");" +
" setStyle(shrinkChild, styleChild);" +
" setStyle(shrinkChild, { width: \"200%\", height: \"200%\" });" +
" shrink.appendChild(shrinkChild);" +
"" +
" element.resizeSensor.appendChild(expand);" +
" element.resizeSensor.appendChild(shrink);" +
" element.appendChild(element.resizeSensor);" +
"" +
" var computedStyle = window.getComputedStyle(element);" +
" var position = computedStyle" +
" ? computedStyle.getPropertyValue(\"position\")" +
" : null;" +
" if (" +
" \"absolute\" !== position &&" +
" \"relative\" !== position &&" +
" \"fixed\" !== position &&" +
" \"sticky\" !== position" +
" ) {" +
" element.style.position = \"relative\";" +
" }" +
"" +
" var dirty, rafId;" +
" var size = getElementSize(element);" +
" var lastWidth = 0;" +
" var lastHeight = 0;" +
" var initialHiddenCheck = true;" +
" lastAnimationFrame = 0;" +
"" +
" var resetExpandShrink = function() {" +
" var width = element.offsetWidth;" +
" var height = element.offsetHeight;" +
"" +
" expandChild.style.width = width + 10 + \"px\";" +
" expandChild.style.height = height + 10 + \"px\";" +
"" +
" expand.scrollLeft = width + 10;" +
" expand.scrollTop = height + 10;" +
"" +
" shrink.scrollLeft = width + 10;" +
" shrink.scrollTop = height + 10;" +
" };" +
"" +
" var reset = function() {" +
" if (initialHiddenCheck) {" +
" var invisible =" +
" element.offsetWidth === 0 && element.offsetHeight === 0;" +
" if (invisible) {" +
" if (!lastAnimationFrame) {" +
" lastAnimationFrame = requestAnimationFrame(function() {" +
" lastAnimationFrame = 0;" +
"" +
" reset();" +
" });" +
" }" +
"" +
" return;" +
" } else {" +
" initialHiddenCheck = false;" +
" }" +
" }" +
"" +
" resetExpandShrink();" +
" };" +
" element.resizeSensor.resetSensor = reset;" +
"" +
" var onResized = function() {" +
" rafId = 0;" +
"" +
" if (!dirty) return;" +
"" +
" lastWidth = size.width;" +
" lastHeight = size.height;" +
"" +
" if (element.resizedAttached) {" +
" element.resizedAttached.call(size);" +
" }" +
" };" +
"" +
" var onScroll = function() {" +
" size = getElementSize(element);" +
" dirty = size.width !== lastWidth || size.height !== lastHeight;" +
"" +
" if (dirty && !rafId) {" +
" rafId = requestAnimationFrame(onResized);" +
" }" +
"" +
" reset();" +
" };" +
"" +
" var addEvent = function(el, name, cb) {" +
" if (el.attachEvent) {" +
" el.attachEvent(\"on\" + name, cb);" +
" } else {" +
" el.addEventListener(name, cb);" +
" }" +
" };" +
"" +
" addEvent(expand, \"scroll\", onScroll);" +
" addEvent(shrink, \"scroll\", onScroll);" +
"" +
" lastAnimationFrame = requestAnimationFrame(reset);" +
" }" +
"" +
" forEachElement(element, function(elem) {" +
" attachResizeEvent(elem, callback);" +
" });" +
"" +
" this.detach = function(ev) {" +
" if (!lastAnimationFrame) {" +
" window.cancelAnimationFrame(lastAnimationFrame);" +
" lastAnimationFrame = 0;" +
" }" +
" ResizeSensor.detach(element, ev);" +
" };" +
"" +
" this.reset = function() {" +
" element.resizeSensor.resetSensor();" +
" };" +
" };" +
"" +
" ResizeSensor.reset = function(element) {" +
" forEachElement(element, function(elem) {" +
" elem.resizeSensor.resetSensor();" +
" });" +
" };" +
"" +
" ResizeSensor.detach = function(element, ev) {" +
" forEachElement(element, function(elem) {" +
" if (!elem) return;" +
" if (elem.resizedAttached && typeof ev === \"function\") {" +
" elem.resizedAttached.remove(ev);" +
" if (elem.resizedAttached.length()) return;" +
" }" +
" if (elem.resizeSensor) {" +
" if (elem.contains(elem.resizeSensor)) {" +
" elem.removeChild(elem.resizeSensor);" +
" }" +
" delete elem.resizeSensor;" +
" delete elem.resizedAttached;" +
" }" +
" });" +
" };" +
"" +
" if (typeof MutationObserver !== \"undefined\") {" +
" var observer = new MutationObserver(function(mutations) {" +
" for (var i in mutations) {" +
" if (mutations.hasOwnProperty(i)) {" +
" var items = mutations[i].addedNodes;" +
" for (var j = 0; j < items.length; j++) {" +
" if (items[j].resizeSensor) {" +
" ResizeSensor.reset(items[j]);" +
" }" +
" }" +
" }" +
" }" +
" });" +
"" +
" document.addEventListener(\"DOMContentLoaded\", function(event) {" +
" observer.observe(document.body, {" +
" childList: true," +
" subtree: true" +
" });" +
" });" +
" }" +
"" +
" return ResizeSensor;" +
" }" +
" var ResizeSensor = prepare();" +
" function pseudoStyle(htmlElement, pseudoElement, styles) {" +
" var _sheetId = \"pseudoStyles\";" +
" var _head = document.head || document.getElementsByTagName(\"head\")[0];" +
" var _sheet =" +
" document.getElementById(_sheetId) || document.createElement(\"style\");" +
" _sheet.id = _sheetId;" +
" var styleClass = htmlElement.className.split(\" \").join(\".\");" +
" if (styleClass.charAt(0) != \".\") {" +
" styleClass = \".\" + styleClass;" +
" }" +
" _sheet.innerHTML += \"\n\" + styleClass + \":\" + pseudoElement + \"{\";" +
" for (var key in styles) {" +
" _sheet.innerHTML += key + \":\" + styles[key] + \";\n\";" +
" }" +
" _sheet.innerHTML += \"}\";" +
" _head.appendChild(_sheet);" +
" }" +
" function getIndexSelectValues(select) {" +
" var result = [];" +
" var options = select && select.options;" +
@ -534,31 +850,38 @@ final public class InAppWebView extends InputAwareWebView {
" 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);" +
" function addSpanWrapper(selectElement) {" +
" var spanElement = document.createElement(\"span\");" +
" spanElement.flutterInAppWebViewSelect = selectElement;" +
" new ResizeSensor(spanElement, function() {" +
" selectElement.style.width = spanElement.getBoundingClientRect().width + \"px\";" +
" selectElement.style.height = spanElement.getBoundingClientRect().height + \"px\";" +
" });" +
" spanElement.className = \"flutterInAppWebViewSelect-\" + uuid;" +
" spanElement.style.padding = \"0px\";" +
" spanElement.style.margin = \"0px\";" +
" spanElement.style.border = \"0px\";" +
" spanElement.style.display = \"inline-block\";" +
" spanElement.style.backgroundColor = \"transparent\";" +
" spanElement.style.position = \"relative\";" +
" pseudoStyle(spanElement, \"before\", {" +
" content: \"' '\"," +
" width: \"100%\"," +
" height: \"100%\"," +
" position: \"absolute\"," +
" top: \"0\"," +
" left: \"0\"," +
" \"z-index\": 99999999" +
" });" +
" mutationObserver.observe(selectElement, {" +
" attributes: true," +
" attributeFilter: ['style']" +
" });" +
" selectElement.mutationObserver = mutationObserver;" +
" selectElement.flutterInAppWebViewSpanWrapper = spanElement;" +
" var clickEventListener = function(event) {" +
" var self = this;" +
" event.preventDefault();" +
" this.flutterInAppWebViewSelect.focus();" +
" var options = [];" +
" var optionElements = this.flutterInAppWebViewSelect.querySelectorAll('option');" +
" var optionElements = this.flutterInAppWebViewSelect.querySelectorAll(" +
" \"option\"" +
" );" +
" for (var i = 0; i < optionElements.length; i++) {" +
" var optionElement = optionElements[i];" +
" options.push({" +
@ -567,7 +890,14 @@ final public class InAppWebView extends InputAwareWebView {
" });" +
" }" +
" var isMultiple = !!this.flutterInAppWebViewSelect.multiple;" +
" window." + JavaScriptBridgeInterface.name + ".callHandler('flutterInAppWebViewDropDownWorkaround', getIndexSelectValues(this.flutterInAppWebViewSelect), isMultiple, options).then(function(result) {" +
" window.flutter_inappwebview" +
" .callHandler(" +
" \"flutterInAppWebViewDropDownWorkaround\"," +
" getIndexSelectValues(this.flutterInAppWebViewSelect)," +
" isMultiple," +
" options" +
" )" +
" .then(function(result) {" +
" if (result != null && result.values != null) {" +
" if (!isMultiple) {" +
" if (result.values.length > 0) {" +
@ -577,53 +907,47 @@ final public class InAppWebView extends InputAwareWebView {
" setMultipleValues(self.flutterInAppWebViewSelect, result.values);" +
" }" +
" }" +
" var evt = document.createEvent('HTMLEvents');" +
" evt.initEvent('change', false, true);" +
" self.flutterInAppWebViewSelect.dispatchEvent(evt);" +
" self.flutterInAppWebViewSelect.blur();" +
" });" +
" };" +
" divElement.addEventListener('click', clickEventListener);" +
" spanElement.addEventListener('click', clickEventListener);" +
" divWithEventListeners.push({" +
" divElement: divElement," +
" spanElement: spanElement," +
" clickEvent: clickEventListener" +
" });" +
" document.body.appendChild(divElement);" +
" selectElement.parentNode.insertBefore(spanElement, selectElement);" +
" spanElement.appendChild(selectElement);" +
" uuid++;" +
" }" +
" function removeDivWrapper(selectElement) {" +
" if (selectElement.flutterInAppWebViewDivWrapper) {" +
" divWithEventListeners.splice(divWithEventListeners.indexOf(selectElement.flutterInAppWebViewDivWrapper), 1);" +
" document.body.removeChild(selectElement.flutterInAppWebViewDivWrapper);" +
" function removeSpanWrapper(selectElement) {" +
" if (selectElement.flutterInAppWebViewSpanWrapper) {" +
" divWithEventListeners.splice(" +
" divWithEventListeners.indexOf(" +
" selectElement.flutterInAppWebViewSpanWrapper" +
" )," +
" 1" +
" );" +
" document.body.removeChild(selectElement.flutterInAppWebViewSpanWrapper);" +
" }" +
" }" +
" 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);" +
" addSpanWrapper(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);" +
" addSpanWrapper(nodeElement);" +
" }" +
" }" +
" for (var nodeElement of mutation.removedNodes) {" +
" if (nodeElement.tagName == 'SELECT') {" +
" removeDivWrapper(nodeElement);" +
" removeSpanWrapper(nodeElement);" +
" if (nodeElement.mutationObserver) {" +
" nodeElement.mutationObserver.disconnect();" +
" }" +
@ -632,7 +956,8 @@ final public class InAppWebView extends InputAwareWebView {
" });" +
" });" +
" mutationObserver.observe(document.body, {" +
" childList: true" +
" childList: true," +
" subtree: true" +
" });" +
"})();";
@ -658,6 +983,7 @@ final public class InAppWebView extends InputAwareWebView {
this.flutterWebView = (FlutterWebView) obj;
this.id = id;
this.options = options;
}
@Override