Skip to content

Commit

Permalink
fix #765, Fixed InAppWebViewController.getHitTestResult wrong type ma…
Browse files Browse the repository at this point in the history
…pping, added auto-comment.yml
  • Loading branch information
pichillilorenzo committed Mar 30, 2021
1 parent 71a8fe2 commit 7d6c88d
Show file tree
Hide file tree
Showing 9 changed files with 77 additions and 23 deletions.
29 changes: 29 additions & 0 deletions .github/workflows/auto-comment.yml
Original file line number Diff line number Diff line change
@@ -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!
4 changes: 3 additions & 1 deletion .idea/libraries/Flutter_Plugins.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
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;
Expand Down Expand Up @@ -478,22 +479,6 @@ public boolean onLongClick(View v) {
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) {
Expand Down Expand Up @@ -1248,6 +1233,15 @@ private void sendOnCreateContextMenuEvent() {
@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);
}

Expand All @@ -1257,6 +1251,17 @@ protected void onOverScrolled(int scrollX, int scrollY, boolean clampedX, boolea

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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
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;
Expand All @@ -13,6 +14,7 @@
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;
Expand Down Expand Up @@ -50,8 +52,19 @@ public void prepare() {
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() {
Expand Down
1 change: 0 additions & 1 deletion flutter_inappwebview.iml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
4 changes: 2 additions & 2 deletions lib/src/in_app_webview/in_app_webview_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
3 changes: 2 additions & 1 deletion lib/src/in_app_webview/webview.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down

0 comments on commit 7d6c88d

Please sign in to comment.