Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

react-native-webview@14.0.1.patch

71 lines3.2 KB

1diff --git a/android/src/main/java/com/reactnativecommunity/webview/RNCWebView.java b/android/src/main/java/com/reactnativecommunity/webview/RNCWebView.java
2index 80c68034b193a47bedb56ca527352de9548e8ac6..1fac4b40c9f376a4f6d6b7fa60e4d247e8ef8550 100644
3--- a/android/src/main/java/com/reactnativecommunity/webview/RNCWebView.java
4+++ b/android/src/main/java/com/reactnativecommunity/webview/RNCWebView.java
5@@ -9,6 +9,7 @@ import android.view.Menu;
6 import android.view.MenuItem;
7 import android.view.MotionEvent;
8 import android.view.View;
9+import android.view.ViewConfiguration;
10 import android.webkit.JavascriptInterface;
11 import android.webkit.ValueCallback;
12 import android.webkit.WebChromeClient;
13@@ -122,14 +123,55 @@ public class RNCWebView extends WebView implements LifecycleEventListener {
14 cleanupCallbacksAndDestroy();
15 }
17+ private float touchDownX;
18+ private float touchDownY;
19+ private float lastTouchY;
20+ private boolean multiTouch;
21+ private boolean horizontalGesture;
22+ private final int touchSlop = ViewConfiguration.get(getContext()).getScaledTouchSlop();
24 @Override
25 public boolean onTouchEvent(MotionEvent event) {
26- if (this.nestedScrollEnabled) {
27- requestDisallowInterceptTouchEvent(true);
28- }
29+ requestDisallowInterceptTouchEvent(!shouldYieldToParent(event));
30 return super.onTouchEvent(event);
31 }
33+ // Keep horizontal drags through vertical drift. Only nested scrolling retains
34+ // vertical drags until the document's scroll edge. A nested document with no
35+ // vertical range keeps its gestures: an iframe may scroll inside it.
36+ // A gesture with a second finger stays with the page until every finger lifts.
37+ private boolean shouldYieldToParent(MotionEvent event) {
38+ switch (event.getActionMasked()) {
39+ case MotionEvent.ACTION_DOWN:
40+ touchDownX = event.getX();
41+ touchDownY = event.getY();
42+ lastTouchY = touchDownY;
43+ multiTouch = false;
44+ horizontalGesture = false;
45+ return false;
46+ case MotionEvent.ACTION_POINTER_DOWN:
47+ multiTouch = true;
48+ return false;
49+ case MotionEvent.ACTION_MOVE:
50+ if (multiTouch || horizontalGesture) return false;
51+ float dy = event.getY() - lastTouchY;
52+ lastTouchY = event.getY();
53+ float distanceX = Math.abs(event.getX() - touchDownX);
54+ float distanceY = Math.abs(event.getY() - touchDownY);
55+ if (Math.max(distanceX, distanceY) <= touchSlop) return false;
56+ if (distanceX > distanceY) {
57+ horizontalGesture = true;
58+ return false;
59+ }
60+ if (!this.nestedScrollEnabled) return true;
61+ if (dy == 0) return false;
62+ if (!canScrollVertically(1) && !canScrollVertically(-1)) return false;
63+ return !canScrollVertically(dy > 0 ? -1 : 1);
64+ default:
65+ return false;
66+ }
67+ }
69 @Override
70 protected void onSizeChanged(int w, int h, int ow, int oh) {
71 super.onSizeChanged(w, h, ow, oh);