diff --git a/.github/workflows/auto-comment.yml b/.github/workflows/auto-comment.yml new file mode 100644 index 00000000..fb538ac3 --- /dev/null +++ b/.github/workflows/auto-comment.yml @@ -0,0 +1,29 @@ +name: Auto Comment +on: [issues, pull_request] +jobs: + run: + runs-on: ubuntu-latest + steps: + - uses: bubkoo/auto-comment@v1 + with: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + issuesOpened: > + 👋 @{{ author }} + + **NOTE**: This comment is auto-generated. + + Are you sure you have already searched for the same problem? + + Some people open new issues but they didn't search for something similar or for the same issue. + Please, search for it using the GitHub issue search box or on the official [inappwebview.dev](https://inappwebview.dev/) website, + or, also, using Google, StackOverflow, etc. before posting a new one. + You may already find an answer to your problem! + + If this is really a new issue, then thank you for raising it. I will investigate it and get back to you as soon as possible. + Please, make sure you have given me as much context as possible! + Also, if you didn't already, post a code example that can replicate this issue. + + In the meantime, you can already search for some possible solutions online! + Because this plugin uses native WebView, you can search online for the same issue adding `android WebView [MY ERROR HERE]` or `ios WKWebView [MY ERROR HERE]` keywords. + + Following these steps can save you, me, and other people a lot of time, thanks! \ No newline at end of file diff --git a/.idea/libraries/Flutter_Plugins.xml b/.idea/libraries/Flutter_Plugins.xml index 31799730..65bb3679 100755 --- a/.idea/libraries/Flutter_Plugins.xml +++ b/.idea/libraries/Flutter_Plugins.xml @@ -1,6 +1,8 @@ - + + + diff --git a/CHANGELOG.md b/CHANGELOG.md index b060674a..ad592cf1 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +## 5.3.0+1 + +- Fixed "Android - Pull to refresh triggered when scrolling container inside a website" [#765](https://github.com/pichillilorenzo/flutter_inappwebview/issues/765) +- Fixed "InAppWebViewController.getHitTestResult" wrong type mapping + ## 5.3.0 - Added `initialSize` property to the `HeadlessInAppWebView` class 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 172e464d..d8d827d0 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 @@ -22,6 +22,7 @@ import android.util.AttributeSet; import android.util.Log; import android.view.ActionMode; import android.view.ContextMenu; +import android.view.DragEvent; import android.view.GestureDetector; import android.view.LayoutInflater; import android.view.Menu; @@ -478,22 +479,6 @@ final public class InAppWebView extends InputAwareWebView { return false; } }); - - getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { - @Override - public void onGlobalLayout() { - final boolean canScrollVertical = canScrollVertically(); - ViewParent parent = getParent(); - if (parent instanceof PullToRefreshLayout) { - PullToRefreshLayout pullToRefreshLayout = (PullToRefreshLayout) parent; - if (!canScrollVertical) { - pullToRefreshLayout.setEnabled(false); - } else { - pullToRefreshLayout.setEnabled(pullToRefreshLayout.options.enabled); - } - } - } - }); } public void setIncognito(boolean enabled) { @@ -1248,6 +1233,15 @@ final public class InAppWebView extends InputAwareWebView { @Override public boolean onTouchEvent(MotionEvent ev) { lastTouch = new Point((int) ev.getX(), (int) ev.getY()); + + ViewParent parent = getParent(); + if (parent instanceof PullToRefreshLayout) { + PullToRefreshLayout pullToRefreshLayout = (PullToRefreshLayout) parent; + if (ev.getActionMasked() == MotionEvent.ACTION_DOWN) { + pullToRefreshLayout.setEnabled(false); + } + } + return super.onTouchEvent(ev); } @@ -1257,6 +1251,17 @@ final public class InAppWebView extends InputAwareWebView { boolean overScrolledHorizontally = canScrollHorizontally() && clampedX; boolean overScrolledVertically = canScrollVertically() && clampedY; + + ViewParent parent = getParent(); + if (parent instanceof PullToRefreshLayout && overScrolledVertically && scrollY <= 10) { + PullToRefreshLayout pullToRefreshLayout = (PullToRefreshLayout) parent; + // change over scroll mode to OVER_SCROLL_NEVER in order to disable temporarily the glow effect + setOverScrollMode(OVER_SCROLL_NEVER); + pullToRefreshLayout.setEnabled(pullToRefreshLayout.options.enabled); + // reset over scroll mode + setOverScrollMode(options.overScrollMode); + } + if (overScrolledHorizontally || overScrolledVertically) { Map obj = new HashMap<>(); obj.put("x", scrollX); diff --git a/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/pull_to_refresh/PullToRefreshLayout.java b/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/pull_to_refresh/PullToRefreshLayout.java index ec40fd31..0d009a4d 100644 --- a/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/pull_to_refresh/PullToRefreshLayout.java +++ b/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/pull_to_refresh/PullToRefreshLayout.java @@ -4,6 +4,7 @@ import android.content.Context; import android.graphics.Color; import android.util.AttributeSet; import android.util.Log; +import android.view.DragEvent; import android.view.MotionEvent; import android.view.View; import android.webkit.WebView; @@ -13,6 +14,7 @@ import androidx.annotation.Nullable; import androidx.swiperefreshlayout.widget.SwipeRefreshLayout; import com.pichillilorenzo.flutter_inappwebview.R; +import com.pichillilorenzo.flutter_inappwebview.in_app_webview.InAppWebView; import java.util.HashMap; import java.util.Map; @@ -50,8 +52,19 @@ public class PullToRefreshLayout extends SwipeRefreshLayout implements MethodCha if (channel != null) { this.channel.setMethodCallHandler(this); } - + setEnabled(options.enabled); + setOnChildScrollUpCallback(new OnChildScrollUpCallback() { + @Override + public boolean canChildScrollUp(@NonNull SwipeRefreshLayout parent, @Nullable View child) { + if (child instanceof InAppWebView) { + InAppWebView inAppWebView = (InAppWebView) child; + return (inAppWebView.canScrollVertically() && inAppWebView.getScrollY() > 0) || + (!inAppWebView.canScrollVertically() && inAppWebView.getScrollY() == 0); + } + return true; + } + }); setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { @Override public void onRefresh() { diff --git a/flutter_inappwebview.iml b/flutter_inappwebview.iml index 4cb39159..0adae5aa 100755 --- a/flutter_inappwebview.iml +++ b/flutter_inappwebview.iml @@ -80,6 +80,5 @@ - \ No newline at end of file diff --git a/lib/src/in_app_webview/in_app_webview_controller.dart b/lib/src/in_app_webview/in_app_webview_controller.dart index 14ac9330..dfe1752f 100644 --- a/lib/src/in_app_webview/in_app_webview_controller.dart +++ b/lib/src/in_app_webview/in_app_webview_controller.dart @@ -1744,8 +1744,8 @@ class InAppWebViewController { InAppWebViewHitTestResultType? type = InAppWebViewHitTestResultType.fromValue( - hitTestResultMap["type"].toInt()); - String extra = hitTestResultMap["extra"]; + hitTestResultMap["type"]?.toInt()); + String? extra = hitTestResultMap["extra"]; return InAppWebViewHitTestResult(type: type, extra: extra); } diff --git a/lib/src/in_app_webview/webview.dart b/lib/src/in_app_webview/webview.dart index 03e1be55..c483acf1 100644 --- a/lib/src/in_app_webview/webview.dart +++ b/lib/src/in_app_webview/webview.dart @@ -137,11 +137,12 @@ abstract class WebView { ///If the host application chooses not to honor the request, it should return `false` from this method. ///The default implementation of this method does nothing and hence returns `false`. /// - ///[createWindowAction] represents the request. + ///- [createWindowAction] represents the request. /// ///**NOTE**: to allow JavaScript to open windows, you need to set [InAppWebViewOptions.javaScriptCanOpenWindowsAutomatically] option to `true`. /// ///**NOTE**: on Android you need to set [AndroidInAppWebViewOptions.supportMultipleWindows] option to `true`. + ///Also, if the request has been created using JavaScript (`window.open()`), then there are some limitation: check the [NavigationAction] class. /// ///**NOTE**: on iOS, setting these initial options: [InAppWebViewOptions.supportZoom], [InAppWebViewOptions.useOnLoadResource], [InAppWebViewOptions.useShouldInterceptAjaxRequest], ///[InAppWebViewOptions.useShouldInterceptFetchRequest], [InAppWebViewOptions.applicationNameForUserAgent], [InAppWebViewOptions.javaScriptCanOpenWindowsAutomatically], diff --git a/pubspec.yaml b/pubspec.yaml index 1c1731c5..16379212 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.3.0 +version: 5.3.0+1 homepage: https://github.com/pichillilorenzo/flutter_inappwebview environment: