fix #765, Fixed InAppWebViewController.getHitTestResult wrong type mapping, added auto-comment.yml

This commit is contained in:
Lorenzo Pichilli 2021-03-30 18:15:50 +02:00
parent 71a8fe23ea
commit 7d6c88d622
9 changed files with 77 additions and 23 deletions

29
.github/workflows/auto-comment.yml vendored Normal file
View File

@ -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!

View File

@ -1,6 +1,8 @@
<component name="libraryTable">
<library name="Flutter Plugins">
<CLASSES />
<CLASSES>
<root url="file://$PROJECT_DIR$" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>

View File

@ -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

View File

@ -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<String, Object> obj = new HashMap<>();
obj.put("x", scrollX);

View File

@ -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() {

View File

@ -80,6 +80,5 @@
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="Dart SDK" level="project" />
<orderEntry type="library" name="Flutter Plugins" level="project" />
<orderEntry type="library" name="Dart Packages" level="project" />
</component>
</module>

View File

@ -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);
}

View File

@ -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],

View File

@ -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: